LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   rename all (https://www.linuxquestions.org/questions/linux-newbie-8/rename-all-877875/)

lipun4u 04-29-2011 01:42 PM

rename all
 
I have 3 files in a directory
a.pc
b.pc
c.pc

I need to rename all these in a single command to
a.txt
b.txt
c.txt

Please suggest me...

spankbot 04-29-2011 02:43 PM

Quote:

Originally Posted by lipun4u (Post 4341025)
I have 3 files in a directory
a.pc
b.pc
c.pc

I need to rename all these in a single command to
a.txt
b.txt
c.txt

Please suggest me...

Here is an easy way to to this using the Bash shell...

http://www.debian-administration.org/articles/150

Snark1994 04-29-2011 02:44 PM

Something like
Code:

rename ".pc" ".txt" *.pc
should do :)

Hope this helps,

szboardstretcher 04-29-2011 02:52 PM

Quote:

Originally Posted by lipun4u (Post 4341025)
I have 3 files in a directory
a.pc
b.pc
c.pc

I need to rename all these in a single command to
a.txt
b.txt
c.txt

Please suggest me...

Why does it have to be a single command?

lipun4u 05-01-2011 05:20 AM

Thank you every body

Fred Caro 05-01-2011 08:35 AM

rename
 
Apologies first but am I right (snark 1994) that you are in the relevant directory and the wildcard (*) only affects that directory? Are the quotes (double or single) strictly necessary as you are in that directory?

Fred.

Snark1994 05-02-2011 07:51 AM

I believe you're completely correct :) I was assuming you were in the directory, and yes the quotes aren't really necessary - it's just a matter of habit...

And lipun4u, if you think the thread has been solved, please click 'Mark thread as SOLVED' at the top of the page. Thanks

lipun4u 05-02-2011 02:36 PM

no....it's not working.

HP Unix doesn't recognize 'rename' as a command..

NirvanaII 05-02-2011 06:26 PM

Don't know about out HP Unix, but you could try this:

Code:

ls *.pc | xargs -I{} basename $1{} .pc | xargs -I{} mv -v -T $1{}.pc $2{}.txt
Or this:

Code:

while read line; do mv -v -T "$line" "${line%.*}.txt" ; done < <(ls *.pc)
Neither an elegant solution, but both work for me.


All times are GMT -5. The time now is 07:07 AM.