Exclude files/directores while tar extraction

I used "tar -cvzf clone.tgz /" to backup the root directory '/' on my ubuntu 9.10 server. Now I want to extract it on a newly installed machine. How could I exclude files and directories while tar extraction.
For extraction I'll be using "tar -xvpzf clone.tgz -C /" which overwrites all the files and directories.

Let say I want to exclude the directory '/etc/udev/' and a file '/home/file1' while Extracting the tar file. Is it possible to do so?
Who is Participating?
Maciej SConnect With a Mentor sysadminCommented:
Use exclude.
tar -xvpzf clone.tgz --exclude "/etc/udev" --exclude "/home/file1" -C /

Open in new window

Thyagaraj03Author Commented:
For checking, I created tar of  /etc/ and /home and tried to extract on a directory called 'test' with the following command:

tar -xvpzf clone.tgz --exclude "/etc/udev" --exclude "/home/file1" -C /test/

The 'test' directory has the udev dir. and the file1 in the respective directories. What I'm doing wrong?.
BlazConnect With a Mentor Commented:
Try removing leading /

tar -xvpzf clone.tgz --exclude "etc/udev" --exclude "home/file1" -C /test/

Maciej SsysadminCommented:
Post output of "tar ztf clone.tgz" command.
Thyagaraj03Author Commented:
Thanks a lot!. Blaz made a small change and it worked.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.