Terminal Mv command including hidden files

May 13, 2011

I often forget how to do this, so this time im going to blog it so that I can always look back at it and hopefully it will also be helpful for everyone else.

Often when im moving files around on my development environment or remote servers I need to move files and folders back and forth, including important files such as .htaccess files.

A simple command like:

mv Folder/* .

Actually does not move hidden files, all be it moves all the rest.

I found two solutions.

Most linux machines will allow the following to set hidden files to be included. Note your regular move commands will now always include hidden files, if you do not want this then move on to the second solution.

shopt -s dotglob

And if not this works pretty nicely too

ls -A  | while read i; do mv /"$i" ; done

Hope this helps.


About me

Hello! I'm David Heward, how are you going? I'm a Senior Devops/Build Engineer, specialising in AWS & Cloud Automation. Based in London. Strong 10+ year background in Software development. Have a read of my blog. Have a look at some of my working projects. Contact me at @davehewy or on Linkedin.