GNU find 的手册页指出:
Run Code Online (Sandbox Code Playgroud)-exec command ; [...] The string `{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a `\') or quoted to protect them from expansion by the shell.
那是从人到find
(GNU findutils)4.4.2。
现在我用 bash 和 dash 测试了这个,两者都不需要{}
被屏蔽。这是一个简单的测试:
find /etc -name "hosts" -exec …
Run Code Online (Sandbox Code Playgroud) 我正在尝试删除名称中带有空格的所有文件。我正在使用以下命令。但它给了我一个错误
命令 : ls | egrep '. ' | xargs rm
在这里,如果我只使用ls | egrep '. '
命令,它会给我所有文件名,文件名中带有空格。但是当我尝试将输出传递给 rm 时,所有空格(前导或尾随)都会被删除。所以我的命令没有得到正确执行。
有关如何删除名称中至少有一个空格的文件的任何指示?
在我的当前目录中,我执行命令:
ls -1
它给出了当前目录内容的列表。
在同一个目录中,我重复命令:ls
它给了我相同的结果,但输出格式可能不同。
最后,我尝试通过键入来查找可用命令,ls --help
输出为:
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
Run Code Online (Sandbox Code Playgroud)
看起来最后一个选项是1
(#1)。有人可以解释一下ls -1
它的作用以及它与标准ls
命令的不同之处吗?
我需要在某个文件夹中搜索最新创建的文件并 grep 模式的内容。到目前为止,我已经使用此命令取得了成功:
find /var/log/folder -type f -printf '%T+ %p\n' | sort | tail -n1 | xargs grep 'string to find'
Run Code Online (Sandbox Code Playgroud)
这确实找到了具有匹配项的最新文件,但我在标准输出中得到了意外的一行。
$ find /var/log/folder -type f -printf '%T+ %p\n' | sort | tail -n1 | xargs grep 'string to find'
grep: 2016-05-12+20:01:59.0570667340: No such file or directory
/var/log/folder/file:string to find
Run Code Online (Sandbox Code Playgroud)
如何更改我的命令,使其不给我“没有这样的文件或目录”行?
命令是什么:
ls | wc -l
Run Code Online (Sandbox Code Playgroud)
做?我知道
wc <filename>
Run Code Online (Sandbox Code Playgroud)
给出行、词和字符,以及
wc -l <filename>
Run Code Online (Sandbox Code Playgroud)
打印行数。但是它如何与 ls` 一起使用尚不清楚。它有什么作用?