How can I get mv (or the * wildcard) to move hidden files?
Solution 1:
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 ..?*
.
Solution 2:
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
Solution 3:
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.
Solution 4:
Two possible solutions I can think of. The first is to use cp instead with its recursive option, copying the current directory to the destination.
cp -Rp . /desired/directory
then you can remove the source files in the current directory
Alternatively, if you know the files are sanely named (no spaces, wildcards, non-printable characters), you can do something like this
mv $(ls -A) /desired/directory