如何在整个目录上运行dos2unix ?

时间:2022-09-02 18:40:07

I have to convert an entire directory using dos2unix. I am not able to figure out how to do this.

我必须使用dos2unix转换整个目录。我不知道该怎么做。

7 个解决方案

#1


348  

find . -type f -print0 | xargs -0 dos2unix

找到。-type f -print0 | xargs -0 dos2unix。

Will recursively find all files inside current directory and call for these files dos2unix command

递归地查找当前目录中的所有文件,并要求这些文件dos2unix命令?

#2


51  

If it's a large directory you may want to consider running with multiple processors:

如果它是一个大的目录,您可能需要考虑使用多个处理器运行:

find . -type f -print0 | xargs -0 -n 1 -P 4 dos2unix 

This will pass 1 file at a time, and use 4 processors.

这将一次传递一个文件,并使用4个处理器。

#3


13  

As I happened to be poorly satisfied by dos2unix, I rolled out my own simple utility. Apart of a few advantages in speed and predictability, the syntax is also a bit simpler :

当我碰巧对dos2unix感到不满意时,我推出了自己的简单实用程序。除了在速度和可预测性方面的一些优势之外,语法也更简单一些:

endlines unix *

And if you want it to go down into subdirectories (skipping hidden dirs and non-text files) :

如果你想让它进入子目录(跳过隐藏的dirs和非文本文件):

endlines unix -r .

endlines is available here https://github.com/mdolidon/endlines

endlines在这里可以使用https://github.com/mdolidon/endlines。

#4


12  

It's probably best to skip hidden files and folders, such as .git. So instead of using find, if your bash version is recent enough or if you're using zsh, just do:

最好跳过隐藏的文件和文件夹,比如.git。所以不要使用find,如果您的bash版本最近足够了,或者您正在使用zsh,只需:

dos2unix **

Note that for Bash, this will require:

请注意,对于Bash,这将需要:

shopt -s globstar

....but this is a useful enough feature that you should honestly just put it in your .bashrc anyway.

....但这是一个有用的特性,你应该把它放在。bashrc中。

If you don't want to skip hidden files and folders, but you still don't want to mess with find (and I wouldn't blame you), you can provide a second recursive-glob argument to match only hidden entries:

如果您不想跳过隐藏的文件和文件夹,但是您仍然不希望发现(我不会责怪您),您可以提供第二个递归glob参数来匹配隐藏的条目:

dos2unix ** **/.*

Note that in both cases, the glob will expand to include directories, so you will see the following warning (potentially many times over): Skipping <dir>, not a regular file.

注意,在这两种情况下,glob将扩展到包含目录,因此您将看到以下警告(可能多次):跳过

,而不是常规文件。

#5


4  

For any Solaris users (am using 5.10, may apply to newer versions too, as well as other unix systems):

对于任何Solaris用户(使用5.10,可能也适用于较新的版本,以及其他unix系统):

dos2unix doesn't default to overwriting the file, it will just print the updated version to stdout, so you will have to specify the source and target, i.e. the same name twice:

dos2unix不默认覆盖文件,它只会将更新后的版本打印到stdout,因此您必须指定源和目标,即相同的名称两次:

find . -type f -exec dos2unix {} {} \;

#6


0  

for FILE in /var/www/html/files/*
do
/usr/bin/dos2unix FILE
done

在/var/www/html/文件/* do /usr/bin/dos2unix文件中完成。

#7


-1  

If there is no sub-directory, you can also takels | xargs -I {} dos2unix "{}".

如果没有子目录,您也可以使用| xargs -I {} dos2unix“{}”。

#1


348  

find . -type f -print0 | xargs -0 dos2unix

找到。-type f -print0 | xargs -0 dos2unix。

Will recursively find all files inside current directory and call for these files dos2unix command

递归地查找当前目录中的所有文件,并要求这些文件dos2unix命令?

#2


51  

If it's a large directory you may want to consider running with multiple processors:

如果它是一个大的目录,您可能需要考虑使用多个处理器运行:

find . -type f -print0 | xargs -0 -n 1 -P 4 dos2unix 

This will pass 1 file at a time, and use 4 processors.

这将一次传递一个文件,并使用4个处理器。

#3


13  

As I happened to be poorly satisfied by dos2unix, I rolled out my own simple utility. Apart of a few advantages in speed and predictability, the syntax is also a bit simpler :

当我碰巧对dos2unix感到不满意时,我推出了自己的简单实用程序。除了在速度和可预测性方面的一些优势之外,语法也更简单一些:

endlines unix *

And if you want it to go down into subdirectories (skipping hidden dirs and non-text files) :

如果你想让它进入子目录(跳过隐藏的dirs和非文本文件):

endlines unix -r .

endlines is available here https://github.com/mdolidon/endlines

endlines在这里可以使用https://github.com/mdolidon/endlines。

#4


12  

It's probably best to skip hidden files and folders, such as .git. So instead of using find, if your bash version is recent enough or if you're using zsh, just do:

最好跳过隐藏的文件和文件夹,比如.git。所以不要使用find,如果您的bash版本最近足够了,或者您正在使用zsh,只需:

dos2unix **

Note that for Bash, this will require:

请注意,对于Bash,这将需要:

shopt -s globstar

....but this is a useful enough feature that you should honestly just put it in your .bashrc anyway.

....但这是一个有用的特性,你应该把它放在。bashrc中。

If you don't want to skip hidden files and folders, but you still don't want to mess with find (and I wouldn't blame you), you can provide a second recursive-glob argument to match only hidden entries:

如果您不想跳过隐藏的文件和文件夹,但是您仍然不希望发现(我不会责怪您),您可以提供第二个递归glob参数来匹配隐藏的条目:

dos2unix ** **/.*

Note that in both cases, the glob will expand to include directories, so you will see the following warning (potentially many times over): Skipping <dir>, not a regular file.

注意,在这两种情况下,glob将扩展到包含目录,因此您将看到以下警告(可能多次):跳过

,而不是常规文件。

#5


4  

For any Solaris users (am using 5.10, may apply to newer versions too, as well as other unix systems):

对于任何Solaris用户(使用5.10,可能也适用于较新的版本,以及其他unix系统):

dos2unix doesn't default to overwriting the file, it will just print the updated version to stdout, so you will have to specify the source and target, i.e. the same name twice:

dos2unix不默认覆盖文件,它只会将更新后的版本打印到stdout,因此您必须指定源和目标,即相同的名称两次:

find . -type f -exec dos2unix {} {} \;

#6


0  

for FILE in /var/www/html/files/*
do
/usr/bin/dos2unix FILE
done

在/var/www/html/文件/* do /usr/bin/dos2unix文件中完成。

#7


-1  

If there is no sub-directory, you can also takels | xargs -I {} dos2unix "{}".

如果没有子目录,您也可以使用| xargs -I {} dos2unix“{}”。