相关疑难解决方法(0)

“垂直显示‘ls’命令的输出”在哪里记录?

发现可以ls使用-1开关垂直显示命令的输出:

$ ls -1

但是在说明书上没找到ls。这是一个秘密选择吗?

ls man documentation

38
推荐指数
2
解决办法
4万
查看次数

GNU 为某些 shell 查找并屏蔽 {} - 哪个?

GNU find 的手册页指出:

-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. 
Run Code Online (Sandbox Code Playgroud)

那是从人到find(GNU findutils)4.4.2。

现在我用 bash 和 dash 测试了这个,两者都不需要{}被屏蔽。这是一个简单的测试:

find /etc -name "hosts" -exec …
Run Code Online (Sandbox Code Playgroud)

shell find xargs quoting

37
推荐指数
3
解决办法
3846
查看次数

删除名称中带有空格的文件

我正在尝试删除名称中带有空格的所有文件。我正在使用以下命令。但它给了我一个错误

命令 : ls | egrep '. ' | xargs rm

在这里,如果我只使用ls | egrep '. '命令,它会给我所有文件名,文件名中带有空格。但是当我尝试将输出传递给 rm 时,所有空格(前导或尾随)都会被删除。所以我的命令没有得到正确执行。

有关如何删除名称中至少有一个空格的文件的任何指示?

shell xargs quoting rm

13
推荐指数
4
解决办法
5万
查看次数

“ls -1”命令有什么作用?

在我的当前目录中,我执行命令: ls -1它给出了当前目录内容的列表。

在同一个目录中,我重复命令:ls它给了我相同的结果,但输出格式可能不同。

最后,我尝试通过键入来查找可用命令,ls --help输出为:

usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
Run Code Online (Sandbox Code Playgroud)

看起来最后一个选项是1(#1)。有人可以解释一下ls -1它的作用以及它与标准ls命令的不同之处吗?

osx ls shell

9
推荐指数
2
解决办法
2万
查看次数

如何在包含某个字符串的目录中找到最新的文件?

我需要在某个文件夹中搜索最新创建的文件并 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)

如何更改我的命令,使其不给我“没有这样的文件或目录”行?

shell grep find files

5
推荐指数
1
解决办法
2万
查看次数

ls 与 wc 命令一起使用

命令是什么:

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` 一起使用尚不清楚。它有什么作用?

ls wc

1
推荐指数
1
解决办法
4万
查看次数

标签 统计

shell ×4

ls ×3

find ×2

quoting ×2

xargs ×2

documentation ×1

files ×1

grep ×1

man ×1

osx ×1

rm ×1

wc ×1