Operating System - HP-UX
1833008 Members
2946 Online
110048 Solutions
New Discussion

Another Question About Tar

 
SOLVED
Go to solution
Andrew Kaplan
Super Advisor

Another Question About Tar

This one may be slightly more difficult.

If I want to tar a directory but leave out a specific subdirectory within it, what would the correct syntax be? Thanks.
A Journey In The Quest Of Knowledge
8 REPLIES 8
Patrick Wallek
Honored Contributor

Re: Another Question About Tar

That is not done quite as easily.

I would do something like the following:

# cd /dir/to/tar
# ls -1 >> ../filename
# vi ../filename
(Do this and remove the directory that you want to skip)
# tar -xvf /path/to/file.tar $(cat ../filename)
Andrew Kaplan
Super Advisor

Re: Another Question About Tar

I followed the steps you had outlined, and the command syntax that I used was:

# tar -cvf /path/to/tar.file $(cat /path/to/test)

I encountered the following error:

Illegal variable name.

What did I miss?
A Journey In The Quest Of Knowledge
Michael Schulte zur Sur
Honored Contributor

Re: Another Question About Tar

Hi Andrew,

try
tar -cvf /path/to/tar.file `cat /path/to/test`

greetings,

Michael

Andrew Kaplan
Super Advisor

Re: Another Question About Tar

Hi there --

I tried the syntax

tar -cvf /path/to/tar.file `cat /path/to/test`

and got the error:
Cannot add file cat /home/ahk/test: No such file or directory

I also tried

tar -cvf /path/to/tar.file cat'/path/to/test`
and got the following:
Cannot add file cat /home/ahk/test: No such file or directory
Removing leading '/' from absolute path names in the archive

A Journey In The Quest Of Knowledge
Bernhard Mueller
Honored Contributor
Solution

Re: Another Question About Tar

Andrew,

the reason for the error is that you are using the C-Shell.

Just feed the tar to sh and it will work:

sh -c 'tar cvf /path/to/tarfile $(cat ../filelist)'

Regards,
Bernhard
Andrew Kaplan
Super Advisor

Re: Another Question About Tar

That did it. Thanks.
A Journey In The Quest Of Knowledge
Victor BERRIDGE
Honored Contributor

Re: Another Question About Tar

What about something like:
tar -cvf /tmp2/vbe/find_test -C $(find . -print|grep -v )

All the best
Victor
Bob_Vance
Esteemed Contributor

Re: Another Question About Tar

Another, perhaps slightly more general, dynamic command example :>)

(cd /d2tar ; tar cvf /dev/rmt/0m `ls -1a |grep -vE '^\.$|^\.\.$|^exd1$|^exd2$' ` )

. the "1" lists one per line.

. the "a" is to force "." files to be printed, like ".profile". Depending on the Unix version, they may not show up without it -- e.g., certain Linux.

. the grep's -v excludes lines and -E allows expressions.

. the ^...$ means match entire name from beginning of line to end of line.

. here we exclude 2 directories, "exd1" and "exd2" (the "|" meaning "or").

. finally, the ^\.$|^\.\.$ excludes the "." and ".." that show up in a 'ls -1a' listing (which are current directory and parent directory).


bv
"The lyf so short, the craft so long to lerne." - Chaucer