tar ONLY hidden files
I have been looking online for a bit and can't seem to find any information on this, so I thought I would ask.
It is easy enough to include hidden files in a tar archive, but what I want to do is have only the hidden files placed into the archive. I want to backup the configuration files from my /home directory, but not the ~30 GB of downloads/music/randomness that also lives there. Doing: Code:
tar cvf /tmp/backup.tar ~/.* I am assuming there is some Bash expression I am missing here. I was thinking I could script it so that a list of the hidden files/directories is manually fed into tar directly, but that seems a bit hackish; I am sure there is a proper way to do it. |
Try this,
Code:
tar cvf /tmp/backup.tar ~/\.* What I believe is happening the way you have it this-- the (.) is a wildcard for any one character. So the way you are entering it you are saying to backup any files in your home directory that begins with any character followed by any series of characters. The (\) protects the (.), making bash read it as a literal (.) and not a wildcard. George |
Seems like that is doing the same thing.
Here is the output I get: Code:
tj@T-Bird:~$ tar cvf /tmp/backup.tar ~/\.* Code:
/home/tj/./.vlc/cache/ |
Sorry about my previous post-- after closer examination what I tried did get unhidden files and directories. I just did it with a user that has very few unhidden files in the home directory. I also noticed though, that my suggestion included files one directory up (included ../), which on this system was only one other folder with mainly hidden files. So, my suggestion is not close to what you are looking for. Hopefully someone will come along soon that can help.
George |
Something like
Code:
find -name .\* | tar czf test.tgz -T - Cheers, Tink |
Same result with that one.
Running it in a test directory: Code:
tj@T-Bird:~/Temp/PlayPen$ tree -a Quote:
|
Of course ... my bad, and my apologies.
Code:
find -type f -name .\* | tar czf test.tgz -T - There you go. Cheers, Tink |
Yes, that works for the files. I can't seem to get it working for hidden directories though. Giving "-type d" returns all files, for some reason.
But I managed to figure this out while poking around with variations on the pipe: Code:
ls -A | egrep '^\.' | tar cvf ./test.tar -T - I am running this against my home directory to see what comes out. Thanks all. |
And another shot :} ... this time tested :D
Code:
find -regex './\..*' | tar cvf ./test.tar -T - Cheers, Tink |
directory '.' vs hidden file '.' gotcha
regarding the repeated mysterious reappearance of all files -
keep in mind that in every directory the current directory is '.' and for all but the root directory '..' means the parent directory. I'll bet tar suppresses following '..' up the directory hierarchy, but I'll also bet that explicitly listing ~/.* makes tar include ~/./regular_file.txt for instance. |
Quote:
I avoided this by calling ls with -A rather than -a. It turns out (the things you learn from the man pages, eh?) that -a is literally all files, and -A is all files without the current and parent directory symbols. When this is piped into tar, everything works the way it should. Tinkster, looks like this one has hit the mark as well. :) Though I noticed it seems to take quite some time to complete; I also hear a lot of thrashing from the drive. I take it that it must be looking for hidden files/directories under the non-hidden directories? That is a nice trick to keep in my list of useful commands, but for this particular situation I just want it to check 1 directory deep to get my user configuration files. But I can think of a few uses for finding hidden files anywhere in the tree. In fact, this whole topic has been quite illuminating on a few concepts and regexes. Gotta love the community here at LQ. |
Quote:
-maxdepth 1 to the find.... Glad you're enjoying the "brain share" at LQ :} Cheers, Tink |
Here's a nice one:
Code:
find . -maxdepth 1 -regex "\./\..*" -print0 | tar cvfz test.tgz --null -T - |
Easiest way is
Code:
tar -czf whatever .[^.]* ..?* |
All times are GMT -5. The time now is 10:47 PM. |