Friday, May 3, 2024
211
rated 0 times [  211] [ 0]  / answers: 1 / hits: 233645  / 2 Years ago, fri, may 27, 2022, 4:03:37

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?


More From » command-line

 Answers
2

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 ..?*.


[#32559] Saturday, May 28, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
amencisiv

Total Points: 9
Total Questions: 102
Total Answers: 118

Location: Tajikistan
Member since Tue, Mar 21, 2023
1 Year ago
amencisiv questions
Wed, Dec 28, 22, 12:58, 1 Year ago
Wed, Sep 28, 22, 18:24, 2 Years ago
Fri, May 13, 22, 19:08, 2 Years ago
;