Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

mv: cannot stat with *

Writer Sebastian Wright

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:

Any idea why it's telling me

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

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!

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

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)

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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