Linux chmod:在+;T

Linux chmod:在+;T,linux,bash,shell,Linux,Bash,Shell,正在尝试修复世界可写文件并出现以下错误: chmod: missing operand after a+t 这是我的密码 df --local -P | awk {'if (NR!=1) print $6'} | xargs -I '{}' find '{}' -xdev -type d -perm -0002 -a ! -perm -1000 2>/dev/null | xargs chmod a+t 有什么想法吗?如果您没有向chmod提供参数,就会发生这种情况: $ chmod

正在尝试修复世界可写文件并出现以下错误:

chmod: missing operand after a+t
这是我的密码

df --local -P | awk {'if (NR!=1) print $6'} | xargs -I '{}' find '{}' -xdev -type d -perm -0002 -a ! -perm -1000 2>/dev/null | xargs chmod a+t

有什么想法吗?

如果您没有向
chmod提供参数,就会发生这种情况:

$ chmod a+x
chmod: missing operand after ‘a+x’
Try 'chmod --help' for more information.
因此,据推测,该命令:

df --local -P | awk {'if (NR!=1) print $6'} | \
        xargs -I '{}' find '{}' -xdev -type d -perm -0002 -a ! -perm -1000 2>/dev/null

未生成任何输出,即在要搜索的给定目录中没有任何与所需
perm
约束匹配的目录。只运行此命令,不使用
chmod
,以确保这一点。

如果您没有为
chmod
提供参数,则会发生这种情况:

$ chmod a+x
chmod: missing operand after ‘a+x’
Try 'chmod --help' for more information.
因此,据推测,该命令:

df --local -P | awk {'if (NR!=1) print $6'} | \
        xargs -I '{}' find '{}' -xdev -type d -perm -0002 -a ! -perm -1000 2>/dev/null

未生成任何输出,即在要搜索的给定目录中没有任何与所需
perm
约束匹配的目录。只运行这个命令,不使用
chmod
,以确保这一点。

这里根本不需要
xargs
——它是您的bug的来源,如果您在目录中装载了名称中带有空格或引号(或文字反斜杠)的内容,那么它将是更多bug的来源

{
  read _                           # consume header
  while IFS= read -r dirname; do   # ...iterate over later lines...
    find "$dirname" -xdev -type d \
      '(' -perm -0002 -a ! -perm -1000 ')' \
      -exec chmod a+t '{}' + 2>/dev/null
  done
} < <(df --output=target --local)  # tell df to emit only the one column you want
{
读取35;消耗标题
当IFS=read-r dirname;do#…迭代后面的行时。。。
查找“$dirname”-xdev-类型d\
“('-perm-0002-a!-perm-1000')”\
-exec chmod a+t'{}'+2>/dev/null
完成

}<这里根本不需要使用
xargs
——它是您的bug的来源,如果您将内容装载在名称中带有空格或引号(或文字反斜杠)的目录上,它将是更多bug的来源

{
  read _                           # consume header
  while IFS= read -r dirname; do   # ...iterate over later lines...
    find "$dirname" -xdev -type d \
      '(' -perm -0002 -a ! -perm -1000 ')' \
      -exec chmod a+t '{}' + 2>/dev/null
  done
} < <(df --output=target --local)  # tell df to emit only the one column you want
{
读取35;消耗标题
当IFS=read-r dirname;do#…迭代后面的行时。。。
查找“$dirname”-xdev-类型d\
“('-perm-0002-a!-perm-1000')”\
-exec chmod a+t'{}'+2>/dev/null
完成

}<如果使用
-exec
而不是
xargs
,则不会出现此问题(或其他几个问题)。如果使用GNU
xargs
,则可以使用
--no run If empty
(又称
-r
)选项避免在没有参数的情况下运行命令一次(POSIX所要求的行为,可能是出于对历史先例的尊重,而不是因为它看起来真的是个好主意)。但是您最好避免使用
xargs
@JonathanLeffler在没有参数的情况下仍然调用命令,这就像……当它不匹配时仍然扩展到未扩展的glob模式,并传递一个无用的参数。@Kaz,……有一个非常好的理由,
nullglob
默认关闭:广泛可用命令行程序在不传递参数时使用默认行为;向它们传递glob文本意味着它们没有返回默认行为,而是有机会发出错误。相比之下,GNU xargs的默认行为是我无法辩护的。如果使用
-exec
而不是
xargs
您不会有这个问题(或其他几个问题)。如果您有GNU
xargs
,您可以使用
--no run If empty
(又称
-r
)选项避免在没有参数的情况下运行命令一次(POSIX所要求的行为,可能是出于对历史先例的尊重,而不是因为它看起来真的是个好主意)。但是您最好避免使用
xargs
@JonathanLeffler在没有参数的情况下仍然调用命令,这就像……当它不匹配时仍然扩展到未扩展的glob模式,并传递一个无用的参数。@Kaz,……有一个非常好的理由,
nullglob
默认关闭:广泛可用命令行程序在不传递参数时使用默认行为;向它们传递glob literal意味着它们没有返回默认行为,而是有机会发出错误。相比之下,GNU xargs的默认行为是我无法辩护的。