LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   How can I find all files ending with a \r (http://www.linuxquestions.org/questions/linux-general-1/how-can-i-find-all-files-ending-with-a-%5Cr-4175478285/)

andrew777 09-23-2013 09:46 PM

How can I find all files ending with a \r
 
Hello,

I have some files that were accidentally created with a \r at the end of the name because of a transfer from Windows to Linux.

Example:
file1.html\r

Can someone tell me what the syntax of a recursive list command would be to find all files that have a \r as the last character.

Thank you

TobiSGD 09-23-2013 10:46 PM

Code:

ls -R *\\r
If you use Zsh instead of Bash
Code:

echo **/*\\r
should also work.

andrew777 09-24-2013 07:47 AM

It did not work for me...

$ ls -R *\\r
/bin/ls: cannot access *\\r: No such file or directory
$ ls -R \*\\r
/bin/ls: cannot access *\\r: No such file or directory

schneidz 09-24-2013 08:29 AM

this worx for me:
Code:

[schneidz@hyper cobra]$ ll /home/schneidz/music
total 21452
-rw-rw-r--. 1 schneidz schneidz 17747542 Jun 22 14:26 08-k.i._-_machal_montano-single_forever.flac
drwxr-xr-x. 2 schneidz schneidz    4096 Feb 11  2013 midnight-marauders
drwxr-xr-x. 2 schneidz schneidz    4096 Feb 11  2013 perceptionists-black-dialogue
-rw-rw-r--. 1 schneidz schneidz  4207742 Jun 22 14:29 sf.mp3
-rw-rw-r--. 1 schneidz schneidz        0 Sep 24 08:27 test\r
[schneidz@hyper cobra]$ ll /home/schneidz/music/*'\r'
-rw-rw-r--. 1 schneidz schneidz 0 Sep 24 08:27 /home/schneidz/music/test\r


Firerat 09-24-2013 09:00 AM

Not sure these tests are working correctly
Actually not so easy to create

Code:

for i in {01..20};do echo -e Test${i}.txt\\r;done | while read line;do touch $line;done
mv them around a little now find them with find

Code:

find . -name "*^M"
NOTE:
^M is special.. to get it Ctrl+v ( release ) <enter>


I assume you would like to fix these

Code:

find -name "*^M" | while read File;do mv -v "${File}" "${File%^M}";done
Again, ^M is Ctrl+v<enter>


All times are GMT -5. The time now is 05:01 PM.