LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 01-18-2010, 08:50 AM   #1
unix1adm
Member
 
Registered: Oct 2008
Posts: 688

Rep: Reputation: 32
mv is not working right.


I have a bunch of files in a dir and want ot move them from
mv *.JPG *.jpg

When I do this command on a unix system it works just fine.

When i do i on Linux I get this..
mv *.JPG *.jpg
mv: target `P1170003.jpg' is not a directory

Thats right its not a directory tis a jpg file.

I also tried the -T option and that did not work too

-T, --no-target-directory
treat DEST as a normal file
 
Old 01-18-2010, 09:00 AM   #2
cola
Senior Member
 
Registered: Sep 2007
Posts: 1,045

Rep: Reputation: 65
Quote:
Originally Posted by unix1adm View Post
I have a bunch of files in a dir and want ot move them from
mv *.JPG *.jpg

When I do this command on a unix system it works just fine.

When i do i on Linux I get this..
mv *.JPG *.jpg
mv: target `P1170003.jpg' is not a directory

Thats right its not a directory tis a jpg file.

I also tried the -T option and that did not work too

-T, --no-target-directory
treat DEST as a normal file
Do you want to move or rename files in same directory?

Last edited by cola; 01-18-2010 at 09:09 AM.
 
Old 01-18-2010, 09:01 AM   #3
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Code:
sasha@reactor: ls
file.JPG
sasha@reactor: mv *.JPG *.jpg
sasha@reactor: ls
*.jpg
sasha@reactor:
Based on the above sample of trying what you're doing, are you sure this is a good way to do what you're doing? I mean the wildcard bit?
 
Old 01-18-2010, 09:05 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I would not expect that to work on any system----In Bash, at least, the "*" expands to whatever Bash can see in the directory. The opportunity for ambiguity and confusion is huge.

try it this way:
Code:
for file in *.JPG; do mv $file $(sed 's/\.JPG//' $file).jpg; done
 
Old 01-18-2010, 09:14 AM   #5
unix1adm
Member
 
Registered: Oct 2008
Posts: 688

Original Poster
Rep: Reputation: 32
Well all the files in that one directory are of the .JPG extension and I want to move them all to a .jpg. For some reason the sw i am using only see .jpg not .JPG files.

So I dont see why the wild card would be bad here. Now I would never use it with rm

I have used the * on AIX many times for just such a thing and its fine. Why would it be a problem?

I also tried using the first 3 characters and it did not work

mv P100*.JPG P100*.jpg

This works on AIX but not in Ubuntu for some reason.

Last edited by unix1adm; 01-18-2010 at 09:16 AM.
 
Old 01-18-2010, 09:27 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
For some reason the sw i am using only see .jpg not .JPG files.
What do you get with "ls | grep JPG"? If all the files are *.JPG", then what do you mean that the SW only sees "*jpg"?

Quote:
So I dont see why the wild card would be bad here.
Do "echo *"---you should get the same output as if you did "ls". Now imagine plugging all that in for the destination of the mv command.

I can't tell you why it at least **appears** to work on AIX, but I CAN tell you that it is not the way to do things in BASH.
 
Old 01-18-2010, 09:42 AM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
If you had a directory with the files

file1.jpg file2.JPG file3.JPG file4.JPG

and you ran

mv *.JPG *.jpg

it would be the same as saying

mv file2.JPG file3.JPG file4.JPG file1.jpg

because the shell expands wildcards independently of the program to a list of filenames in the current directory.
 
Old 01-18-2010, 10:47 AM   #8
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Quote:
Originally Posted by unix1adm View Post
I have used the * on AIX many times for just such a thing and its fine. Why would it be a problem?
...
This works on AIX but not in Ubuntu for some reason.
Doesn't work on AIX either:
Code:
$ touch hello1.jpg hello2.jpg hello3.jpg
$ mv *.jpg *.JPG
Usage: mv [-i | -f]  [--] src target
   or: mv [-i | -f]  [--] src1 ... srcN directory
$ uname -a
AIX glxaix2 1 4 00841039A600
I believe it _does_ work in DOS though. Maybe that's what you're thinking of.

Dave
 
Old 01-18-2010, 01:07 PM   #9
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
There's also the rename command which I believe exists on most Linux distros, in this case one would do:

rename JPG jpg *.JPG
 
1 members found this post helpful.
Old 01-19-2010, 06:29 AM   #10
unix1adm
Member
 
