i can rename a file in the current dir
is there a way to be in a parent dir, and rename a file in a child dir?
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 work, as the rename is coming back saying that the file doesn't exist..
it seems that the rename is operating on files in the current dir, as opposed to the files from the 'find'....
thanks
On 12/28/06, bruce bedouglas@earthlink.net wrote:
i can rename a file in the current dir
is there a way to be in a parent dir, and rename a file in a child dir?
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 work, as the rename is coming back saying that the file doesn't exist..
it seems that the rename is operating on files in the current dir, as opposed to the files from the 'find'....
thanks
-- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
I haven't used xarg. I use -exec with the find command.
find . -name "foo" -exec rename {} ... ;
Not sure if that will help you or not.
Not to detract from your question, but once answered I'd be interested in some input on the difference in using xarg vs -exec.
Thanks,
Jacques B.
On 28Dec2006 11:32, bruce bedouglas@earthlink.net wrote: | i can rename a file in the current dir | | is there a way to be in a parent dir, and rename a file in a child dir? | | 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 | work, as the rename is coming back saying that the file doesn't exist.. | | it seems that the rename is operating on files in the current dir, as | opposed to the files from the 'find'....
Generate "mv" commands from the output of find, and pipe to "sh". Without knowing exactly what renaming you're doing it's hard to be much more help.
Remi Collet wrote:
Jacques B. a écrit :
Not to detract from your question, but once answered I'd be interested in some input on the difference in using xarg vs -exec.
Using xarg seems subject to command line size limit.
Using xargs will help you avoid the problem of hitting the command line size limit.
find -exec run the command once for each file.
Which is very inefficient when you're doing something that could be done on all the files at once. Generally I think using xargs is more appropriate.
bruce wrote:
i can rename a file in the current dir
is there a way to be in a parent dir, and rename a file in a child dir?
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 work, as the rename is coming back saying that the file doesn't exist..
it seems that the rename is operating on files in the current dir, as opposed to the files from the 'find'....
Can you post the command and the output?
This works here:
$ mkdir dir; touch dir/abcCat.{txt,py} $ ls dir/ abcCat.py abcCat.txt $ find dir/ -name 'abcCat.*' | xargs rename . _dog. $ ls dir/ abcCat_dog.py abcCat_dog.txt
On 12/28/06, Cameron Simpson cs@zip.com.au wrote:
On 28Dec2006 11:32, bruce bedouglas@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