Use rename
, which is a Perl script and maybe on your system already. You can use the rename command to quickly rename files using a regular expression pattern. For instance, if you wanted to rename all files containing foo to contain bar instead, you could use a command like this one:
1rename –v 's/foo/bar/g' *
1for f in * ; do cp "$f" 2014-08-26-"$f" ; done
1mv $f ${f#[0-9]*-}
Test
1$ ls
223-a aa23-a hello
3$ for f in *; do mv $f ${f#[0-9]*-}; done
4$ ls
5a aa23-a hello
Let’s say you have image files named like this:
The following will rename all these .jpg files and remove the space in file name.
1IFS="\n"
2for file in *.jpg;
3do
4 mv "$file" "${file//[[:space:]]}"
5done
1rename "s/ /_/g" *
OR, if you don’t have rename
1for f in *\ *; do mv "$f" "${f// /_}"; done
1find -name "* *" -type f | rename 's/ /_/g'
1find -name "* *" -type d | rename 's/ /_/g'
1find /tmp/ -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;
/tmp/
is the folder where you are looking for files,