LinuxQuestions.org
Visit Jeremy's Blog.
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 09-06-2008, 10:57 PM   #1
leupi
Member
 
Registered: Mar 2004
Location: Annapolis, Maryland, USA
Distribution: Ubuntu 11.04, Mint 11.11, Xubuntu 11.11
Posts: 458

Rep: Reputation: 30
Renaming files


I have a large number of files in a directory with a .JPG extension and I would like to rename them as *.jpg (lowercase). I tried using:
Code:
mv *.JPG *.jpg
But I just got the error:
Code:
mv: target `*.jpg' is not a directory
My understanding was that I needed to use the command as
Code:
mv oldFileName newFileName
According to the manpage:
Quote:
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
I am obviously overlooking something as I have DEST being confused with DIRECTORY. What am I missing?

Thanks,
Todd
 
Old 09-06-2008, 11:37 PM   #2
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Because *.JPG expands to multiple files. You and copy 1 file to another, or multiple to a directory. Put it in a loop.
 
Old 09-06-2008, 11:44 PM   #3
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
This link may help you

http://linux.dsplabs.com.au/mmv-copy...d-patterns-p5/
 
Old 09-06-2008, 11:55 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 680Reputation: 680Reputation: 680Reputation: 680Reputation: 680Reputation: 680
The Linux utils package has a multiple rename command.
example:
rename JPG jpg *.jpg

The first argument is the from pattern. The second is the to pattern. The third is a wild card that selects the files you want to rename.

Here is a very common way of doing it:
Code:
for file in *.JPG; do
  mv "${file}" "${file%JPG}jpg"
done
Look in the bash info manual for variable expansion. To change a prefix on a group of files, you could do something like:
Code:
for file in pics-*.jpg; do
  mv "$pics" "photos-${pics#*-}"
done
To change a pattern in the middle you could do something like this:
Code:
for file in *\ *; do
  mv "$file" "${file// /_}"
done
This replaces spaces in names with underscores. You may find yourself doing that
often for mp3 files.

If you have thousands of files, file globbing may fail because the shell runs out of memory. In that case, use the "find" command to generate a list of files and the xargs command to take a list of files in STDIN and use them as the arguments for a command. The xargs command lets you limit the number of files that are processed at once.

Code:
find ~/Documents/pictures/ -type f -print0 | xargs -0 md5sum >md5sumlist
The 100 or so most common console programs in /bin/ and /usr/bin/ are supplies by the coreutils package. I downloaded the source and ran
"./configure && make pdf" to generate the documentation in book form from the docbook info files source. Print it out and you have the documentation for most of the programs you would use in the console. Having a nicely formatted hard copy may make it easier to learn and remember.

Last edited by jschiwal; 09-07-2008 at 12:03 AM.
 
Old 09-07-2008, 12:07 AM   #5
jpsatlinuxquestions
LQ Newbie
 
Registered: Dec 2007
Posts: 18

Rep: Reputation: 0
Quote:
Originally Posted by leupi View Post
I have a large number of files in a directory with a .JPG extension and I would like to rename them as *.jpg (lowercase). I tried using:
Code:
mv *.JPG *.jpg
But I just got the error:
Code:
mv: target `*.jpg' is not a directory
My understanding was that I needed to use the command as
Code:
mv oldFileName newFileName
Code:
rename JPG jpg *JPG
Code:
man rename
 
Old 09-16-2008, 03:22 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
you can use the script here
eg usage
Code:
# ./script.sh -p "JPG" -d "*.JPG" # display all files to be renamed
# ./script.sh -p "JPG" "*.JPG" # remove -d to actual rename
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
help renaming files please balistic Linux - Newbie 2 07-29-2007 03:35 PM
renaming files starwarsfan982 Linux - Software 7 10-30-2006 02:06 PM
renaming files TomalakBORG Linux - Newbie 4 12-24-2005 10:14 AM
Renaming files TomalakBORG Linux - Newbie 2 12-05-2005 04:13 PM
Renaming files in one go saurya_s Linux - Software 1 01-12-2004 01:16 PM

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

All times are GMT -5. The time now is 07:56 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
Open Source Consulting | Domain Registration