LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-27-2014, 08:02 PM   #1
julianvb
Member
 
Registered: Apr 2009
Posts: 390

Rep: Reputation: 3
Globally Renaming Files with Same Extension in a Directlory


I frequently need to add a prefix to the file names in a directory from the command line globally. An example would be .wav or .mp3 files in a particular directory. This way, I can distinguish similarly named files from other directories. My immediate need is to add a prefix such as '01-' to all the .wav files in a directory where the original files are named trk01.wav, trk02.wav, trk03.wav, etc. and they would be renamed 01-trk01.wav, 01-trk02.wav, 01-trk03.wav, etc.

I have forgotten how to do it using the mv command. I've also tried the rename command without much luck. I've looked into the two commands' manuals but to no avail. As a matter of fact, one recommended 'rename' example does not work in my Ubuntu 12.04 system.

I would appreciate seeing some simple illustrative examples. I am sory that due to poor typing my post was incomplete when it was submitted.

Julianvb

Last edited by julianvb; 04-29-2014 at 12:10 AM.
 
Old 04-28-2014, 01:31 AM   #2
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
Examples :
Change all jpg files of a directory /tmp/user into mp3 files
Quote:
rename 's/\.jpg$/\.mp3/' /tmp/user/*
Removing all blank space of all files of a directory /tmp/user
Quote:
rename "s/ *//g" /tmp/user/*
To convert all uppercase filenames to lowercase:
Quote:
$ rename 'y/A-Z/a-z/' /tmp/user/*
Suppose there are 55 files in the folder /usr/src/zz-folder/thumbnail_square as name1.txt name2.txt and so on and you want to change all into name1.jpg, name2.jpg and so on
Quote:
rename 's/\.txt/\.jpg/g' /usr/src/zz-folder/thumbnail_square/*
Suppose there are files a,b,c,d,e,f in /tmp/user and you want to add prefix .txt in the files
Quote:
rename "s/$/\.txt/g" /tmp/user/*
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] renaming real name (of an .so file) with .bak extension causes problem shamjs Programming 3 09-16-2011 10:01 PM
Renaming files mashcaster Linux - General 3 05-08-2009 03:14 PM
bash: renaming file extension based on actual file type alekone Linux - General 9 12-28-2008 09:12 AM
renaming files TomalakBORG Linux - Newbie 4 12-24-2005 10:14 AM
Renaming files TomalakBORG Linux - Newbie 2 12-05-2005 04:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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