Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining TAR with FIND

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,
I am trying to use the TAR command to archive a subset of files within a directory (and all its subdirectories).
I am interested in all files ending in .csv.

I think the way to do this is to combine the TAR and the FIND command e.g. find . -name *.csv
will list all file from the current direcotry downwards which end in .csv.
However when I try and pipe this into the tar command e.g.

find . -name *.csv | tar -cvf test.tar

the command does not work.

Any ideas on how to get this working?
I may be on the wrong path with the FIND command.

Thanks!!

 
try

tar cvf test.tar $(find . -name '*.csv')

don't forget the single quotes when you're using globbibg characters (* and ?) in the find command Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Hi Thomas,

Try this :

find . -name '*.csv' | tar cTf - test.tar

- Depending on the OS, use the T or I option.
-T FILE
`tar' will use the contents of FILE as a list of archive members
or files to operate on, in addition to those specified on the
command-line.

- I am not sure that all versions of tar accept '-' for 'stdin'
Jean Pierre.
 
Thanks very much guys!!
Mike your solution worked perfectly - but has lead to another question.
However when I try to expand it the solution to include everything except csv files, it does not appear to work:-

e.g. tar cvf test.tar $(find . ! -name '*.csv')

find . ! -name '*.csv' gives me the correct list, but is not what is being feed into the tar command.

Any more ideas/
Thanks again!




 
Restrict your find to files only. Otherwise the negative case will pass directory names to the tar command.
Code:
find . -type f ! -name '*.csv'
Cheers, Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top