Bash Help: Renaming all files in a Directory

Patrick Doyle wpdster at gmail.com
Fri Jul 21 23:50:35 UTC 2006


On 7/21/06, Thom Paine <painethom at gmail.com> wrote:
> I'm making a digital picture frame out of an old laptop and the pic
> viewer doesn't support filenames with spaces in them.
>
> Is there a quick command I can type to process all files in a
> directory that will rename the files from "Family Pic 001.jpg" to
> "FamilyPic001.jpg"?
>
Off the top of my head...
$ for f in *.jpg; do; mv $f `echo $f | sed 's/ //g'`; done

(Be careful about the back (single) quotes and the forward single quotes.

BTW, when I write little shell ditties like this, I usually starft with:

$ for f in *.jpg; do; echo mv $f `echo $f | sed 's/ //g'`; done

(Notice the "echo" command conveniently placed to avoid actually doing
anything.)

Also, I usually try the command on a _copy_ of my original directory
(cp -a old_dir new_dir) first, just in case...

hth

--wpd




More information about the fedora-list mailing list