Math-Linux.com

Knowledge base dedicated to Linux and applied mathematics.

Home > Linux > Tip of the day > Archiving and compressing data files tar

Archiving and compressing data files tar

All the versions of this article: <English> <français>

We will briefly discuss the use of archiving and data compression via the tar command.


Archiving

To archive data, we use the command tar -cvf, like this:

nadir@ipowerht:~/Desktop $ ls -al
total 73796
drwxr-xr-x   8 nadir nadir     4096 2005-10-14 18:56 .
drwxr-xr-x  37 nadir nadir     4096 2005-10-14 18:49 ..
-rw-r--r--   1 nadir nadir 72265250 2005-10-14 00:30 archive.tar.gz
-rw-r--r--   1 nadir nadir       69 2005-03-20 17:22 .directory
drwxr-xr-x   2 nadir nadir     4096 2005-04-08 00:10 evian
drwxr-xr-x   2 nadir nadir     4096 2005-10-14 18:56 muzik
-rw-r--r--   1 nadir nadir    18652 2005-10-14 14:21 pagerankstatus-0.9.5.xpi
drwxr-xr-x   2 nadir nadir     4096 2005-05-16 18:08 poster
-rw-r--r--   1 nadir nadir  1517514 2005-05-16 17:18 poster.tar.gz
drwxr-xr-x   2 nadir nadir     4096 2005-05-16 18:03 poster.tar.gz_FILES
drwxrwxr-x  10 nadir nadir     4096 1970-01-01 01:00 Sauvegarde
-rw-r--r--   1 nadir nadir     1686 2005-10-13 17:12 sources.list
drwxr-xr-x   4 nadir nadir     4096 2005-03-27 19:13 these
-rwx------   1 nadir nadir  1632848 2005-03-19 22:53 these.tar.gz
nadir@ipowerht:~/Desktop $ tar -cvf muzik.tar muzik
nadir@ipowerht:~/Desktop $ ls *.tar
muzik.tar

tar -cvf is followed by the name of the archive, it must always end with .tar here it is muzik.tar, and the name of the directory that we want to archive, here it is muzik.

Data unarchive

To unarchive data we use the command tar -xvf followed by the name of the archive

nadir@ipowerht:~/Desktop $ tar -xvf muzik.tar

Archiving and compressing date files

When the data volume is important, we sometimes want to compress the data using the gunzip utility, we use the command tar -cvzf

nadir@ipowerht:~/Desktop $ tar -cvzf archive.tar.gz muzik

tar -cvzf est suivi du nom de l’archive (elle doit toujours terminer par .tar.gz ici c’est archive.tar.gz, et du nom du répertoire que l’on veut archiver, ici c’est muzik.

Decompression of data

To decompress the archive, use the extraction command tar -xvzf

nadir@ipowerht:~/Desktop $ tar -xvzf archive.tar.gz

Conclusion

All of these commands are very useful for backing up your data file . Do not to forget them !

Also in this section

  1. Crontab : Scheduling Tasks
  2. Time a task: time
  3. Download music and videos .mp3, .wma, .avi, .mpg , divx with google
  4. How to change the MAC address on Linux
  5. Comment changer son adresse MAC sous Linux
  6. How to Convert Text File From ISO-8859-15 to UTF-8 Encoding
  7. SVN — How to ignore file or directory in subversion?
  8. How to setup SSH timeout in shell script ?
  9. phpMyAdmin: Search and Replace in MySQL database
  10. How to encrypt/decrypt a file or directory in Linux?
  11. Find list of options that python was compiled with
  12. Check/find version of numpy i’m using
  13. Speedup GNU make build and compilation process
  14. How to make a denial of a service with fork functions in BASH ?
  15. Find out biggest cpu/memory consuming processes with ps command
  16. Intel compilation for MIC architecture KNL Knights Landing
  17. GNU compilation for MIC architecture KNL Knights Landing
  18. Archiving and compressing data files tar
  19. Linux How to delete or remove printer from command line
  20. Linux How to connect to Windows with remote desktop RDP in CentOS 7 / RedHat 7
  21. SVN — Branch, Branching subversion howto
  22. How to diff remote files using ssh ?
  23. Generating a self-signed certificate using OpenSSL with Linux CentOs/RedHat for Apache/httpd