Bash moving hidden files, reset dotglob

bashdot-filesmv

I wanted to move all files, including starting with dot (hidden) and folders (recursively).

So I used the following commands

shopt -s dotglob nullglob
mv ~/public/* ~/public_html/

and it worked.

But do I need to reset anything after doing shopt -s dotglob nullglob? Doesn't it change how commands like mv operate? Because I would like it changed back.

Best Answer

Yes, you would have to unset those options (with shopt -u nullglob dotglob) afterwards if you wanted the default globbing behaviour back in the current shell.

You could just do

mv ~/public/* ~/public/.* ~/public_html/

That would still generate an error without nullglob set if one of the patterns didn't match anything, obviously, but would work without having to set either option. It would probably also say something about failing to rename . since it's a directory, but that too isn't stopping it from moving the files.

A better option may be to use rsync locally:

rsync -av ~/public/ ~/public_html/

and then delete ~/public.

Related Question