Remove Whitespace From All Filenames in the current directory
http://www.gautamk.com/blog/2012/09/07/remove-whitespace-from-all-filenames/
Bash :
for i in * ; do
if [ $i != ${i//[[:space:]]} ] ; then
mv $i ${i//[[:space:]]}
fi
done
Another one by chepner
for old in *; do
new="${old//[[:space:]]}"
[[ $old = $new || -f $new ]] || mv "$old" "$new"
done
Python :
import os
for f in os.listdir("."):
r = f.replace(" ","")
if( r != f):
os.rename(f,r)
Here is the related stackoverflow question
Written by Gautam
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#