Currently, I am using the following command to change dos2unix line endings, but this is for file-y file...
sed -i \'s/\\r//\' filename
Is ther
Just adding another reference ...
On Ubuntu 14.04 the man dos2unix
page provides this example, specifically for recusive conversion:
find . -name *.txt | xargs dos2unix
Quoting from the man page, this will
... convert all the .txt files in the directory tree under the current directory ...
The simplest way to run dos2unix
against an entire directory recursively is to just have the find
command execute it for each file it finds based on your criteria.
For example, to find all files (excluding directory names) in your current directory and all its sub-directories and have dos2unix
do the default conversion on each of those files:
find . -type f -exec dos2unix -k -s -o {} ';'
This will output every single filename, but not necessarily change each of them. This works as follows:
find .
: Find anything in this directory, including its subdirectories, and anything in those subdirectories as well (recursion)
-type f
: Only return 'regular file' names. Exclude folder names from the results.
-exec
: Execute the following command for every result. Everything beyond this point should be treated as part of that command until the ;
character is found.
dos2unix
: dos2unix
will be executed with the following options...
-k
: Keep the date stamp of the output file the same as the input file
-s
: Skip binary files (images, archives, etc.). This option is included by default, but I use it anyway in case that default were different on some systems (e.g. OS X v. Debian v. CentOS v. Ubuntu v. ...).
-o
: Write the changes directly to the file, rather than creating a new file with the data in the new format.
{}
: This tells find
to insert the filename it has found as a parameter of the dos2unix
call.
';'
: Tell find
that the params for dos2unix
have ended. Anything beyond this point will again be treated as a parameter of find
.
for i in `find . -type f \( -name "*.c" -o -name "*.h" \)`; do sed -i 's/\r//' $i ; done
Another option: find your_dir type f -exec sed -i 's/\r//' {} \;
Why aren't you using dos2unix command? If your'e doing just the sed above there might be files (depending on their source) that will have incorrect EOF (you can see it if you run cat and the prompt afterwards is concatenated to the file output)
use
for i in `ls directory_path`; do sed -i 's/\r//' $i ; done
for entire directory.
find $(pwd) -type f | xargs -I xxx sed -i 's/\r//g' xxx