LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-03-2006, 01:18 AM   #1
skilletlicker
LQ Newbie
 
Registered: Feb 2006
Posts: 1

Rep: Reputation: 0
mv command question


If I have a file called "long_file_name" and would like to rename it "01_long_file_name", how could I do that without retyping the "long_file_name" part? I know about using copy and paste, but I'm looking for the scriptable way to do it.

thanks.
 
Old 02-03-2006, 01:35 AM   #2
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
Just save it to a variable and use the mv command this way - "mv $filename 01_$filename"

-twantrd
 
Old 02-03-2006, 01:22 PM   #3
WilliamsJD
LQ Newbie
 
Registered: Nov 2003
Distribution: Fedora Core 4
Posts: 11

Rep: Reputation: 0
If you need to do a bunch of files you can do it this way:

for f in starname
do
mv $f 01_$f
done

where starname is a starname giving the list of files to rename.

Example:

Suppose you want to rename all the files ending in ".in" and ".list" to have a prefix of "froggy.":

for f in *.in *.list
do
mv $f froggy.$f
done

Hope that helps,
WilliamsJD
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command question satimis Fedora 2 04-15-2005 06:52 PM
Command question satimis Linux - Newbie 2 11-24-2004 08:59 AM
Command Question Siki Linux - General 3 07-29-2003 03:34 PM
cp command question . jesse_mair Linux - Newbie 3 07-09-2003 12:55 PM
ls -al command question Stingreen Linux - Networking 5 02-14-2002 11:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:51 PM.

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
Open Source Consulting | Domain Registration