Skip to Content Skip to Navigation Menu

Archives

My Amazon Wishlist

My Amazon.com Wish List
qrcode

Linux-fu: Remove spaces from all filenames in a directory

Posted Saturday the 14th of March, 2009 by Robert Carpenter

I needed to remove spaces from a whole list of files in a directory. A short bash script took care of it easy:

$ for file in *; do 
> newFile=$(echo $file | tr ' ' _)
> mv "$file" $newFile
> done

To do this recursively:

$ for file in `find .`; do 
> newFile=$(echo $file | tr ' ' _)
> mv "$file" $newFile
> done

No Comments Posted.

Post a comment:

You will be taken to a CAPTCHA in order to help curb spamming.
Privacy Policy

A random XKCD comic.

I'm An Idiot