Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tar 1

Status
Not open for further replies.

zyrag

IS-IT--Management
Dec 4, 2002
252
PH
how do i tar a directory? e.g. i'm in dir /usr/local/apache2/htdocs and i want to tar /home/uploads directory.

thnks,
 

tar cvf uploads.tar /home/uploads

Cheers Henrik Morsing
Certified AIX 4.3 Systems Administration
& p690 Technical Support
 
thanks morsing, it works. is it right when i use tar xvf uploads.tar to extract the files on it? the command doesn't have errors but i don't know where did the files go. is it possible to create/extract the files on a specified directory?

thanks again,
 

If you create the archive using absolute paths, e.g. /home/uploads, they will be restored to the same directory.

You should really use relative paths. Go to the directory just above where you want to go and acrhive just the directory:

# cd /home
# tar cvf uploads.tar uploads

In that case the files will be extracted to a directory, uploads, relative to where you are.

# cd /tmp
# tar xvf uploads.tar

The files will then be in /tmp/uploads

Cheers Henrik Morsing
Certified AIX 4.3 Systems Administration
& p690 Technical Support
 
you can also tell tar where to put the files with "C".

tar -C /my_new_location -xvf my.tar


And you get compress with -z on both create and extract.


tar -czvf my.tgz /home tgz is the common extension for a zipped tar.

tar -zxvf my.tgz to extract zipped tar.

man tar to get all of the options on how to use tar.
 
on solaris tar you don't have the -C on -x ... (cd /my_new_location ; tar xvf /home/me/my.tar) would work ...

btw when using tar make sure you always use relative paths, saves a lot of trouble later. instead of 'tar cvf /tmp/etc.tar /etc' it is better to 'cd / ; tar cvf /tmp/etc.tar etc'

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top