Re: Spaces in file names
- From: John Reiser <jreiser@xxxxxxxxxxxx>
- Date: Sun, 30 Dec 2007 20:22:38 -0800
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.]
--
.
- References:
- Spaces in file names
- From: Leslie Rhorer
- Re: Spaces in file names
- From: Paul Pluzhnikov
- Re: Spaces in file names
- From: Leslie Rhorer
- Spaces in file names
- Prev by Date: Re: Spaces in file names
- Next by Date: Re: Spaces in file names
- Previous by thread: Re: Spaces in file names
- Next by thread: Re: Spaces in file names
- Index(es):
Relevant Pages
|