Bash Help: Renaming all files in a Directory
Mikkel L. Ellertson
mikkel at infinity-ltd.com
Sat Jul 22 00:45:59 UTC 2006
Todd Zullinger wrote:
>>> Off the top of my head...
>>> $ for f in *.jpg; do; mv $f `echo $f | sed 's/ //g'`; done
>
> The spaces in the file names will make this fail. The loop will split
> the files at the spaces, so you'd end up with f=Family, then f=Pic,
> etc. You can muck around with the IFS variable, but to me it always
> seems easier to just use a while loop instead. :)
>
No, the loop will have f=Family Pic 001.jpg but the mv command will
fail unless you use "$f" because mv will see it as 3 file names,
split at the spaces.
[mikkel backup]$ ls G*
Giraffe High Score.prc Graffiti.prc Graffiti ShortCuts .prc
[mikkel backup]$ for f in G* ; do echo $f ; done
Giraffe High Score.prc
Graffiti.prc
Graffiti ShortCuts .prc
Mikkel
--
Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!
More information about the fedora-list
mailing list