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会很棒.
我猜非切割解决方案也很好,但我不想放弃一个简单的想法.
我有以下设置:
core.symlinks=true (由于上面的线)core.autocrlf=false (我不想让 git 做任何聪明的事,我在 Windows 和 WSL 之间共享 repo)这几乎完美无缺(印象非常深刻)。当我克隆一个存储库时,在 Windows 和 WSL 中都可以,除了两侧之一的符号链接说它们被修改但它们没有。在两侧,符号链接都可以正常工作,我可以毫无问题地导航它们。
初始克隆(在 Windows 端)后,Windows PowerShell 提供:
PS C:\Users\Matthew\Projects\...> git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
Run Code Online (Sandbox Code Playgroud)
但是,在 WSL 方面,它表示修改了两个符号链接:
/mnt/c/Users/Matthew/Projects/...$ git status
On branch master
Your branch is up to date with 'origin/master'. …Run Code Online (Sandbox Code Playgroud)