Is there a way to rename all files in a directory to lowercase|uppercase?
I am looking for a oneliner command.
I loved TotalCommander's Alt + F7, now I need that functionality in the Terminal.
Is there a way to rename all files in a directory to lowercase|uppercase?
I am looking for a oneliner command.
I loved TotalCommander's Alt + F7, now I need that functionality in the Terminal.
For each file
a_file
in current directory renamea_file
to lower case.For upper case reverse the arguments to
[:lower:] [:upper:]
tr
command reference linkUpdate
For even more control
*
can be replaced withls
.For example in a directory containing 1.txt, 2.txt, 3.txt, 1.jpg, 2.jpg and 3.jpg in order to filter only *.jpg files,
ls
can be used:The above code will assign to
a_file
variable all files with .jpg extension.Update added
-v
option tomv
command as per sds suggested.There's a more elegant and general utility called
prename
.Written by Larry Wall, it comes with
perl
so it is most likely already available on your system as/usr/bin/prename
(if you have setup alternatives is may also be available as/usr/bin/rename
symlinked via /etc/alternatives toprename
)Using it you can rename multiple files in one command by providing any perl expression (including but not limited to substitution
s///
or char transliterationtr///
):Examples:
And so on.
Another nice thing about prename is that it protects you, in the case of renaming a file to an existing file name.
man prename
for more details.Using
find
For
find
-name
put your pattern.-maxdepth 0
: Only current directory.For
rename
-n, -nono
: No action: print names of files to be renamed, but don't rename.y/source/dest/
: Transliterate the characters in the pattern space which appear in source to the corresponding character in dest.Using
mmv
to convert matched string to uppercase:Its important to quote the pattern otherwise it will expand the wildcard instead.