Re: Spaces in file names



Leslie Rhorer inquired:
OK, here's the problem. I need to automatically manipulate the file
names of a number of files whose filenames have spaces in them.

Paul Pluzhnikov suggested by example:
$ touch "a b" "c d" "e f g"
$ ls -1
a b
c d
e f g

$ find . -type f | while read line; do mv "$line" "$line.bak"; done
$ ls -1
a b.bak
c d.bak
e f g.bak
$

Leslie Rhorer replied:
[That suggestion] won't work. As I said in theoriginal post, I
already thought of this.


No, you didn't. Note Paul's use of "while read line". That works
to deal with any character in a filename except newline, but using
"for file in ..." does not (unless you adjust $IFS, and that has
pitfalls of its own.)

RTFM. Seriously: "man find" or "info find". The option "-print0"
was made exactly for dealing with filenames that contain arbitrary
characters, including newline. See also "man xargs" for the "-0" option.

[Also, do not "top post." That might work for social or managerial
correspondence, but it is obnoxious in a technical conversation.
Instead, place your reply paragraph immediately _below_ the quoted
portion to which it responds. Then the reader can follow the chronology
much more easily.]

--
.



Relevant Pages

  • portable pathname construction tools anywhere?
    ... I was unable to find a set of tools that handles dealing with ... filenames and pathnames correctly. ... Thx a lot. ... Regards, ...
    (comp.lang.lisp)
  • Re: Deployment Project Question
    ... > When dealing with filenames, ... will get you the parent of the current ... folder, so given this structure: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Loading an Access database in code
    ... for dealing with long filenames. ... Ian ... Prev by Date: ...
    (microsoft.public.dotnet.languages.vb)
  • Unicode file names
    ... Does anyone know if there are any articles about dealing with Unicode ... filenames in Delphi. ... Problems, pitfalls etc? ...
    (borland.public.delphi.language.objectpascal)