Re: Bash Help: Renaming all files in a Directory

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

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mikkel L. Ellertson wrote:
> 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.

D'oh!  I should be more careful before correcting anyone.  My
apologies to Patrick and for spreading misinformation. :)

Using a simple patter in the for loop works, it's things where you get
the loop item from a command that it doesn't work.  If you had a file
with some names and tried to do

    for i in $(cat filename); do ...

then you run into the problem I was thinking of.  Even using

    for i $(ls *.jpg); do ...

is a problem (though it's pointless to do it that way).

Anyway, thanks for the correction Mikkel.

- -- 
Todd        OpenPGP -> KeyID: 0xD654075A | URL: www.pobox.com/~tmz/pgp
======================================================================
With reasonable men I will reason; with humane men I will plead; but
to tyrants I will give no quarter.
    -- William Lloyd Garrison

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (GNU/Linux)
Comment: When crypto is outlawed bayl bhgynjf jvyy unir cevinpl.

iG0EARECAC0FAkTBgr4mGGh0dHA6Ly93d3cucG9ib3guY29tL350bXovcGdwL3Rt
ei5hc2MACgkQuv+09NZUB1rngwCgu7Fua+dvV8mTpPAI9LPsDK59I5AAoJOkLdXr
nhA+Cajc/oObBU9NKMlm
=RsRB
-----END PGP SIGNATURE-----

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux