LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 04-13-2004, 04:36 PM   #1
unamiccia
LQ Newbie
 
Registered: Apr 2004
Location: New York City
Distribution: Debian hybrid (originally Knoppix)
Posts: 9

Rep: Reputation: 0
Command line: How do I filter for dotfiles only?


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?

Thanks for all help!
 
Old 04-13-2004, 04:52 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Try this:
tar -cf ~/dotbackup.tar `find ~/ -name ".*" -type f`
 
Old 04-13-2004, 05:03 PM   #3
unamiccia
LQ Newbie
 
Registered: Apr 2004
Location: New York City
Distribution: Debian hybrid (originally Knoppix)
Posts: 9

Original Poster
Rep: Reputation: 0
That sounded good, but the following happened:

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?
 
Old 04-13-2004, 05:08 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
It looks like there may be funny characters in some file names - what are they - can you post the output of:
ls -l /home/me/.gnome/apps/Open*
 
Old 04-13-2004, 05:18 PM   #5
unamiccia
LQ Newbie
 
Registered: Apr 2004
Location: New York City
Distribution: Debian hybrid (originally Knoppix)
Posts: 9

Original Poster
Rep: Reputation: 0
Hmm -- they look pretty tame:

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
 
Old 04-13-2004, 05:22 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Sorry - it is probably the directory iteself - what about:
ls -l /home/me/.gnome/apps/
 
Old 04-13-2004, 05:25 PM   #7
Muzzy
Member
 
Registered: Mar 2004
Location: Denmark
Distribution: Gentoo, Slackware
Posts: 333

Rep: Reputation: 30
One problem is the space in 'OpenOffice.org 1.1.0'.

Doing something like this might be better:

find ~/ -name ".*" -type f -exec tar rf dotbackup.tar {} \;

Not sure if that predicate is really what you want though?

Do:

find ~/ -name ".*" -type f

to check that the files it lists are the ones you mean.

Mark Byers.
 
Old 04-13-2004, 05:30 PM   #8
unamiccia
LQ Newbie
 
Registered: Apr 2004
Location: New York City
Distribution: Debian hybrid (originally Knoppix)
Posts: 9

Original Poster
Rep: Reputation: 0
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 . . .
 
Old 04-13-2004, 05:35 PM   #9
unamiccia
LQ Newbie
 
Registered: Apr 2004
Location: New York City
Distribution: Debian hybrid (originally Knoppix)
Posts: 9

Original Poster
Rep: Reputation: 0
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

(about thirty lines of this)

??
 
Old 04-13-2004, 05:37 PM   #10
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I think that should still work it is just using relative names.

For spaces you could also pipe the fins string though sed:
tar -cf ~/dotbackup.tar `find ~/ -name ".*" -type f | sed 's/\ /\\ /g'`
 
Old 04-13-2004, 05:38 PM   #11
Muzzy
Member
 
Registered: Mar 2004
Location: Denmark
Distribution: Gentoo, Slackware
Posts: 333

Rep: Reputation: 30
Try this match:

find ~/ -path "/home/me/.*" instead?

Or for current directory:

find . -path "./.*" instead?

This matches both dotfiles and directories. Using path matches the full path, not just the base filename.
 
Old 04-13-2004, 05:39 PM   #12
unamiccia
LQ Newbie
 
Registered: Apr 2004
Location: New York City
Distribution: Debian hybrid (originally Knoppix)
Posts: 9

Original Poster
Rep: Reputation: 0
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 ".*" !).
 
Old 04-13-2004, 05:40 PM   #13
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
Quote:
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.
 
Old 04-13-2004, 05:41 PM   #14
unamiccia
LQ Newbie
 
Registered: Apr 2004
Location: New York City
Distribution: Debian hybrid (originally Knoppix)
Posts: 9

Original Poster
Rep: Reputation: 0
I am called to dinner! Will try the new suggestions and post back later.

Meanwhile, thanks for the blow-by-blow help!
 
Old 04-13-2004, 05:47 PM   #15
Muzzy
Member
 
Registered: Mar 2004
Location: Denmark
Distribution: Gentoo, Slackware
Posts: 333

Rep: Reputation: 30
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.

Mark Byers.

Last edited by Muzzy; 04-13-2004 at 05:57 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 07:19 PM
cp command can't do "dotfiles" netdemon Linux - Software 4 04-01-2005 03:50 AM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 07:45 PM
51 characters only in the 1st Line of command line eggCover Linux - General 2 07-29-2004 01:28 PM
Where is Command line utility for Cups and command tutorial mossy Linux - Software 8 01-16-2004 12:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration