LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-29-2011, 02:42 PM   #1
lipun4u
Member
 
Registered: Sep 2008
Location: Mumbai, india
Distribution: ubuntu and hp-unix
Posts: 118

Rep: Reputation: 15
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...
 
Old 04-29-2011, 03:43 PM   #2
spankbot
Member
 
Registered: Aug 2007
Posts: 131

Rep: Reputation: 16
Quote:
Originally Posted by lipun4u View Post
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
 
Old 04-29-2011, 03:44 PM   #3
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
Something like
Code:
rename ".pc" ".txt" *.pc
should do

Hope this helps,
 
Old 04-29-2011, 03:52 PM   #4
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,116

Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
Quote:
Originally Posted by lipun4u View Post
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?
 
Old 05-01-2011, 06:20 AM   #5
lipun4u
Member
 
Registered: Sep 2008
Location: Mumbai, india
Distribution: ubuntu and hp-unix
Posts: 118

Original Poster
Rep: Reputation: 15
Thank you every body
 
Old 05-01-2011, 09:35 AM   #6
Fred Caro
Member
 
Registered: May 2007
Posts: 999

Rep: Reputation: 166Reputation: 166
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.
 
Old 05-02-2011, 08:51 AM   #7
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
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
 
Old 05-02-2011, 03:36 PM   #8
lipun4u
Member
 
Registered: Sep 2008
Location: Mumbai, india
Distribution: ubuntu and hp-unix
Posts: 118

Original Poster
Rep: Reputation: 15
no....it's not working.

HP Unix doesn't recognize 'rename' as a command..
 
Old 05-02-2011, 07:26 PM   #9
NirvanaII
Member
 
Registered: Jun 2005
Posts: 139

Rep: Reputation: 18
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.

Last edited by NirvanaII; 05-02-2011 at 08:04 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to rename a username? ceci2 Linux - General 4 11-09-2009 03:43 PM
rename errorsunknownp Linux - Newbie 2 12-28-2008 06:06 AM
rename partition varun_saa Fedora 2 05-28-2006 09:46 AM
Filename rename jarod_123 Programming 4 03-21-2006 03:40 PM
Rename my pc ? Tanc Linux - Newbie 6 09-13-2003 09:28 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration