LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   using tar to compress specific files in a directory named a certain way (https://www.linuxquestions.org/questions/linux-newbie-8/using-tar-to-compress-specific-files-in-a-directory-named-a-certain-way-771506/)

slinky66 11-25-2009 12:29 PM

using tar to compress specific files in a directory named a certain way
 
Hi All,

I need to create a tar archive of only files that start with "60-", located in a directory with a lot of other files that I don't want in the archive.

I tried this but it doesn't work:

tar -zcvf backfill.tar.gz | grep "60-"

Can someone help?

Thanks

JohnGraham 11-25-2009 12:43 PM

Quote:

Originally Posted by slinky66 (Post 3769470)
Hi All,

I need to create a tar archive of only files that start with "60-", located in a directory with a lot of other files that I don't want in the archive.

I tried this but it doesn't work:

tar -zcvf backfill.tar.gz | grep "60-"

Can someone help?

Thanks

You're over-complicating it:

Code:

tar -zcvf backfill.tar.gz 60-*
:)

John G

slinky66 11-25-2009 01:02 PM

Thanks. When I ran the command the way you suggested,I received the "argument list too long" message so I created a text file containing the list of files:

find /usr/www/htdocs/images/closeup | grep "60-" > filelist.txt

And then, fed the text file to tar:

tar -zcvf backfill.tar.gz --files-from filelist.txt

Worked fine.

Thanks

fara78 11-25-2009 01:31 PM

i think this works too

tar -zcvf backfill.tar.gz `ls 60\-*`


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