I've tried this before. I swear I was able to issue this kind of command before:

mv /home/user/temp1/* /home/user/temp2

Basically, I got this command from here: https://superuser.com/questions/273254/move-files-and-folders-recursively-in-linux

Any idea why it's telling me

mv: cannot stat `/home/user/temp1/*': No such file or directory

I can think of 2 possible reasons why this can happen:

  1. The source directory may not exist (OR)
  2. The source directory might be empty

Ignore if neither!

| improve this answer | |

You need to use $USER for user to expand to your username. /home/user is only valid if you have a user named user. This will work if temp1 and temp2 exists in your home directory

mv /home/$USER/temp1/* /home/$USER/temp2
| improve this answer | |

I'll try to help out and clear up the confusion a little:

  • If you want to move a folder and its contents to another one, you enter:

    mv ~/Scripts ~/Podcasts

  • If you want to move a folder's contents but not the folder itself to another folder, you must enter, for example, mv ~/Scripts/* ~/Podcasts. You can enter echo ~/Scripts/* to check the folder's content

  • (If you also need to know about globstar, which will allow you to recurse through all directory levels, see this article and this one. It can be enabled with shopt -s globstar, but that will need to be put in .bashrc to work permanently.)

(The tilde ~ in ~/Scripts is expanded to /home/mike/ or your user name automatically by the shell)

| improve this answer | |

If you're using bash and the source directory is empty, you can modify the shell's default glob expansion behavior with:

shopt -s nullglob

to enable the nullglob and cause any succeeding commands like mv to behave properly when the source directory is empty. Beware that this can cause other commands such as ls to behave unexpectedly.

You can disable the nullglob again with:

shopt -u nullglob

For more information, look here and here.

| improve this answer | |

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.