xargs vs exec with find:


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting xargs vs exec with find:
# 8  
Old 07-14-2012
This should work if for some reason one insist using tar:
Code:
touch txtarchive.tar && find . -type f -name "file-*.txt" -exec tar uf txtarchive.tar {} +

This User Gave Thanks to jlliagre For This Post:
# 9  
Old 07-14-2012
Quote:
Originally Posted by Tribe
Could you provide examples with pax or cpio?
Code:
find path -type f '*.txt' | pax -w > txtarchive.tar

Many tar implementations have an option that allows them to read a file list from a file, allowing for find's output to be redirected and then read. In my opinion, not a very elegant solution. If I recall correctly, BSD tar uses -I and GNU tar uses -T. Like ps, tar is a ubiquitous utility whose usage, for anything non-trivial, varies a great deal between platforms of different lineage.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 10  
Old 07-19-2012
Quote:
Originally Posted by alister
Code:
find path -type f '*.txt' | pax -w > txtarchive.tar

Many tar implementations have an option that allows them to read a file list from a file, allowing for find's output to be redirected and then read. In my opinion, not a very elegant solution. If I recall correctly, BSD tar uses -I and GNU tar uses -T. Like ps, tar is a ubiquitous utility whose usage, for anything non-trivial, varies a great deal between platforms of different lineage.

Regards,
Alister
Thank you, it worked with pax and cpio after the proper fixes.

Code:
find path -name '*.txt' -type f  | pax -w > txtarchive.tar

Code:
find path -name '*.txt' -type f | cpio -ov -H ustar -F txtarchive.tar

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exec and xargs mvoe file to directory

Hello, I am trying to move all the file listed by below command to /tmp/testing directory find ./ -maxdepth 1 -type f -mtime +3 I tried using -exec and xargs - none of the combination is working? Please, help (3 Replies)
Discussion started by: saurabh84g
3 Replies

2. Shell Programming and Scripting

Difference b/w xargs and "-exec" in Find

Hi, What is the difference between the following commands find . -type f -exec grep 'abc' {} \; and find . -type f | xargs grep 'abc' Appreciate your help. (2 Replies)
Discussion started by: bobbygsk
2 Replies

3. Shell Programming and Scripting

find: missing argument to `-exec' while redirecting using find in perl

Hi Friends, Please help me to sort out this problem, I am running this in centos o/s and whenever I run this script I am getting "find: missing argument to `-exec' " but when I run the same code in the command line I didn't find any problem. I am using perl script to run this ... (2 Replies)
Discussion started by: ramkumarselvam
2 Replies

4. Programming

difference bewteen pipe, xargs, and exec

I have read several docs on these on the web and looked at examples. I can't figure out the difference. In some cases you use one or the other or you combine them. can someone help me understand this? (1 Reply)
Discussion started by: guessingo
1 Replies

5. Shell Programming and Scripting

Xargs + Find Help

Guys i want to run a command to list all directories that havn't been modified in over 548 days ( 1.5 yrs ). Id like to run a script to first print what the command finds ( so i get a list of the files pre move ... i have a script set for this : find /Path/Of\ Target/Directory/ -type d -mtime... (4 Replies)
Discussion started by: modulartention
4 Replies

6. Shell Programming and Scripting

find and xargs

hi, i've been trying to figure this weird error but I cannot seem to know why. I am using below find command: find . \( ! -name . -prune \) -type f -mtime +365 -print The above code returns no file because no files are really more then 365 days old. However, when I use xargs, its... (9 Replies)
Discussion started by: The One
9 Replies

7. UNIX for Dummies Questions & Answers

XARGS and FIND together

I am trying to delete files older than 60 days from a folder: find /myfolder/*.dat -mtime +60 -exec rm {} \; ERROR - argument list too long: find I can't just give the folder name, as there are some files that I don't want to delete. So i need to give with the pattern (*.dat). I can... (3 Replies)
Discussion started by: risshanth
3 Replies

8. Shell Programming and Scripting

String substitution on find results inside exec/xargs

What I'm trying to do is perform a copy, well a ditto actually, on the results of a find command, but some inline string substitution needs to happen. So if I run this code find ./ -name "*.tif" I get back these results. .//1234567.tif .//abcdefg.tif Now the action from exec or xargs I... (2 Replies)
Discussion started by: myndcraft
2 Replies

9. Shell Programming and Scripting

MV files with xargs or -exec

Hi I need to move multiple (say 10 files) from one location to another location. My selection would be like this... ls -ltr *.arc | head ---> Need to move top 10 files with single command without iterating in loop. I know we can move files like this with find command but not sure if I can... (4 Replies)
Discussion started by: malaymaru
4 Replies

10. UNIX for Dummies Questions & Answers

Difference between xargs and exec

Hi, I have tried both the options in small dummy scripts, but somehow i can't differentiate between the two. find . -name H* -exec ls -l {} \; find . -name H* | xargs ls -l Both work the ditto way. Any help is appreciated. (19 Replies)
Discussion started by: vibhor_agarwali
19 Replies
Login or Register to Ask a Question