Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ScurvyMro

macrumors newbie
Original poster
Feb 13, 2015
3
0
I'm trying to understand how the move command works. I've googled it of course and found some information, but I'm still confused.

I'm logged into the Mac as myself (call me Dad), and I want to use terminal to move some files around in the Pictures folder in my wife's profile (call her Mom). I have permission to the Pictures folder. In terminal, I issued the command to change to the folder. when I execute 'pwd', it shows the current folder as /users/mom/pictures. Now, assume I want to move all JPG files from the root of the pictures folder to a folder called photos that is one level below pictures. I've tried 'mv /users/mom/pictures/*.jpg /users/mom/pictures/photos' but I get 'No such file or directory'. I tried several variations of that command with the same results. So I decided to try moving just one file. That file was called 'weird.png'. so I issue the command mv weird.png ~/photos. That command executed without error, but now the file is no where to be found. It is not in the pictures folder, and it's not in my pictures folder, and it is not in the photos folder. So, clearly I am not understanding how this works.

Can anyone help?
 

chown33

Moderator
Staff member
Aug 9, 2009
10,998
8,887
A sea of green
Please use CODE tags around commands.

This command:
Code:
mv weird.png ~/photos
moves the weird.png file to your home folder. It also renames it to "photos", with no extension. That is, its name is exactly "photos", not "photos.png".

It does this because ~/ stands for your login's home folder. You said you logged in as 'dad', so ~/ refers to dad's home folder, not mom's.

If you had a folder in your home folder named "photos", then weird.png will be placed inside that folder. Since you didn't say you had that, I'm assuming you don't. That means the 'mv' command sees the second parameter as non-existent, and it will move the first parameter (weird.png) to the given location (~/) and rename it (to "photos").


Use this command and you should see the file listed:
Code:
ls -l ~
Then use this command to determine what the file is:
Code:
file ~/photos
In both cases, you can select, then copy and paste Terminal's output into a post. Again, use CODE tags around what you paste.


Going back to your original task, you wrote:
Now, assume I want to move all JPG files from the root of the pictures folder to a folder called photos that is one level below pictures. I've tried 'mv /users/mom/pictures/*.jpg /users/mom/pictures/photos' but I get 'No such file or directory'.​
Question 1 for you to answer:
Does the folder "photos" already exist in "/users/mom/Pictures" or not?

If the folder doesn't exist, you have to create it first. You can do that in Finder, or in Terminal.

If you want the folder to be owned by 'mom', then you should login as 'mom' to create the folder. Otherwise it will be owned by 'dad', because that's who you're logged in as.

You could change the owner after creating the folder (there's a command for that), so decide how you want to proceed and then tell us.

I assume you can login as mom without further instructions. If you want to create the folder using Terminal, then ask again and we can tell you what commands to use.


After the folder "/users/mom/Pictures/photos" exists, then this command should work:
Code:
mv /users/mom/pictures/*.jpg /users/mom/pictures/photos
If it doesn't, then run this command and post the complete output in CODE tags:
Code:
echo /users/mom/pictures/*.jpg
If the 'echo' command says something unexpected, copy and paste the complete output. Don't paraphrase it, retype it, or edit it. Error messages are important details.
 

ScurvyMro

macrumors newbie
Original poster
Feb 13, 2015
3
0
Thanks for your help on this. I tried the command again with the same results.

This command:

Code:
mv /users/mom/pictures/*.jpg /users/mom/pictures/photos

Results in the following error:

Code:
rename /users/mom/pictures/*.jpg to /users/mom/pictures/photos/*.jpg: No such file or directory

I ran the echo command:

Code:
echo /users/mom/pictures/*.jpg

which produced this output:

Code:
/users/mom/pictures/*.jpg

For the mv command, I ran it both under my profile and my wife's with the same result. So I thought maybe I had created the photos folder under my own profile, resulting in some permissions issue. But in fact, the permissions for my wife are set to read&write. They were set to Read Only for Staff and Everyone. I changed that. But then I looked at the permissions of some of the files in my wife's "pictures" folder. Most of them are Read & Write for my wife but Read Only for everyone else. So clearly I just need to be doing these commands from my wife's profile.
 

ScurvyMro

macrumors newbie
Original poster
Feb 13, 2015
3
0
After fiddling with it for a while, I finally decided to forget about the *.jpg mask, and just move all of the files, which worked, then sort the files in finder by type and delete what I needed to. I don't know why it didn't work the other way, but it's moot.

Thanks for your help.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,998
8,887
A sea of green
After fiddling with it for a while, I finally decided to forget about the *.jpg mask, and just move all of the files, which worked, then sort the files in finder by type and delete what I needed to. I don't know why it didn't work the other way, but it's moot.

Thanks for your help.

FWIW, it probably didn't work because wildcard (i.e. the "*") expansion needs exact spelling of pathnames. Although the filesystem is case-insensitive, wildcard expansion is case-sensitive.

The actual pathname of the enclosing directory is something like this:
Code:
/Users/mom/Pictures/
so that's what you have to type.


EDIT
The pathname components aren't case-sensitive, but the wildcard components are. See post #7 below.
 
Last edited:

mfram

Contributor
Jan 23, 2010
1,356
405
San Diego, CA USA
I don't know why the O.P.'s commands didn't work. Maybe he didn't get the path quite right. But it turns out that wildcard processing does not seem to be case-sensitive in my case:

Code:
bob-mbp-wl:~$ pwd
/Users/bob
bob-mbp-wl:~$ ls -1 /users/bob/*.txt
/users/bob/data.txt
/users/bob/test.txt
/users/bob/time-machine-pref.txt
 

chown33

Moderator
Staff member
Aug 9, 2009
10,998
8,887
A sea of green
I don't know why the O.P.'s commands didn't work. Maybe he didn't get the path quite right. But it turns out that wildcard processing does not seem to be case-sensitive in my case:

Code:
bob-mbp-wl:~$ pwd
/Users/bob
bob-mbp-wl:~$ ls -1 /users/bob/*.txt
/users/bob/data.txt
/users/bob/test.txt
/users/bob/time-machine-pref.txt

You are correct. I edited my earlier post.

The part that's case-sensitive is the wildcard part. For example, I expect this won't work on your machine:
Code:
ls -1 /users/bob/*.Txt
So if the OP's files have the extension ".JPG", then the wildcard "*.jpg" won't match.
 
Last edited:

w0lf

macrumors 65816
Feb 16, 2013
1,268
109
USA
You are correct. I edited my earlier post.

The part that's case-sensitive is the wildcard part. For example, I expect this won't work on your machine:
Code:
ls -1 /users/bob/*.Txt
So if the OP's files have the extension ".JPG", then the wildcard "*.jpg" won't match.

I believe this is the correct command:

Code:
mkdir -p /users/mom/pictures/photos/
mv /users/mom/pictures/*.[Jj][Pp][Gg] /users/mom/pictures/photos
 

w0lf

macrumors 65816
Feb 16, 2013
1,268
109
USA
You shouldn't get into the habit of using multiple square brackets that can match many more possibilities when you're just trying to match two. For the example, it wouldn't cause problems, but applying it imprecisely in the future could lead to undesired consequences (possibly even catastrophic). To match just two possibilities of case it would be preferable to list them explicitly:

Code:
mv /users/mom/pictures/*.{jpg,JPG} /users/mom/pictures/photos

That form indicates you are looking for ONLY jpg and JPG extensions.

I also highly suggest the OP use an alias for "mv" as default:

Code:
alias mv='mv -i'
alias mv 'mv -i'

First example for bash, second for tcsh.

Except any variation of JPG is valid. For example .JpG or .jPg or .JPg are all the same extension.

Also no point in setting up an alias if you're only gonna use the command once. Unless you add it to the .profile so it's always available to you.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.