logo rss

La commande tar en quelques exemples

Intro

La commande GNU/Linux historique tar permet d'archiver tout ou partie d'un système de type UNIX. Par défaut l'archive créée n'est pas compressée, mais un logiciel de compression peut y être associé en vue de réduire la taille des archives générées.

Extraction

  • Lister et chercher un contenu :
user@host $ tar -tz -f archive.tar.gz
  • Extraire vers un chemin défini :
user@host $ tar -xzvf archive.tar.gz -C /tmp/un_dossier
  • Extraire une partie de l'archive :
user@host $ tar -xzvf archive.tar.gz "./arch/fichier01" "./arch/fichier02"

Création

  • Créer et compresser une archive avec lzip :
root@host:~# apt-get install lzip
user@host $ tar --lzip -cvf archive.tar.lz /a/folder/*
  • Créer une archive tar :
user@host $ tar -cvf archive.tar /a/folder/*
  • Créer et compresser avec gzip une archive tar :
user@host $ tar -czvf archive.tar.gz /a/folder/*
  • Créer et compresser plusieurs dossiers en archive bzip2 :
root@host~# tar cpjf backup.tgz /etc /var/log
  • Archive tar à travers ssh :
root@host~# tar -jcvf - /my/fodler/ | ssh root@10.0.0.124 "cat > /backup/$(date +%Y.%m.%d)_backup.tgz"
  • Sauvegarde complète du système :
root@host~# tar cvzf /$(date +%Y.%m.%d)_backup.tar.gz --exclude=/$(date +%Y.%m.%d)_backup.tar.gz --exclude=/dev --exclude=/mnt --exclude=/proc --exclude=/sys --exclude=/tmp --exclude=/media --exclude=/lost+found /
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

adresse mail de contact