Ubuntu – How to get mv (or the * wildcard) to move hidden files

bashcommand line

I am migrating my home directory from an old system to a new one, and the tarball I made contains everything, including hidden files like .bashrc. However, when I move the contents of the unpacked tarball (which are in /tmp) to my new home directory, the hidden files do not copy (mv /tmp/home/rcook/* /home/rcook/). How can I get mv to move them?

Actually, I think the problem is not with mv, but with bash's globbing. If I do this:

mkdir a
mkdir b
touch a/.foo
touch a/bar
mv a/* b/
ls -a a/ b/

I see this:

a/:
.  ..  .foo

b/:
.  ..  bar

a/.foo did not move. So how can I get the * wildcard to find hidden files?

Yes, I suppose I could decompress the tarball directly into my home directory, but the tarball decompresses into home/rcook/..., and I want to be sure I overwrite the new .bashrc, etc. with the old, customized versions, and knowing how to find and move hidden files is a worthwhile skill. Suggestions?


Some answers suggest doing something like mv src/.* dest/. However, I tried this on my test directories and got errors. Starting with:

rcook$ ls -a a/ b/
a/:
.  ..  bar  .foo

b/:
.  ..
rcook$ mv a/.* b/
mv: cannot move 'a/.' to 'b/.': Device or resource busy
mv: cannot remove 'a/..': Is a directory
rcook$ ls -a a/ b/
a/:
.  ..  bar

b/:
.  ..  .foo

What am I doing wrong?

Best Answer

You can do this :

shopt -s dotglob
mv /tmp/home/rcook/* /home/rcook/

You can put

shopt -s dotglob

in your ~/.bashrc if you want it to be the default.

See http://mywiki.wooledge.org/glob


Another approach to copy the dot files:

mv /tmp/home/rcook/.[!.]* /home/rcook/

Don't use the pattern ..* as it matches .. (pointer to the parent directory). If there are files whose name begin with two dots (..something), also use the pattern ..?*.