Re: Bash Help: Renaming all files in a Directory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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!


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux