Basic tar usage

As you probably know tar is designed to store and extract files from an archive file (a tarfile). Here I’ll show you some basic usage of this tool…

Here we go!

Archive a set of files:

tar -cvf tarfile.tar /var/log/syslog /var/log/messages

Archive and compress (gzip) a set of files:

tar -cvzf file.tar.gz /var/log/syslog /var/log/messages

Archive and compress (bzip2) a set of files:

tar -cvjf file.tar.bz2 /var/log/syslog /var/log/messages

Extract a tar file:

tar -xvf file.tar
tar -xvzf file.tar.gz
tar -xvjf file.tar.bz2


Display the content of a tar file:

tar -tvf file.tar
tar -tvzf file.tar.gz
tar -tvjf file.tar.bz2


Replace a file in an existing tar file:

tar -rvf tarfile.tar filetoreplace

Update a file in an existing tar file:

tar -uvf tarfile.tar newfile

Copy all files in one directory to another directory on local host:

cd /etc; tar cf – . | (cd /etc.bak; tar xvpf -)

Copy a directory from one host to another and preserve ownership and permissions:

tar -cf – /var/amavisd | ssh user@otherhost tar -xf -

  • 1 کاربر این را مفید یافتند
آیا این پاسخ به شما کمک کرد؟

مقالات مربوطه

Internal server error with 777 chmodded folders and files

For PHP applications to access MySQL databases or upload (write) files to site folder(s), the...

Can I host adult content on your web hosting?

Yes, as long as it's legal adult material (no child porn or weird things).

Can you install a script on my account?

Yes, we can install any standard script for a one time fee of 15$. Most scripts can be...

Can you transfer my website from my old web hosting company?

For us to be able to move your website from your old web hosting company we will need the...

Do you do backups?

Yes, daily on all shared and reseller accounts! Vps and dedicated server's backups are client's...