renaming a file....

Tom Browder tom.browder at gmail.com
Mon Jan 1 13:52:05 UTC 2007


On 12/28/06, Cameron Simpson <cs at zip.com.au> wrote:
> On 28Dec2006 11:32, bruce <bedouglas at earthlink.net> wrote:
...
> | i can use the find cmd, and generate the files i want to rename. however, my
> | attempts at using the find . -name "foo" | xargs rename... doesn't seem to

You can try

  find . -name "foo" -exec mv -i {} newfoo \;

That will rename all the files named foo in the subdirectory structure
(after getting you to confirm the rename), but that won't show the
full path.  In addition, if you have files with the same name in
different subdirectories you may not want to rename all of them.
Another consideration is if you are looking at files with similar
names.

What I like to do before any use of find to change a file is to know
what find "finds."

In the example above I will execute

  find . -name foo

and see what files are found.  The list returned will include the
relative path, so I will see something like:

  ./subdir1/foo
  ./foo

Then I can do a couple of things.  I can gang rename:

  find . -name foo -exec mv {} foo2 \;

or, one at a time

  mv ./foo ./foo2
  mv ./subdir1/foo ./subdir/foo3

-Tom

Tom Browder
Niceville, Florida
USA




More information about the fedora-list mailing list