LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Command line: How do I filter for dotfiles only? (https://www.linuxquestions.org/questions/linux-general-1/command-line-how-do-i-filter-for-dotfiles-only-169723/)

Shade 04-13-2004 09:42 PM

Sometimes the answer is less complicated than piping commands, or stacking them.
This should work :

tar -czvf dotfilebackup.tgz \.*

The \ takes out special meaning of .
In this case, the special meaning is current directory. :-D

Works with ls, at least. didn't want to try tarring my entire . contents.

--Shade

Muzzy 04-14-2004 03:45 AM

I didn't know about the \. trick, this useful to know... however, I have tested your suggestion and it isn't quite correct because the directories '.' and '..' are included. Doing \.??* fixes it, at the risk of missing files of the form '.a' . Possibly this could be fixed in a better way??

But, I have actually tried the following:

find . -path "./.*" -exec tar -rf backup.tar {} \;

and it works. I even tried untarring it again just to be sure.

I am sure we have thoroughly confused the poster by now with all these different answers! But it's good to share tricks. I actually learnt the 'find -exec' pattern a few weeks again on this very site and I have found it very useful for a number of tasks, and is well worth learning.

unamiccia 04-14-2004 01:26 PM

Original poster here. Thanks to all for the time and energy invested in confusing me!

I can confirm that Shade's backslash suggestion (post #16) works for me -- problem solved.

Muzzy's find suggestion (post #17) seems to execute the correct filter, but I tried to execute it with compression (tar -rzf) and it wouldn't append to a compressed file. Doing a tar -czf produced an archive file of only a few bytes' length, so that doesn't appear to work, either.

I would like to undergo additional confusion and deconfusion regarding the find strategy if any of you have further interest. Meanwhile, though, thanks again!

unamiccia 04-14-2004 01:32 PM

Oops -- to be more precise, Shade as modified by Muzzy works:

tar -czvf dotfilebackup.tgz \.??*

And yes, it appears that it would skip filename .a -- practically not an issue for me, but of course it would be great to know that one last tweak to establish full control over the operation . . .

Muzzy 04-14-2004 02:24 PM

Hehe between us we will get there! But half the fun is in the learning, and the other half is when it works :)

I agree that when you try to append + compress it doesn't work, but a solution to this could be to tar first and then use gzip afterwards. This gives:

find . -path "./.*" -exec tar -rf backup.tar {} \; ;gzip backup.tar

Not the most simple solution ever.

The ".??*" hack works 99.9% (based on sample size of 2) of the time and is less to type. Any further improvements from othe LQ'ers would be worth learning, but at least you have something that works.

AutOPSY 04-14-2004 03:12 PM

They should just create a switch for tar " -a " To archive all files begginning with a dot.

Not being a proggrammer though, I don't know what problems this would cause.

LinFreak! 04-14-2004 06:10 PM

I found this problem also but gave up and removed the leading dot... I was in a hurry. It took ages.
Confucious say: the slow method removes the need for haste!


All times are GMT -5. The time now is 09:29 AM.