2

I was searching the answer to question how to move files from one folder to upper folder and nowhere I have not found the answer mv name/* .

Why I can't use this to moving files to upper folder? The most voted option is mv * .[^.]* .., so my question is, why mv name/* . is wrong?

Regards

2

Because of globbing. mv name/* . only matches files in the folder that don't start with a dot (.). You can change that behavior by setting dotglob in a bash shell:

shopt -s dotglob

Now, you can use mv name/* . to move ALL files and folders.

As example is have a folder containing two files: file and .file:

$ echo *
file
$ shopt -s dotglob
$ echo *
file .file

Notice: mv * .[^.]* destination works without the dotglob, because it matches first * and second .[^.]* which matches files/folders starting with a dot (not . and ..).

0

You may need to also match .* not just * if the archive contained dot-files.

Also add && rmdir folder to the end o that to remove the now extraneous folder. This is save because it will only run if the mv returns success AND because rmdir will not remove a non-empty directory.

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.