Trying to use the move (mv) command, but I get "no such file or directory"
I having trouble using the move command. I have created two directories called Cat
and Dog
. Under Cat
I created a file called puppies
.
When I try to move puppies
from Cat
to Dog
I get No such file or directory
. However, when I go back and cd Cat
and ls -a
, it shows puppies
. Then, I go back to my home directory and ls -a
, and Cat
and Dog
are listed.
So what am I doing wrong?
Solution 1:
Some useful things to know when doing things with files:
- Linux is case sensitive (so
dog
,Dog
andDOG
are all different files) - How commands work depends on where you are in the filesystem
- Based on where you are you can use relative or absolute pathnames
So, if you are in the parent directory of Cat
and Dog
you can use relative pathnames, like this:
mv Cat/puppies Dog
An easy mistake to make is to type the pathname starting with /
mv /Cat/puppies /Dog
This will give a no such file or directory
error, because /
is the root directory and there are no Cat
and Dog
directories under /
. Have a look:
ls /
One reason for this confusion is that the system uses a helpful shortcut for the user's home directory, so instead of /home/username/somefile
you can type ~/somefile
as the absolute pathname of somefile
in your user's home directory, so, assuming Cat
and Dog
are at the top of your user's home directory, you can move puppies
from Cat
to Dog
from anywhere in your filesystem with
mv ~/Cat/puppies ~/Dog
A couple of examples using relative pathnames
If you are in the directory Cat
, you can move puppies
like this
mv puppies ../Dog
..
specifies the parent directory of the current working directory
If you are in the directory Dog
you can move puppies like this
mv ../Cat/puppies .
.
specifies the current working directory
To find out where you are, you can usually look at your prompt, but just to be sure, you can always check with pwd
which stands for 'print working directory'