Re: How do I get a list of filenames with spaces on bash?





On 1/24/2008 11:38 AM, Stephane Chazelas wrote:
On Thu, 24 Jan 2008 11:04:29 -0600, Ed Morton wrote:
[...]

cp -- "$f" "$n" &&
rm -- "$f"

[...]

Why not mv? cp won't work great for non-regular files.

To ensure that in the event of a failure the original file is unaffected.


in that case, mv doesn't affect the file not even its inode, it
affects the current directory, it's just a rename. A failing
rename just leaves things as they are.

Huh, I didn't realise that "mv" was totally safe. Then I'd just use:

for f in *\ *
do
n="${f// /_}"
[ ! -f "$n" ] &&
mv -- "$f" "$n"
done

Thanks for the tip.

Ed.

.



Relevant Pages

  • Re: How do I get a list of filenames with spaces on bash?
    ... To ensure that in the event of a failure the original file is unaffected. ... in that case, mv doesn't affect the file not even its inode, it ... affects the current directory, it's just a rename. ... A failing cp may leave an ...
    (comp.unix.shell)
  • Re: trouble with msconfig.exe
    ... The original file has been renamed to msconfig.old (I don't know the ... msconfig.exe directly from Windows installation CD-Rom (it's Windows XP ... I can't rename or delete msconfig.old. ... Be sure the machine is clean first: ...
    (microsoft.public.windowsxp.general)
  • Re: lots of _RBLDAxxxx after table rebuilt
    ... The rebuild utility does not rename the original file until the ... rename that rebuild does after it rebuilds the file. ... Just do like the rebuild utility would do and delete the original ...
    (comp.databases.btrieve)
  • Re: How can I do a 100% bullet proof Save?
    ... original file is left with the wrong name. ... of failure - namely the final rename. ... to rename the original file back to its original file name, ... fails. ...
    (microsoft.public.vc.mfc)
  • Re: STILL Unable to use YUM to update
    ... John Moore wrote: ... I tried to rename it but it won't rename. ... result from an editor renaming the original file as a backup when saving ... If that backup file contains anything ...
    (Fedora)