Cool stuff for removing space in your file and folders names.This command will remove a whitespace and change it to underscore character “_” . Open your terminal. Changes path to your working folders. Caution, this command will affect all of your files and folders recursively. Then do this command :
a. Remove spaces in current folders:
user@machine~>rename -v 's/\ /\_/g' *
b. Remove spaces in all files and one sub folder:
user@machine~>rename -v 's/\ /\_/g' */*
note:
* -> in current folders only (ex : folder1)
*/* -> in current and sub folders (ex: folder1/folder2)
*/*/* -> in current, sub folders, sub folders (ex: folder1/folder2/folder3)
Just simply changes */* with your folder depth needs.


Maksud dari ini apa bos,. >> -v ‘s/\ /\_/g’ *
-v = ?
‘s/\/\_/g’= ?
Why are you so lazy to type “man” in your console mamen… ^_!
v, --verbose
Verbose: print names of files successfully renamed.
in rename commands the matching and rename pattern are separated by forward slash ( / ) sign.
's/\ /\_/g', just simple perl expression, it can said something likes :
"found just one (s) space character (/\ ) and ( / ) replace it with underscore (\_)
/g modifiers means -> rename every space in the files or folder names into underscore.
This is an incredibly useful post, and I thank you for taking the time. I’ve been using rename to remove whitespace for quite some time, but in a script I’m writing now I’d like to be able to do it recursively. I do not want to have to manually specify the depth of the directory trees, because I don’t want to expect the user to know it!
Any ideas?
Hello Connor,
Just walking into whole directory, at the same time run the rename commands. Like this:
#!/bin/sh
#change MYPATH variable to your own path
MYPATH="/home/teknosoft-machine/Desktop/test/"
cd $MYPATH
find -type d | while read directory
do
echo "diving into : ${directory#"./"}"
cd $MYPATH."/${directory#"./"}"
rename -v 's/\ /\_/g' *
done
Sorry for the comment spam, but the relevant explanation which I should have included in the comment above is available in the Perl documentation: