Moving files around to include hidden files

Often times when moving files from one directory to another, specifically when dealing with web folders, I have missed out the all important .htaccess hidden files with just the usual `mv source/* destination` command.

Here's a one liner that will include the hidden files too:

$ ls -A <source> | while read i; do mv <source>/"$i" <destination>; done

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

shopt in a subshell

shopt can be limited to just applying to a single command by running in a subshell (i.e. in parenthesis):

(shopt -s dotglob; mv /* )

However, in common with the above solutions, this still fails if any of the copied files is a directory, and the destination includes a non-empty directory of the same name. 'mv -f' doesn't help in this case. I think the best solution is therefore a tweak of sandip's answer: iterating over each file to be copied, and deleting from the destination before moving, one at a time.

Nice tip

Thanks for this nice tip, I just "recover" from a unfortunate "mv *" on my home directory where I almost lost all my "hidden" files and folders because the bash wildcart did not include them.

I found another way to manage hidden file/folders: you can activate their inclusion in the environment with this command:

shopt -s dotglob

All the best,

Comment