How can I get mv (or the * wildcard) to move hidden files?
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 ..?*
.
In your additions, you got errors but the code still worked. The only thing to add is that you told it only to copy the dot files. Try:
mv src/* src/.* dst/
You will still get the errors for the . and .. entries, which is fine. But the move should succeed.
~/scratch [andrew] $ mv from/* from/.* to/
mv: cannot move ‘from/.’ to ‘to/.’: Device or resource busy
mv: cannot remove ‘from/..’: Is a directory
~/scratch [andrew] $ ls -a from/ to/
from/:
. ..
to/:
. .. test .test
If you ls -l
in a directory, you will see .
and ..
among listed files. So, I think mv .* /dest
takes those pointers into account. Try:
mv /tmp/home/rcook/{*,.[^.]*,..?*} /home/rcook/
this will ignore those current and parent dir pointers.
You will get an error if any of the three patterns *
, [^.]*
or ..?*
matches no file, so you should only include the ones that match.