0

我有一个可执行文件放置在我的 Linux 机器上,因此可执行文件的路径长度为 107 个字符。我使用 command 找到了字符数echo -n "/path/to/the/executable" | wc -c -m。当我尝试使用完整路径执行可执行文件时,出现以下错误:

sh: 1: /subpath/to/the/executable: not found

我检查了长度,/subpath/to/the/executable它是 81 个字符。如果我放置我的可执行文件,使其路径长度小于 81 个字符,我不会得到上面的sh error.

我做了一些搜索,发现 Linux env 上的文件路径限制为 255 个字符。我找不到 dash 或 shell 是否对文件路径有任何限制。在我的机器上,/bin/sh 是指向 /bin/dash 的符号链接。

有人可以解释破折号强制执行的文件路径上 81 个字符的限制吗?有没有办法提高限额?

4

1 回答 1

1

是的,dash(由于 Linux)对文件路径的长度有限制:

  • 路径中的条目不能超过 255 个字符。
  • 总路径不能超过 4095 个字符。

以下是证明这一点的示例:

$ "$(head -c 255 /dev/zero | tr '\0' 'x')"
dash: 2: xxxxxx[...]xxxxxxx: not found

$ "$(head -c 256 /dev/zero | tr '\0' 'x')"
dash: 3: xxxxxx[...]xxxxxxxx: File name too long

$ "$(while true; do printf "/x"; done | head -c 4095)"
dash: 4: /x/x/[...]/x/x/x/: not found

$ "$(while true; do printf "/x"; done | head -c 4096)"
dash: 5: /x/x/[...]/x/x/x/x: File name too long

没有限制会影响 81 个字符或 107 个字符的名称。这是一个示例,显示 200 个字符可以正常工作dash

$ name="./$(head -c 200 /dev/zero | tr '\0' x)"
$ printf '%s\n' '#!/bin/sh' 'echo "hello world"' > "$name"
$ chmod +x "$name"
$ "$name"
hello world

如果您对 Java 程序无法正确执行命令的原因有任何疑问,请在java标签下单独发布。确保不要缩写或掩盖文件名,因为确切的值很重要。

于 2016-08-09T20:24:31.577 回答