bash 如何将某些文件从 dos 格式转换为 unix
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14995923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert some files from dos format to unix
提问by How Chen
I know how to change file format from dos to unix by use dos2unix, but how can I change ALL the files will under a directory tree. Can dos2unixchange files recursively?
我知道如何通过 use 将文件格式从 dos 更改为 unix dos2unix,但是如何更改目录树下的所有文件。可以dos2unix递归更改文件吗?
for example, I have some files like following:
例如,我有一些文件如下:
TOPDIR
|
+-----dir1
| |
| +---file1,file2, file3
|
+-----dir2
|
+---file4,file5
How can I change them in one time, or use some shell scripts?
如何一次性更改它们,或使用一些 shell 脚本?
回答by Andrey Dmitriev
better to do find /path -type -f -exec dos2unix '{}' \;
最好做 find /path -type -f -exec dos2unix '{}' \;
回答by Unknown
find /path -name '*' -type f -exec dos2unix {} \;
find /path -name '*' -type f -exec dos2unix {} \;
回答by Sergei Nikulov
dos2unix -k `find . -type f`
find . -type f -exec dos2unix -k '{}' \;
find . -type f -print | xargs dos2unix -k
Any of above command can be used from TOPDIR
上面的任何命令都可以从 TOPDIR 使用