Registered: Oct 2008
Posts: 688

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by btmiller View Post
There's also the rename command which I believe exists on most Linux distros, in this case one would do:

rename JPG jpg *.JPG
When i refer to SW i was talking about photobucket www site wont let me upload fiels of a .JPG extension. Only a .jpg (various other ones work but no caps) My camera puts the file with a JPG extension so I have to move all the pictures to a .jpg extension before uploading


ahhhh thank you that was the command I must have been thinking of. My bad.. rename not mv. I have used mv to move various files/dirs out of the way so they dont get over written. But you are right one at a time not with *.

Sorry brain cramp.

Ok may be not.. I must be doing something fundamentally wrong here

rename test test2
Bareword "test" not allowed while "strict subs" in use at (eval 1) line 1.

What the heck is "strict subs"

So I just tried a bunch of junk files and it does not work either..
(dont mind th e.bff just a test extension) If i do the files one at a time with mv command it works.

touch test.bff test2.bff test3.bff
me@mysys:/tmp$ rename *.bff *.abc
Bareword "test2" not allowed while "strict subs" in use at (eval 1) line 1.
Bareword "bff" not allowed while "strict subs" in use at (eval 1) line 1.


I can do a cp of the file to a new name
I can do a mv one file at a time.

I googled this error and see lots of hits but no real solution. My name doe snot have a space in it like some solution suggested so No clue here.

I tried a .txt extension and a .JPG jpg on empty files and nothing worked.

I am my regular user and i own the files.

Last edited by unix1adm; 01-21-2010 at 02:15 PM.
 
Old 01-19-2010, 06:35 AM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Try "rename --help" or "man rename" or read the previous post that had the answer.

rename JPG jpg *.JPG

Notice the list of files to change as the third argument.
The first argument is the original string. The second is the replacement string. The third ans subsequent arguments are the list of files to rename.

For example:
rename JPG jpg pic1.JPG pic2.JPG pic3.JPG
would rename just the three files you indicated.
 
Old 01-19-2010, 07:47 AM   #12
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Different distributions can have different programs called "rename". The one I have on mine is supplied as part of perl and uses the sed-and-perl-style "s///" syntax. So as suggested above, be sure to check the manpage.

And in fact, when I try to use the above style, I get the same error you do, so you're probably using perl rename also. This means that for you the command would be:

Code:
rename -nv "s/.JPG/.jpg/" *.JPG
I highly suggest using the -n flag to dry-run the renaming first, as well as the -v option for verbose output.
 
Old 01-19-2010, 09:14 AM   #13
unix1adm
Member
 
Registered: Oct 2008
Posts: 688

Original Poster
Rep: Reputation: 32
Thank you. I would have thought rename/mv would be standard commands across releases.

yes I did do a man on the rename command before posting.
 
Old 01-19-2010, 04:00 PM   #14
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Well, mv is part of the gnu coreutils, so it's highly unlikely that any Linux distro will be using anything different. But outside of the basics there can sometimes be variations in which programs the distros offer. It's rare to have multiple programs with the same name though.

Other unixes (solaris, etc) also generally have their own versions of the core utilities. These are often less flexible than the gnu ones, since gnu has extended its versions with a great many options outside of the basic posix standards. This probably won't directly affect you very much, but you might want to keep it in mind when you search the web for scripting advice.
 
Old 01-19-2010, 04:03 PM   #15
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by unix1adm View Post
I would have thought rename/mv would be standard commands across releases.
They are!!
But not between Linux and Unix. Was that the confusion?
 
  


Reply

Tags
rename



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
Ubuntu 8.04: Transparent proxy using squid working but block domain not working bleketux Linux - Networking 10 03-16-2009 06:41 AM
media problem with .avi --- audio only in vlc working rest amarock ,etc. not working fedex Linux - Newbie 1 12-22-2007 08:06 AM
SED - minor changes work - Larger doesn't (working and non working code included) Nimoy Programming 17 09-22-2007 04:34 PM
Fortemedia FM801 card not working under FC5 on Intel 845 but working with windows morningkiran Linux - Hardware 0 11-30-2006 07:57 AM
acpi nearly working IBM thinkpad R40e 2684HVG no Fn key working, throttling OK Emmanuel_uk Linux - Laptop and Netbook 2 05-31-2006 01:41 AM

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

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