phi*_*urn 11 unix null cut file nul
Unix'file'命令有一个-0选项,用于在文件名后输出空字符.据说这对于'cut'来说很有用.
来自man file
:
-0, --print0
Output a null character ‘\0’ after the end of the filename. Nice
to cut(1) the output. This does not affect the separator which is
still printed.
Run Code Online (Sandbox Code Playgroud)
(注意,在我的Linux上,不会打印'-F'分隔符 - 这对我来说更有意义.)
如何使用'cut'从'file'的输出中提取文件名?
这就是我想要做的:
find . "*" -type f | file -n0iNf - | cut -d<null> -f1
Run Code Online (Sandbox Code Playgroud)
<null>
NUL角色在哪里?
好吧,这就是我想要做的,我想要做的是从目录树中获取具有特定MIME类型的所有文件名.我使用grep(未显示).
我想处理所有合法的文件名,而不是卡在冒号的文件名上,例如,在他们的名字中.因此,NUL会很棒.
我猜非切割解决方案也很好,但我不想放弃一个简单的想法.
rua*_*akh 13
只需指定一个空分隔符:
cut -d '' -f1
Run Code Online (Sandbox Code Playgroud)
(注意:-d
和之间的空间''
很重要,所以-d
空字符串作为单独的参数传递;如果你写-d''
,那么它将作为公正传递-d
,然后cut
会认为你试图-f1
用作分隔符,它会抱怨,错误信息"分隔符必须是单个字符".)