Including the extension. Eg file.txt --> FILE.TXT
If anyone could point me in the general direction then I'd be grateful :)
And here is just some random text because the character count was too low for Stackoverflow...
Including the extension. Eg file.txt --> FILE.TXT
If anyone could point me in the general direction then I'd be grateful :)
And here is just some random text because the character count was too low for Stackoverflow...
An initial solution would be:
rename 'y/a-z/A-Z/' *
It takes every file/directory in current directory, and changes every character in the range a-z by its corresponding uppercase version.
The problem with rename
is there is no option to go inside directories to apply the renaming recursively, and *
character is expanded to names of current directory (files and directories). Even more, this command will rename directories also, but you only want to rename files.
To do it recursively, but over files only, you can use find
, which search recursively, and pass each file to rename
:
find . -type f -execdir rename 'y/a-z/A-Z/' {} \;
This command searches only files, and executes rename
over each file inside the directory (execdir
option) where that file has been found. That's important because otherwise find
will pass the complete path of the file (eg: ./fold1/fold2/file.txt') to rename
, which in turns will try to pass to uppercase the complete path: (./FOLD1/FOLD2/FILE.TXT) which will cause an error because folders FOLD1
and FOLD2
don't exist.
Using bash, this is easy:
for f in *; do mv "$f" "${f^^}"; done
The expansion ${f^^}
converts the name of the file to uppercase.
In another shell, using tr
:
for f in *; do mv "$f" "$(echo "$f" | tr '[:lower:]' '[:upper:]')"; done
I would suggest something like that:
ls|sed 's/\(.*\)/mv "\1" "\U\1"/' | sh
I like to use sed this way, because it is easy to inspect the output before piping it into sh (removing |sh
in a first step)
Using perl
perl -e 'for (glob "*.txt" ){ rename $_,uc($_)}'
glob "*"
creates a list of all the .txt files in the current directory.
rename
replaces each value with a uc
(uppercase) value.