
任何人都可以解释为什么下面的命令会产生以下错误:
cannot open `{}' (No such file or directory)
命令
$ ls -al|grep -v '^d\|^$'|awk '{print $10}'|xargs file '{}'
我得到了预期的结果,但出现错误
{}: cannot open `{}' (No such file or directory)
cpuinfo: empty
cygdrive: symbolic link to /cygdrive
devices: empty
filesystems: empty
loadavg: empty
meminfo: empty
misc: empty
mounts: symbolic link to self/mounts
partitions: empty
self: symbolic link to 19812
stat: empty
swaps: empty
uptime: empty
version: empty
答案1
因为您使用了xargs
错误,所以您可能会受到 find 工作原理的启发。
xargs
接受输入并将其分成几部分以生成几个命令,但是(除非您要求它)它在您在 xargs 之后指定的命令末尾给出多个参数,因此您{}
只是命令的一部分。所以你最终会执行file {} <file_1> <file_2> ... <file_n>
, file {} <file_n+1>...
, .... (在你的情况下,你的文件很少,只执行一个命令。)
由于您没有名为 的文件{}
,file
因此会告诉您。