0

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?

  • 2
    What is the exact command you used? – Mark Kirby May 30 '16 at 13:08
  • Most likely this will be the answer: Linux is case-sensitive. – Rinzwind May 30 '16 at 13:34
4

Some useful things to know when doing things with files:

  • Linux is case sensitive (so dog, Dog and DOG 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'

0

The command I would use here is (assuming they are in the top level of your home directory):

mv ~/Cat/puppies ~/Dog/puppies 

If the directory puppies contains more directories you will need to add the recursive flag -r which would make the command look like:

mv -r ~/Cat/puppies ~/Dog/puppies 

Note the command is case sensitive.

  • 4
    If the OP is trying to move files in their home directory, sudo could most likely be omitted. – grooveplex May 30 '16 at 13:24
  • 2
    @Danturnip You don't need sudo to move files you own ie ones you created in your home directory, that is why it can be omitted. Just edit the sudos out and people will revert there votes. – Mark Kirby May 30 '16 at 13:31
  • 1
    the use of sudo is not needed nor recommended, please remove from your answer. (plus Sudo isn't even a command but obviously sudo is & shouldn't be used in this case. Users don't need or want root owning files in their $HOME – doug May 30 '16 at 13:31
  • 1
    The OP is most likely the owner of their own home directory. sudo would move the files as root, which is a bad idea, see the explanation of the Principle of least privilege at en.wikipedia.org/wiki/Principle_of_least_privilege. If the OP instead wanted to move, say, /cats/puppies/ to /dog/puppies, sudo would most likely be required. To the OP: only if the command fails because of permission denied, try with sudo. – grooveplex May 30 '16 at 13:32
  • 1
    besides that ... it would be "sudo" not "Sudo". – Rinzwind May 30 '16 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.