Reputation: 24248
I need to set case of all files to lowercase:
directory11
subdirectory11
subdirectory21
File1
File2
...
Filen
directory21
subdirectory21
subdirectory21
File1
File2
...
Filen
..............................................
directory11
subdirectory11
subdirectory21
file1
file2
...
filen
directory21
subdirectory21
subdirectory21
file1
file2
...
filen
..............................................
Does it possible with linux command? Thanks.
Upvotes: 1
Views: 580
Reputation: 11395
One of many possible options is using tr
to change the case. Find all the files using find
in the directory. Create the upper file name string using tr
& use mv
to rename. Something on these lines:
while read OLD_FILENAME
do
NEW_FILENAME=`echo "$OLD_FILENAME"|tr [:upper:] [:lower:]`
mv -v "$OLD_FILENAME" "$NEW_FILENAME"
done < <(find directory_name -type f)
Or if you want interactive mode for mv
i.e ask for replacement confirmation use something on these lines:
(
IFS=$'\n'
for OLD_FILENAME in $(find directory_name -type f)
do
NEW_FILENAME=`echo "$OLD_FILENAME"|tr [:upper:] [:lower:]`
mv -vi "$OLD_FILENAME" "$NEW_FILENAME"
done
)
Hope this helps!
Upvotes: 1
Reputation: 185073
You should consider to using rename(1)
command :
rename 'y/A-Z/a-z/' **
**
mean recursive if you are using bash4 and globstar
setting :
shopt -s globstar
Moreover, this is the perl version of rename
. If you type
file $(readlink -f $(type -p rename))
and you see ELF
, you have the wrong one, see prename
Upvotes: 1