tar: restore only non-hidden files during a restore of /home
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
tar: restore only non-hidden files during a restore of /home
I am stuck for a solution to this seemingly simple problem: restore all non-hidden files and directories to all /home directories found in in a full-system tarball.
I created this test environment in my home directory to mimic a /home restore from a backup directory in /:
I made and populate the following directories:
~/ttar
~/ttar/td1 (several dummy files, some links, some hidden)
~/ttar/td1/root (several dummy files, some links, some hidden)
~/ttar/td1/bin (several dummy files, some links, some hidden)
~/ttar/td1/usr (several dummy files, some links, some hidden)
~/ttar/td1/home/alan/.config (same as ~/.config)
~/ttar/td1/home/alan/.gconfig (same as ~/.gconfig)
~/ttar/td1/home/alan/ (numerous dummy files, some links, some hidden)
and ~/ttar/td1/backups (to simulate a backup archive in /)
Moving into ~/ttar/td1/backups I created a tar archive simulating a full system archive using the command:
tar -zxvpf ttar.tar.gz --directory=../ .
Then, for several hours, I repeatedly erased everything in ~/ttar/td1 (except ~/ttar/backups) during research and trial-and-error; this the partial solution I came up with:
tar -xzvpf ttar.tar.gz --directory=../ ./home
The partial solution yields only the original ~/ttar/td1/home/alan but with unwanted hidden files.
Can anyone tell me how to avoid restoring those last few hidden files?
you can run find .* and it will list all the hidden files/folders
Yup, that will list all hidden files and folders in and below a directory in an existing file system, but even redirecting the output to a file, and using that file as input to tar to exclude files from the restore, will not stop tar from restoring hidden files in the archive tarball that aren't on the system yet.
By the by, I altered my 'nearest solution' tar command posted above as it was the wrong example.
Moving into ~/ttar/td1/backups I created a tar archive simulating a full system archive using the command:
tar -zxvpf ttar.tar.gz --directory=../ .
That command extracts from a tar archive. It does not create one.
Quote:
Then, for several hours, I repeatedly erased everything in ~/ttar/td1 (except ~/ttar/backups) during research and trial-and-error; this the partial solution I came up with:
tar -xzvpf ttar.tar.gz --directory=../ ./home
I'm having trouble figuring out just what you did, but this should extract everything except the dotfiles and directories:
Code:
tar -zxvpf ttar.tar.gz --exclude='.[^/]*' --directory=../ .
That pattern excludes any name that begins with a dot that is not immediately followed by a slash (so that "./" itself is not excluded).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.