If all the files are in the same directory (no recursion is necessary), you are almost there.
for file in /tmp/testFiles/*.xml ; do dos2unix "$file" done
By default, dos2unix
should convert to place and overwrite the original.
If you need recursion, you will also need to use find
:
find /tmp/testFiles -name '*.xml' -print0 | while IFS= read -d '' file ; do dos2unix "$file" done
That will work with all files ending in .xml
in /tmp/testFiles/
and in all its subdirectories.
If no other step is required, you can skip the shell loop completely:
nonrecursive:
find /tmp/testFiles -maxdepth 1 -name '*.xml' -exec dos2unix {} +
And for recursive:
find /tmp/testFiles -name '*.xml' -exec dos2unix {} +
In the original command, I see that you find the base name of each file name and try to transfer it to dos2unix
, but your intentions are not clear. Later in the comment, you say that you just want to overwrite the files. My solution performs the conversion, does not back up and overwrites the original with the converted version. Hope this was your intention.
source share