Moving all files in current directory up one directory

2

1

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?

DextrousDave

Posted 2013-07-06T12:00:48.443

Reputation: 385

Answers

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.

evilsoup

Posted 2013-07-06T12:00:48.443

Reputation: 10 085

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 – DextrousDave – 2013-07-06T12:58:07.393

1

You may also find this page useful for future reference (that whole website is a very good reference for working with bash).

– evilsoup – 2013-07-06T13:04:50.653

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.

Mattias

Posted 2013-07-06T12:00:48.443

Reputation: 551

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. 

terdon

Posted 2013-07-06T12:00:48.443

Reputation: 45 216