tar command exclude question

I'm trying to restore  /etc/ directory and wants to exclude  /etc/pki directory and some  other files. The follwoing command is not working. Do I need to do anything else?

tar  xpvfz  backup_opt.tgz  -C  /  --exclude=/etc/pki/
mokkanAsked:
Who is Participating?
 
farzanjConnect With a Mentor Commented:
Are you trying to create tar ?

You can using x, which means you are extracting tar.

To create tar you need option c

tar pcvfz  backup_opt.tgz  -C  /  --exclude=/etc/pki/
0
 
farzanjCommented:
Also you can have as many excludes as you want -- while creating the tar.  If you have a tar and you want to delete files from it that is different.  Please tell me what you want

0
 
wesly_chenConnect With a Mentor Commented:
mkdir /etc_tmp
tar  xpvfz  backup_opt.tgz  -C /etc_tmp
rm -rf /etc_tmp/etc/pki
cp -pr /etc_tmp/etc  /
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
farzanjConnect With a Mentor Commented:
tar  cpvfz  backup_etc.tgz  /etc --exclude=/etc/pki/

You don't need -C in creation.  But you do need to mention the folder you want to tar!!

You would need -C when you extract if you did not create with -P (upper case P) option.
0
 
mokkanAuthor Commented:
I want to do

cp  -ar  *  /etc  

but, it is prompting and I need to say yes all the time. How do I force it to overwrite?
0
 
wesly_chenConnect With a Mentor Commented:
/bin/cp -afpr * /etc/
-f force
/bin/cp to avoid alias
0
 
wesly_chenConnect With a Mentor Commented:
/bin/cp -afr * /etc/
0
 
farzanjConnect With a Mentor Commented:
\cp -far * /etc

I wrote it before but somehow it did not go through
0
 
mokkanAuthor Commented:
still same thing I saw   cp  -i in .bashrc file I comment out and I did source .bashrc

still same issue
0
 
wesly_chenConnect With a Mentor Commented:
You mean
/bin/cp -afr * /etc
or
\cp -far * /etc
still prompt ?
0
 
simon3270Connect With a Mentor Commented:
Just a side comment - if you comment out an alias in .bashrc and simply source it again, the old alias definition is still in place.  Either explicitly "unalias cp", or comment out the line and log out and in again.
0
 
farzanjConnect With a Mentor Commented:
\cp unaliases it
0
 
mokkanAuthor Commented:
Thanks a lot all of you. It worked fine now. After I logged in back, it  didn't source .bashrc correctly
0
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.