Cyb*_*m0n 514
find . -type f -print0 | xargs -0 dos2unix
将以递归方式查找当前目录中的所有文件并调用这些文件dos2unix命令
nik*_*ikc 64
如果它是一个大目录,您可能需要考虑使用多个处理器运行:
find . -type f -print0 | xargs -0 -n 1 -P 4 dos2unix
Run Code Online (Sandbox Code Playgroud)
这将一次传递1个文件,并使用4个处理器.
Mat*_*don 24
因为我碰巧对dos2unix感到很满意,所以我推出了自己的简单实用工具.除了速度和可预测性方面的一些优点外,语法也更简单:
endlines unix *
Run Code Online (Sandbox Code Playgroud)
如果你想让它进入子目录(跳过隐藏的目录和非文本文件):
endlines unix -r .
Run Code Online (Sandbox Code Playgroud)
endlines
可在此处https://github.com/mdolidon/endlines
Kyl*_*and 14
最好是跳过隐藏的文件和文件夹,例如.git.
So而不是使用find
,如果您的bash
版本足够新或者您正在使用zsh
,只需执行以下操作:
dos2unix **
Run Code Online (Sandbox Code Playgroud)
请注意,对于Bash,这将需要:
shopt -s globstar
Run Code Online (Sandbox Code Playgroud)
....但这是一个非常有用的功能,你应该老老实实地把它放在你的.bashrc
手中.
如果你不希望跳过隐藏的文件和文件夹,但你还是不想惹find
(和我也不会怪你),你可以提供第二递归水珠参数匹配只隐藏的条目:
dos2unix ** **/.*
Run Code Online (Sandbox Code Playgroud)
请注意,在这两种情况下,glob都会扩展为包含目录,因此您将看到以下警告(可能多次): Skipping <dir>, not a regular file.
fri*_*mle 12
一个常见的用例似乎是标准化提交到 Git 存储库的所有文件的行尾:
git ls-files | xargs dos2unix
Run Code Online (Sandbox Code Playgroud)
请记住,某些文件(例如*.sln
,*.bat
)等都是只使用在Windows操作系统中,应该保持的CRLF
结尾:
git ls-files '*.sln' '*.bat' | xargs unix2dos
Run Code Online (Sandbox Code Playgroud)
如有必要,请使用 .gitattributes
我已经在谷歌上搜索了这一百万次,所以我的解决方案是将这个 bash 函数放入您的环境中。
.bashrc
或.profile
或无论什么
dos2unixd() {
find $1 -type f -print0 | xargs -0 dos2unix
}
Run Code Online (Sandbox Code Playgroud)
用法
$ dos2unixd ./somepath
这样你仍然拥有原来的命令dos2unix
并且很容易记住这个命令dos2unixd
。
小智 6
对于任何Solaris用户(使用5.10,也可能适用于较新版本,以及其他unix系统):
dos2unix不会默认覆盖文件,它只会将更新后的版本打印到stdout,因此您必须指定源和目标,即两次相同的名称:
find . -type f -exec dos2unix {} {} \;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
171753 次 |
最近记录: |