Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
I want to archive the "dotfiles" and "dot directories" in my /home directory. When I try tar -czvf dotfilebackup.tgz .* I get an archive of everything because the shell interprets the "." to mean "the current directory," not "filenames beginning with a dot."
What's the filter trick to nab everything beginning with a dot but not the rest of the current directory's contents?
me@box:~$ tar -cf ~/dotbackup.tar `find ~/ -name ".*" -type f`
tar: Removing leading `/' from member names
tar: /home/me/.gnome/apps/OpenOffice.org: Cannot stat: No such file or directory
tar: 1.1.0/.order: Cannot stat: No such file or directory
tar: /home/me/.gnome/apps/OpenOffice.org: Cannot stat: No such file or directory
tar: 1.1.0/.directory: Cannot stat: No such file or directory
tar: /home/me/.kde/share/applnk/OpenOffice.org: Cannot stat: No such file or directory
tar: 1.1.0/.directory: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
Is there a little edit that will get this working?
me@box:~$ ls -la /home/gb/.gnome/apps/Open*
total 40
|drwxr-xr-x 2 me me 4096 Mar 11 00:18 .
drwxr-xr-x 3 me me 4096 Mar 11 00:18 ..
-r--r--r-- 1 me me 167 Sep 1 2003 .directory
-r--r--r-- 1 me me 91 Sep 1 2003 .order
-r--r--r-- 1 me me 208 Sep 1 2003 calc.desktop
-r--r--r-- 1 me me 208 Sep 1 2003 draw.desktop
-r--r--r-- 1 me me 217 Sep 1 2003 impress.desktop
-r--r--r-- 1 me me 208 Sep 1 2003 math.desktop
-r--r--r-- 1 me me 1118 Sep 1 2003 printeradmin.desktop
-r--r--r-- 1 me me 214 Sep 1 2003 writer.desktop
Aha -- good call! I wonder why OpenOffice.org sticks a space in their directory?
me@box:~$ ls -la /home/me/.gnome/apps/
total 12
drwxr-xr-x 3 gb me 4096 Mar 11 00:18 .
drwxr-xr-x 6 me me 4096 Apr 13 16:11 ..
drwxr-xr-x 2 me me 4096 Mar 11 00:18 OpenOffice.org 1.1.0
Do you have a top-of-your-head modification of the find syntax to handle that? Sorry, I'm feeling like a lazy questioner -- I could do this work myself . . .
Muzzy: I didn't see your post before I posted the above. Here's what happens when I try your syntax:
me@box:~$ find ~/ -name ".*" -type f -exec tar rf dotbackup.tar {} \;
tar: Removing leading `/' from member names
tar: Removing leading `/' from member names
tar: Removing leading `/' from member names
tar: Removing leading `/' from member names
tar: Removing leading `/' from member names
BTW, I'm eager to learn this application of find, but I could swear that I once knew a simple filter strategy for outputting the files and directories that started with a "dot" without using find -- maybe through quoting -- but all my little tests prior to posting here failed to jog my memory (and try searching forums or Google on the string ".*" !).
Originally posted by unamiccia Aha -- good call! I wonder why OpenOffice.org sticks a space in their directory?
me@box:~$ ls -la /home/me/.gnome/apps/
total 12
drwxr-xr-x 3 gb me 4096 Mar 11 00:18 .
drwxr-xr-x 6 me me 4096 Apr 13 16:11 ..
drwxr-xr-x 2 me me 4096 Mar 11 00:18 OpenOffice.org 1.1.0
Do you have a top-of-your-head modification of the find syntax to handle that? Sorry, I'm feeling like a lazy questioner -- I could do this work myself . . .
maybe.... (this is just top-of-my-drunk-head)...
mkdir /home/me/backup
for file in /home/me/.* ; do
cp "$file" /home/me/backup
done
and then tar this directory. Like I said, though, it's just a guess without testing it myself. Just make sure the quotes around "$file" are there in order to include spaces.
Doesn't the sed need to be:
sed "s/ /\\\\ "
because sed converts "\ " into a literal " " so you need to specify "\\\\ " to make sed see "\\ " so that it writes "\ " ! Even then, it seems that bash then converts it back to " " after the backtick is performed??? Even with 4 slashes it still doesn't work - I don't know why.
What was wrong with my earlier suggestion? Using the -exec of find, combined with the append of tar seems to do the trick for me.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.