2

I have installed wordpress onto my CentOS server.

Now inside my /var/ww/html folder, I have a wordpress folder. I want to move all the files inside the 'wordpress' folder up into the parent dir, which is /var/www/html.

Now I have read this post - How to move all files from current directory to upper directory?

and I have tried the commands suggested there, and all that command line is saying is:

[root@servername wordpress]# mv * .[^.]* ..
mv: cannot stat `*': No such file or directory

How do I move all the files up one dir?

3 Answers 3

5

If you have bash 4+ (check with bash --version), you can simply use the dotglob shell option to ensure that globs include files starting with . by default.

shopt -s dotglob ## activate dotglob
mv ./* ../
shopt -u dotglob ## deactivate dotglob

Aside from reducing the amount of thinking you need to give to this task, it also has the advantage of being smart enough to not match . and .. without you having to mess around. I prefer to preface my globs with ./ to prevent any filenames beginning with a - from being treated as options.

However, your error indicates to me that you're trying to work on an empty directory, or at least one that only contains dotfiles. By default, if a glob doesn't match any filenames, bash sends it literally to the command -- and since there is no file named * in the directory, mv is sending that error.

2
  • cool...I got it sorted thank you. For some reason it actually moved the files, amongst all the errors I got. But thank you for the tip Commented Jul 6, 2013 at 12:58
  • 1
    You may also find this page useful for future reference (that whole website is a very good reference for working with bash).
    – evilsoup
    Commented Jul 6, 2013 at 13:04
2

The message indicates that there is no files matching '*'. Make sure that there exists files or folders in the folder you're moving from. If only files or folders starting with . exists you can run the command mv .[^.]* .. to move them one directory up. Verify that all files are moved by running ls -la and verify that the list only contains this (.) and above (..) directories.

0
2

As others have said, you are probably running your command on an empty directory. Another way of doing this (that will simply fail silently on an empty directory) is to use find's -exec action:

find . -exec mv '{}' ../ \;

This will give you an error:

mv: cannot move `./' to `../.': Device or resource busy

This is because I am not restricting find by file type so it will also attempt to move the current directory (.) and fail. You can safely ignore this error, or you can specify you want all types of files and folders:

find . \( -type f -o -type d \)   -exec echo '{}' ../ \;

From man find:

  -exec command ;
          Execute command; true if 0 status is returned.
          All following arguments to find are  taken  to
          be  arguments to the command until an argument
          consisting of `;' is encountered.  The  string
          `{}'  is  replaced  by  the  current file name
          being processed everywhere it  occurs  in  the
          arguments  to  the  command, not just in argu‐
          ments where it is alone, as in  some  versions
          of  find.   Both  of these constructions might
          need to be escaped (with a `\') or  quoted  to
          protect them from expansion by the shell. 
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .