DriverHeaven.net

Looking for the skin chooser?
 
 
  • Home

  • Reviews

  • Articles

  • News

  • Tools

  • GamingHeaven

  • Forums

  • Network

 

Go Back   DriverHeaven.net > Forums > Software / Tools > Linux Operating Systems


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

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, 08:42 AM   #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 09:17 AM.
merry is offline   Reply With Quote
Old Nov 27, 2008, 12: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 12:32 PM.
Malus is offline   Reply With Quote
Old Nov 27, 2008, 01:02 PM   #4
Hopeless Dreamer
 
Join Date: Aug 2003
Location: Dreamland, near the pool of infinite graphics cards
Posts: 2,487
Rep Power: 57
ET3D has a brilliant futureET3D has a brilliant futureET3D has a brilliant futureET3D has a brilliant futureET3D has a brilliant futureET3D has a brilliant futureET3D has a brilliant futureET3D has a brilliant futureET3D has a brilliant futureET3D has a brilliant futureET3D has a brilliant future
System Specs

Re: Can anyone help out with this simple command?

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

Bookmarks

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple question. IFartOnYou Hardware Discussion & Support 12 Jun 13, 2008 05:05 PM
Simple plugin for use with 'ma' console command Russ Effects and the DSP 12 Apr 14, 2008 02:53 PM
Do some simple tests for me? Russ Effects and the DSP 37 Apr 13, 2006 05:57 PM
Simple Question! tonygg General Discussion 1 Mar 3, 2005 06:58 PM
Help with a simple PC OC. totally_tonedef Overclocking and Modding 27 Oct 19, 2004 10:00 AM