Snippet to remove caps and spaces from filename

Remove caps and spaces from names in files in current directory with tr command. First step is parse the name of the file or directory and then rename it.

 bash | 
 
 copy code |
?

1
for f in *; do
2
     file=$(echo $f | tr A-Z a-z | tr ' ' _)
3
     [ ! -f $file ] && mv "$f" $file
4
done
5