Remove last three characters from all filenames in a directory
I have a directory with about 10 files and I want to remove the last three characters from the names of all of these files. Anyone know a terminal command that can do this?
And separately, how would I change the characters in the names of all these files to lowercase?
Solution 1:
Remove last three characters from all filenames in current directory:
rename 's/...$//' *
Change the characters in the names of all files from current directory to lowercase:
rename 'y/A-Z/a-z/' *
For more info see man rename
.
Solution 2:
Remove the last 3 characters:
for i in *
do
j=`echo $i | sed -e 's/...$//'`
mv $i $j
done
Change names to lower case:
for i in *
do
j=`echo $i | tr A-Z a-z`
mv $i $j
done