How to exclude files/directory when tar - up a files

Linux & Unix newsgroup archiveAix2003

Linuxmisc » Aix

News Grou #1 / 2 Sun, 28 Sep 2003 14:06:59 GMT
I need to tar up a directory, but I want to omit certain files/sub-directory
. How can I do it? In Solaris I can append in a ".Exclude" file, but I cant'
find this option in AIX.

Please advise, Thanks

Andrew

Steve Los #2 / 2 Mon, 29 Sep 2003 05:25:29 GMT
In article <nNRA6.1514$s34.45...@ozemail.com.au>,
 "News Group" <andrew.h...@integration.sungard.com> writes:

You can use the -L option.

Create a file of filenames that you want included in the tar
archive, one filename per line.  Then list the name of this
file after the -L option.  Tar will only archive exactly what
is listed.  Directories are not recursed.

Building the file of filenames isn't too difficult.  You can
use "find" to build a complete list and then edit the list
by hand.

find dir -print > list
vi list
tar -c -f tar.out -L list

If you need to automate this, you have several options.
You can pipe the list through "grep -v" or "egrep -v"
to take out lines you don't want.

find dir -print | grep -v skipdir > list

find dir -print | egrep -v 'skipdir|nogood' > list

You can get clever with find and have it omit files
you don't want.

find dir ! -name '*.old' -print > list

find dir \( \( -name skipdir -o -name nogood \) -prune \) \
  -o -print > list

For example, suppose you want to archive directory "dir" but
want to skip any file whose name ends with .old.  You could
do it like this:

find dir ! -name '*.old' > list

tar -c -f tar.out -L list

This page is kept from the Linuxmisc archive of Linux and Unix newsgroups (snapshot 2014). Posts are shown as they were published, so commands, versions and addresses date from the original discussion. Linuxmisc.com now publishes a guide to online casinos in Canada.