This blog entry is related to old post here. The only difference is that this time around it would be done recursively.
If you have hundreds of files with a common filename located from direcoty and its subdirectories, and you wish to have their filenames renamed to fielname with all uppercase letters - this blog can provide the concept on how to achieve that. And if you wish to remove space character from those hundreds of filename recursively, this blog entry can spark the idea on how to do that as well.
HowTo: Rename multiple files recursively
Supposed we want to rename all *.mp3 files with lowercase characters to *.mp3, you will the concept below on how to do this.
Sample scenario #1
# cd /tmp
# find /tmp/songs *.mp3 -type f
output:/tmp/songs/filefile1.mp3
/tmp/songs/dir1/file2.mp3
/tmp/songs/dir1/dir5/file3.mp3
/tmp/songs/dir2/dir3/dir4/file6.mp3
/tmp/songs/dir2/dir3/file5.mp3
/tmp/songs/dir2/file4.mp3
/tmp/songs/file1.mp3
file1.mp3
filefile1.mp3
An overview of these MP3 files in tree view
The next step is to rename all these *.mp3 file collections into its uppercase form filenames and do it recursively. This can be done using combinations of linux command done in loop concept.
From this blog entry, we would be renaming their *.mp3 filenames into a filename with all uppercase letters. There are hundreds of ways to do it and here's one way to achieve this goal.
# for file in `find /tmp/songs *.mp3 -type f`; do uppername=`basename $file | tr [:upper:] [:lower:]`; dirs=`dirname $file`; mv $file $dirs/$uppername; done
The modular equivalent of the above command would be like# fetch those *.mp3 files recursively starting from /tmp/songs
for file in `find /tmp/songs *.mp3 -type f`;
do
# convert filename (without the directory path) to uppercase
uppername=`basename $file | tr [:lower:] [:upper:]`;
# preserved the directory path
# to avoid attempts of renaming/moving directory as well
dirs=`dirname $file`;
# now rename smallfilename to BIGFILENAME appended from original directory path
mv $file $dirs/$uppername;
done
# exit
You can modify the above and change a few lines of it or maybe use a while loop instead of for loop. You can also use xargs for passing arguments but the concept would still be the same of changing the the lowercase letters to uppper case letters of filenames recursively.
Take a look on what we have achieved using a one line renaming of multiple files# find /tmp/songs *.MP3 -type f
output:
/tmp/songs/dir1/FILE2.MP3
/tmp/songs/dir1/dir5/FILE3.MP3
/tmp/songs/dir2/FILE4.MP3
/tmp/songs/dir2/dir3/dir4/FILE6.MP3
/tmp/songs/dir2/dir3/FILE5.MP3
/tmp/songs/FILE1.MP3
/tmp/songs/FILEFILE1.MP3
FILE1.MP3
FILEFILE1.MP3
Noticed that all lowercase MP3 files are converted to their uppercase form, which was done on recursive manner. You can also apply this approach to recursively rename and remove space characters from filenames under group subdirectory folder locations.
Linux makes simple task easier.
Hope this helps.
HowTo: Delete All Thumbs.db Recursively
HowTo: Find And Count JPG Files Recursively
Delete Zero-sized Filename Recursively
Find Hidden Linux File Recursively
Move Linux Files Recursively
Rename Linux File Recursively
Delete Files and Folders Recursively
Subscription
Categories
- HowTos (612)
- Linux Devices (40)
- Linux Diggs (620)
- Linux News (1541)
- Linux Videos (24)
Recent Posts
Blog Archive
-
▼
2007
(340)
-
▼
December
(38)
- Holiday Linux
- HowTo: Chikka messenger over GAIM Pidgin Messenger
- HowTo: Rename Multiple Files Without A Script
- HowTo: KDocker/AllTray - System Tray Docking
- HowTo: Thunderbird - News/Feed Reader
- HowTo: ThinFeeder - RSS/RDF/Atom Aggregator
- HowTo: Sage - Firefox Feed Reader Extension
- HowTo: Snownews - RSS/RDF Newsreader
- HowTo: Planet - RDF/RSS/Atom Feed Aggregator
- HowTo: Liferea - RSS/RDF Feed Reader
- HowTo: Blam - RSS/RDF Feed Reader
- Switching Hospital Systems to Linux
- HowTo: CSS Editor and Validator Install
- HowTo: Ebook Reader Install
- vertito's blogspot anniversary
- HowTo: Install 113 Amazing Fedora Games Part 8
- HowTo: Install 113 Amazing Fedora Games Part 7
- HowTo: Install 113 Amazing Fedora Games Part 6
- HowTo: Install 113 Amazing Fedora Games Part 3
- HowTo: Install 113 Amazing Fedora Games Part 2
- HowTo: Thunar File Manager
- HowTo: LeafPad Extremely Fast Text File Editor
- HowTo: View Bzipped file On-The-Fly
- HowTo: TuxPaint Drawing Program Installation
- HowTo: InkScape Drawing Program Installation
- HowTo: Adobe Flash Player on Fedora 8
- HowTo: Install Digital Comic Reader
- HowTo: Install 113 Amazing Fedora Games
- HowTo: Translate Find Statements to Perl Codes
- HowTo: Single Step VirtualBox Installation on Fedo...
- CLI Tip: Control Terminal Keystroke Combinations
- CLI Tip: Clearing Terminal Screen
- HowTo: Linux Aliasing Aliases
- HowTo: Move Multiple Files Recursively
- HowTo: Rename multiple files recursively
- HowTo: Strip Non-Directory Path Suffix from FileName
- HowTo: Generate Pronounceable Random Passwords
- HowTo: Determine RedHat and Fedora release version
-
▼
December
(38)
Saturday, December 1, 2007
HowTo: Rename multiple files recursively
Subscribe to:
Post Comments (Atom)
ILoveTux - howtos and news | About | Contact | TOS | Policy
1 comments:
Fixnames is a script that does recursive renaming of files AND directories, with full logging, --pretend option, progress indicator, simple duplicate file detection. it includes a sed line to make a tree have valid names on a fat/ntfs file system.
Post a Comment