# Scripting using the FIND command

**URL:** <https://community.unix.com/t/scripting-using-the-find-command/208418>\
**Category:** Shell Programming and Scripting\
**Created:** [August 12, 2008, 5:01pm UTC](https://community.unix.com/t/scripting-using-the-find-command/208418 "2008-08-12T17:01:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![buechler66](https://community.unix.com/letter_avatar/buechler66/32/6_449c533f586939b6e5f246632a46421f.png) [@buechler66](https://community.unix.com/u/buechler66)\
**Post date:** [August 12, 2008, 5:01pm UTC](https://community.unix.com/t/scripting-using-the-find-command/208418/1 "2008-08-12T17:01:23Z")

</div>

I'm working on a 'find' command which uses the -exec option to tar a listing of files that it finds. Is there a single option available that would both 1) create the TAR file if it doesn't exist and/or 2) update the TAR file if it already exists?

Currently when I want manually create a TAR file and then add files to it I need to issue two different options to the TAR command. In other words, my command sequence needs to look like:

tar -cvf myTarFile.txt fileA.txt  
tar -uvf myTarFile.txt fileB.txt  
tar -uvf myTarFile.txt fileC.txt

So in the first iteration I have to include the -c (e.g. create TAR file) option. And in subsequent iterations I have to include the -u (e.g. update TAR file) option.

I want to avoid programatically having to issue a different command for the first iteration. Is this possible?

Any help would be greatly appreciated!!!

---

<div class="post-metadata">

**Author:** ![sudhamacs](https://community.unix.com/letter_avatar/sudhamacs/32/6_449c533f586939b6e5f246632a46421f.png) [@sudhamacs](https://community.unix.com/u/sudhamacs)\
**Post date:** [August 12, 2008, 5:23pm UTC](https://community.unix.com/t/scripting-using-the-find-command/208418/2 "2008-08-12T17:23:38Z")

</div>

You can issue tar -uvf myTarFile.txt as the first command.(before iteration)  
Then in the iteration use tar -uvf myTarFile.txt filei.

---

<div class="post-metadata">

**Author:** ![shamrock](https://community.unix.com/letter_avatar/shamrock/32/6_449c533f586939b6e5f246632a46421f.png) [@shamrock](https://community.unix.com/u/shamrock)\
**Post date:** [August 12, 2008, 5:44pm UTC](https://community.unix.com/t/scripting-using-the-find-command/208418/3 "2008-08-12T17:44:41Z")

</div>

Use pax instead of tar and you won't need to issue two commands. After creating the archive you can use tar on it.

```nohighlight
pax -w -f myTarFile.txt fileA.txt fileB.txt fileC.txt
tar tvf myTarFile.txt

```

---

<div class="post-metadata">

**Author:** ![buechler66](https://community.unix.com/letter_avatar/buechler66/32/6_449c533f586939b6e5f246632a46421f.png) [@buechler66](https://community.unix.com/u/buechler66)\
**Post date:** [August 12, 2008, 8:24pm UTC](https://community.unix.com/t/scripting-using-the-find-command/208418/4 "2008-08-12T20:24:56Z")

</div>

Thank you both for the solutions. Great help...I appreciate it.
