The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Moving multiple files and renaming them on the fly daemongk Shell Programming and Scripting 1 06-08-2007 01:36 PM
moving and renaming multiple files rocinante Shell Programming and Scripting 1 06-07-2007 08:20 PM
Renaming multiple files rmayur UNIX for Dummies Questions & Answers 6 02-26-2004 04:40 AM
Renaming multiple files jxh461 Shell Programming and Scripting 4 04-01-2003 06:25 PM
renaming multiple files piltrafa UNIX for Dummies Questions & Answers 6 11-10-2001 12:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-27-2008
jayell jayell is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 3
Renaming multiple files

Hi,

I have several hundred files I need to rename, and I'm would rather not hit F2 for each file individually to rename them.

Example of file:
large1961.jpg
What I need the file to be renamed as:
1961.jpg

I don't know what type of command I can execute within a shell script that would remove a specific unwanted part of the file name ("large") and leave the rest intact.

I am an obvious novice in shell scripting and would appreciate any help.
Thanks in advance.
  #2 (permalink)  
Old 02-27-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
many ways...one is:

Code:
#  echo large1981.jpg | sed 's/large//'
1981.jpg
  #3 (permalink)  
Old 02-27-2008
jayell jayell is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 3
Thanks.

So in order to actually rename the file, how could I take the output of that command and make it the final file name?
  #4 (permalink)  
Old 02-27-2008
HPAVC's Avatar
HPAVC HPAVC is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 106
Code:
$ rename
Usage: rename [-v] [-n] [-f] perlexpr [filenames]
... if you have rename I would go that route ...

Code:
rename 's/^large(.*)/$1/' large*.jpg
  #5 (permalink)  
Old 02-27-2008
jayell jayell is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 3
Thanks a lot. That did what I needed it to, and saved a lot of time on my part.

Could you explain the options you used in the command? I read the man page, but I'm not exactly sure what each parameter actually means.
  #6 (permalink)  
Old 02-27-2008
bushey1's Avatar
bushey1 bushey1 is offline
Registered User
  
 

Join Date: Feb 2008
Location: Florida
Posts: 2
oldtimer..... hope it helps..

if all of the files start with large or even a similar structure try this;

^large1967.*^1967.*
  #7 (permalink)  
Old 01-12-2009
oldtrash oldtrash is offline
Registered User
  
 

Join Date: Jul 2003
Location: india
Posts: 20
Folks, It all worked fine until i hit a filename with spaces in between.. how do i overcome this?
ex..
i tried on files "a.txt", "b.txt", "c d.txt", i got..
mv: cannot stat `c': No such file or directory
mv: cannot stat `d.txt': No such file or directory

Thanks,
OT
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0