Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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: http://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
share|improve this question
add comment

4 Answers

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!

share|improve this answer
add comment

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
share|improve this answer
add comment

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)

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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