Index

Subject : LUG: Rename command question

From : "Daniel Underwood" <daniel.underwood@ncsu.[redacted]>

Date : Sat, 20 Mar 2010 05:02:54 -0400


Folks,

Suppose I have a file with multiple spaces in the filename, e.g., "my
homework submission.txt" and I wish to replace each occurrence of a
"space" with a "dash". The command

$ rename 's/ /-/' *

results in changing the filename to "my-homework submission.txt".
Notice that only the first occurrence of a "space" is replaced. This,
of course, is not what I want to do.

So my question is how can I use <rename> to substitute for *all*
occurrences of the matched expression? I'd prefer to avoid using a
script such as the following:

for f in *; do mv "$f" `echo $f | tr ' ' '-'`; done ;

Also, why should the <tr> command replace all occurrences but the
<rename> command only replaces the first occurrence?

TIA!
--
Daniel Underwood
North Carolina State University
Graduate Student - Operations Research
email: daniel.underwood@ncsu.[redacted]
phone: XXX.302.3291
web: http://www4.ncsu.edu/~djunderw/



Replies :