LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 08-30-2007, 12:54 PM   #1
hpladd
Member
 
Registered: Feb 2003
Distribution: Kubuntu
Posts: 142

Rep: Reputation: 15
mv command


I have a directory called command_expansion_test.

The directory contains the files: test.ogg, test2.ogg, test3.ogg.

Using the mv command, how can I change the filenames to test.mp3, test2.mp3, test3.mp3 ?

Last edited by hpladd; 08-30-2007 at 01:01 PM.
 
Old 08-30-2007, 01:09 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
If you have the rename command, it straightforward as
Code:
rename .ogg .mp3 *.mp3
otherwise you can use sed to substitute the extension as in
Code:
for i in `ls *.mp3`
do
mv $i $(echo $i | sed s/.ogg$/.mp3/)
done
 
Old 08-30-2007, 02:01 PM   #3
hpladd
Member
 
Registered: Feb 2003
Distribution: Kubuntu
Posts: 142

Original Poster
Rep: Reputation: 15
Code:
for i in `ls *.mp3`
do
mv $i $(echo $i | sed s/.ogg$/.mp3/)
done
Thanks colucix:

rename would be the easy way to do it. I never seem to want to do things the easy way however.

This is mostly an academic exercise for me. I was at a LUG last night where the presenter used a string very similar to the one you provided to perform a *.ogg to *.mp3 name change to files in a directory.

I've been banging my head against a wall trying to come up with a single string that can do it, but now I realize that it probably was a script.
 
Old 08-30-2007, 02:11 PM   #4
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
Well
I would say you're on the right track, I usually refer to this document for such tasks.
 
Old 08-31-2007, 05:01 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by hpladd View Post
I've been banging my head against a wall trying to come up with a single string that can do it, but now I realize that it probably was a script.
Not really a script: you can launch a for loop directly in the command line. As you can see from the document suggested by Junior Hacker, usually there are a lot of ways to perform the same task. It is a matter of efficiency or elegance or whatever you are focused on.
 
Old 08-31-2007, 10:07 AM   #6
hpladd
Member
 
Registered: Feb 2003
Distribution: Kubuntu
Posts: 142

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by colucix View Post
Not really a script: you can launch a for loop directly in the command line. As you can see from the document suggested by Junior Hacker, usually there are a lot of ways to perform the same task. It is a matter of efficiency or elegance or whatever you are focused on.
The reason I have a love/hate relationship with Linux: I start out trying to learn how to do some seemingly trivial task, and discover a relatively broad new facet to Linux (and computers). I believe I just stumbled upon "structured Language Constructs," as defined here http://www.freeos.com/guides/lsst/index.html

Thanks for your help!
 
  


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
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 08:19 PM
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 03:23 AM
Why after start of a command the invitation for input next command has not appeared. ukrainet Linux - General 3 06-24-2005 09:16 AM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 08:14 PM
Where is Command line utility for Cups and command tutorial mossy Linux - Software 8 01-16-2004 01:24 AM


All times are GMT -5. The time now is 08:49 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