Working on a file with spaces within its name is is always a headache in Linux. The best way is to rename them to eliminate spaces. For a normal user, even this is guaranteed to give pain if there are a lot of files. Here is the shortcut to do it:
I had a directory with songs that I ripped from a CD which had spaces in name. So i decided to replace the spaces with underscores.
safeer@enjoyfast-lx:~/Music/ONV-Shahbaz-Venugopal/Sahayathrikey$ ls -l
total 57284
-rw-r–r– 1 safeer safeer 6124954 2008-11-06 01:29 01 - Track 1.ogg
-rw-r–r– 1 safeer safeer 5647099 2008-11-06 01:29 02 - Track 2.ogg
-rw-r–r– 1 safeer safeer 5954106 2008-11-06 01:30 03 - Track 3.ogg
-rw-r–r– 1 safeer safeer 5783244 2008-11-06 01:30 04 - Track 4.ogg
-rw-r–r– 1 safeer safeer 5951001 2008-11-06 01:30 05 - Track 5.ogg
-rw-r–r– 1 safeer safeer 6212981 2008-11-06 01:31 06 - Track 6.ogg
-rw-r–r– 1 safeer safeer 5580947 2008-11-06 01:31 07 - Track 7.ogg
-rw-r–r– 1 safeer safeer 5519893 2008-11-06 01:31 08 - Track 8.ogg
-rw-r–r– 1 safeer safeer 5092362 2008-11-06 01:32 09 - Track 9.ogg
-rw-r–r– 1 safeer safeer 6653648 2008-11-06 01:32 10 - Track 10.ogg
Replace space with underscore is done by “tr” utility.
safeer@enjoyfast-lx:~/Music/ONV-Shahbaz-Venugopal/Sahayathrikey$ ls|while read FILE;do mv “$FILE” `echo $FILE|tr ‘ ‘ ‘_’`;done
safeer@enjoyfast-lx:~/Music/ONV-Shahbaz-Venugopal/Sahayathrikey$ ls -l
total 57284
-rw-r–r– 1 safeer safeer 6124954 2008-11-06 01:29 01_-_Track_1.ogg
-rw-r–r– 1 safeer safeer 5647099 2008-11-06 01:29 02_-_Track_2.ogg
-rw-r–r– 1 safeer safeer 5954106 2008-11-06 01:30 03_-_Track_3.ogg
-rw-r–r– 1 safeer safeer 5783244 2008-11-06 01:30 04_-_Track_4.ogg
-rw-r–r– 1 safeer safeer 5951001 2008-11-06 01:30 05_-_Track_5.ogg
-rw-r–r– 1 safeer safeer 6212981 2008-11-06 01:31 06_-_Track_6.ogg
-rw-r–r– 1 safeer safeer 5580947 2008-11-06 01:31 07_-_Track_7.ogg
-rw-r–r– 1 safeer safeer 5519893 2008-11-06 01:31 08_-_Track_8.ogg
-rw-r–r– 1 safeer safeer 5092362 2008-11-06 01:32 09_-_Track_9.ogg
-rw-r–r– 1 safeer safeer 6653648 2008-11-06 01:32 10_-_Track_10.ogg
If you want to eliminate spaces in the file name use:
ls|while read FILE;do mv “$FILE” `echo $FILE|tr -d ‘ ‘ `;done
No comments:
Post a Comment