HardwareHeaven.com
Looking for the skin chooser?
 
 
  • Home

  • Reviews

  • Articles

  • News

  • Tools

  • GamingHeaven

  • Forums

  • Network

 

Go Back   HardwareHeaven.com > Forums > Software / Tools > Linux Operating Systems


Linux Operating Systems Talk about all Linux distributions and software here!

Reply
 
Thread Tools
Old Nov 12, 2008, 12:39 AM   #1
DriverHeaven Addict
 
Calinerti's Avatar
 
Join Date: Sep 2002
Location: Elysium
Posts: 330
Rep Power: 0
Calinerti is on a distinguished road

Donator
Can anyone help out with this simple command?

Hi,

Im trying to rename multiple files, using CentOS (fedora). I'm running the following command:

find -iname .new-account | mv .new-account .new-user

to change all files named .new-account to .new-user

I keep getting "cannot stat .new-account: no such file or directory".

But using just "find -iname .new-account" lists all the files I want changed. Im stuck! I also tried find -iname .new-account | rename 's/\.new-account/\.new-user/' but that doesnt work either (but it works in ubuntu), no error message given.

Id appreciate any and all input you have! (and yeah, I AM a n00b at linux!)
Calinerti is offline   Reply With Quote


Old Nov 17, 2008, 02:42 PM   #2
gargouille
 
merry's Avatar
 
Join Date: Jun 2002
Location: sector ZZ9 Plural Z Alpha
Posts: 962
Rep Power: 0
merry is on a distinguished road

Re: Can anyone help out with this simple command?

Quote:
find -iname .new-account | mv .new-account .new-user
I'm not sure you can pipe anything to mv; not like this, anyway. This command will find (case-insensitive) all files named .new-account in the current directory and below, then proceed to rename the one in the current dir to .new-user (no output from find reaches mv). 'cannot stat [...]' means there is no .new-account file in the current directory.

I don't use ubuntu; the rename command appears to be ubuntu-specific.

I tried the line below on a Mac/bash, but should work mostly anywhere.

This will find all files named .new-account starting from the current dir downwards; get the path using sed to remove the filename from the path (thus creating a list of paths that are stored successively in $i); cd there and rename the file; cd back and continue to the next file:

Code:
for i in `find . -name .new-account | sed -e "s/\/\.new-account$//"`; do cd $i; mv .new-account .new-user; cd -; done
Note that the dot (and preceding slash) must be escaped in the sed regexp, i.e.
Code:
\/\.new-account$
The dollar sign is necessary to force sed to match the filename in a path like
Code:
./path/to/.new-accounts/.new-account
I'm not sure why you want to use -iname? If your files do not have identical names, (some are called .new-account, but some are .New-Account') the above will not work, you need to repeat the line above with each filename version in turn.

[edit]

Here's a better way:

http://snipplr.com/view/2736/rename-...r-expressions/

For your needs, the one-liner in the post above should be modified to:
Code:
for i in `find . -name .new-account`; do j=`echo $i | sed 's/account$/user/'`; mv "$i" "$j"; done
This is more elegant, as it doesn't cd, but renames using the full path, i.e.
Code:
mv /path/to/old /path/to/new
The syntax for sed might differ by unix/shell, so check it first.

Also, 'rename' appears to be a perl script available on Debian:

http://tips.webdesign10.com/files/rename.pl.txt
__________________
There is a war between the ones who say there is a war
and the ones who say there isn't.
~~Leonard Cohen

Last edited by merry; Nov 17, 2008 at 03:17 PM.
merry is offline   Reply With Quote
Old Nov 27, 2008, 06:23 PM   #3
BSD SMASH!
 
Malus's Avatar
 
Join Date: May 2002
Location: A rabbit hole. . .
Posts: 1,170
Rep Power: 0
Malus is on a distinguished road

Re: Can anyone help out with this simple command?

Seems like you are making it too complicated to me. Here is a snippet that works for me on FreeBSD:

Code:
find . -iname .new-account | sed 's/\.new-account$//' | xargs -n1 -I % mv %.new-account %.new-user
It could probably be made even simpler, but I think it is a good start.
__________________
quad (FreeBSD/amd64 8-CURRENT): Intel Q6600 - Asus P5E-VM HDMI - 2x2 GB Kingston PC6400 DDR2 Ram - Seagate 320GB 7200RPM HD - 2xSeagate 1TB 7200RPM HD in RAID 1 via ZFS - Lite-On 20x DVD Multi Recorder - Coolermaster Centurion 5

router (FreeBSD/amd64 8-CURRENT):
Intel E4500 - Intel D945GCNL - 2 GB PC6400 Mushkin Ram - Lite-On 48x24x48x16 - Seagate 320GB 7200RPM HD - Silverstone SST-SG02-F

wanderer (FreeBSD/i386 7-CURRENT): Lenovo Thinkpad T61p

mini (OS X 10.5): Intel Core 2 Duo @ 1.8Ghz, 4 GB Mushkin PC5400 Ram -
Headroom MicroDAC

Portable sound: Rockboxed iPod Video -> Westone UM2's
Not-So-Portable Sound: Headroon MicroDAC -> Singlepower PPX3-SLAM -> Grado RS-1's or Beyerdynamic DT-880's
Very-Not-Portable-Sound: Squeezebox v3 -> Denon AVR-1507 -> B&W 683's & Sunfire HRS-10

Last edited by Malus; Nov 27, 2008 at 06:32 PM.
Malus is offline   Reply With Quote
Old Nov 27, 2008, 07:02 PM   #4
Hopeless Dreamer
 
Join Date: Aug 2003
Location: Dreamland, near the pool of infinite graphics cards
Posts: 3,055
Rep Power: 103
ET3D has a divinity and aura the likes we have never seenET3D has a divinity and aura the likes we have never seenET3D has a divinity and aura the likes we have never seenET3D has a divinity and aura the likes we have never seenET3D has a divinity and aura the likes we have never seenET3D has a divinity and aura the likes we have never seenET3D has a divinity and aura the likes we have never seenET3D has a divinity and aura the likes we have never seenET3D has a divinity and aura the likes we have never seenET3D has a divinity and aura the likes we have never seenET3D has a divinity and aura the likes we have never seen
System Specs

Re: Can anyone help out with this simple command?

It was all much simpler on the Amiga...
ET3D is offline   Reply With Quote
Reply

Bookmarks

Thread Tools