LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices

Reply
 
LinkBack Search this Thread
Old 02-08-2012, 08:45 AM   #1
pavi_kanetkar
Member
 
Registered: Nov 2011
Location: Bangalore
Posts: 48

Rep: Reputation: Disabled
Rename mutiple image files through terminal


I have more than 5000 .jpg files in folder. The names are with backslash.
uploadedfile_129730019157343750\uploadedfile_12973 0019157343750-001.jpg
uploadedfile_129730019157343750\uploadedfile_12973 0019157343750-002.jpg
uploadedfile_129730019157343750\uploadedfile_12973 0019157343750-003.jpg
uploadedfile_129730019157343750\uploadedfile_12973 0019157343750-004.jpg
uploadedfile_129730019157343750\uploadedfile_12973 0019157343750-005.jpg
uploadedfile_129730019157343750\uploadedfile_12973 0019157343750-006.jpg
.... & so on....

I want to rename all files simultaneously. The name should be like
001.jpg
002.jpg
003.jpg

I have used rename command
$ rename "uploadedfile_129730019157343750\uploadedfile_1297 30019157343750-" "" *
but I am facing following error.
Bareword "uploadedfile" not allowed while "strict subs" in use at (eval 1) line 1
I have tried all combinations of rename command but result is same error. Ex-
$ rename "uploadedfile" "" *
I have tried for loop too but no luck.
I do not want to use any GUI application like krename or what ever.
I want to do this from terminal. Please help me
 
Old 02-08-2012, 09:17 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: OpenSUSE 12.1 CentOS 6.2
Posts: 8,994

Rep: Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347
Looking at the error message, it seems you have the perl version of rename (as on Debian-like systems). In this case you have to use a substitution command in place of the FROM and TO arguments:
Code:
rename 's/uploadedfile_129730019157343750\\uploadedfile_12973 0019157343750-//' *.jpg
Notice the escaped backslash inside the regular expression.
 
Old 02-08-2012, 09:29 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 7,514
Blog Entries: 1

Rep: Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139
Hi,

The rename command is probably faster, but here's another way (assuming bash):
Code:
for THIS in uploadedfile*; do mv "${THIS}" "${THIS##*-}"; done
Hope this helps.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change mutiple xml files Exise Programming 1 04-21-2010 11:38 AM
GZIP mutiple files at any one time Azzath General 2 10-18-2007 05:20 AM
copy a file to mutiple files Radical-Rick Programming 6 07-11-2006 03:47 PM
Inserting Text into Mutiple HTML Files patisawsome Linux - Software 2 12-28-2005 01:49 AM


All times are GMT -5. The time now is 05:32 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration