Files
mkdocs/docs/Linux/archiver.md
2020-04-18 07:23:09 +02:00

309 lines
7.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Archiver et compresser
#### tar
Créer une archive tar: **tar -cvf**
```bash
root@DiskStation:~ # tar -cvf archive.tar .profile .bashrc test-dossier/
```
Afficher le contenu de l'archive sans l'extraire: **tar -tf**
```bash
root@DiskStation:~ # tar -tf archive.tar
.profile
.bashrc
test-dossier/
test-dossier/test-copy-scp.txt
```
Ajouter un fichier à l'archive: **tar -rvf**
```bash
root@DiskStation:~ # tar -rvf archive.tar .bash_history
root@DiskStation:~ # tar -tf archive.tar
.profile
.bashrc
test-dossier/
test-dossier/test-copy-scp.txt
.bash_history
```
Extraire les fichiers de l'archive: **tar -xvf**
```bash
root@DiskStation:~ # tar -xvf archive.tar
```
#### tgz
Extraire les fichiers de l'archive: **tar zxvf**
```bash
root@DiskStation:~ # tar zxvf archive.tgz
```
#### gzip
Compresser avec gzip:
```bash
root@DiskStation:~ # gzip archive.tar
root@DiskStation:~ # ls
archive.tar.gz
```
Decompresser avec gunzip:
```bash
root@DiskStation:~ # gunzip archive.tar.gz
root@DiskStation:~ # ls
archive.tar
```
Voir le contenu de l'archive avec zcat:
#### bzip2
Compresser avec bzip2:
```bash
root@DiskStation:~ # bzip2 archive.tar
root@DiskStation:~ # ls
archive.tar.bz2
```
Decompresser avec bunzip2:
```bash
root@DiskStation:~ # bunzip2 archive.tar.bz2
root@DiskStation:~ # ls archive.tar
```
#### zip
Compresser avec zip:
```bash
bruno@DS916:~ $ zip -r scripts.zip scripts/
adding: scripts/ (stored 0%)
adding: scripts/@eaDir/ (stored 0%)
adding: scripts/@eaDir/ffmpeg@SynoResource (deflated 84%)
adding: scripts/@eaDir/ffmpeg@SynoEAStream (deflated 35%)
adding: scripts/ffmpeg (deflated 64%)
adding: scripts/ffmpeg-convertMP4v3.sh (deflated 50%)
adding: scripts/running3.sh (deflated 48%)
adding: scripts/ffmpeg-convertMP4v4.sh (deflated 49%)
adding: scripts/ffmpeg-convertMP4v5.sh (deflated 56%)
```
Exclure les fichiers ressources invisibles (“*MACOSX” “.*Filename” “.ds store”):
```bash
bruno@DS916:~ $ zip -r -X scripts.zip scripts/
```
Décompresser avec zip:
```bash
bruno@DS916:~/test $ unzip scripts.zip
Archive: scripts.zip
creating: scripts/
creating: scripts/@eaDir/
inflating: scripts/@eaDir/ffmpeg@SynoResource
inflating: scripts/@eaDir/ffmpeg@SynoEAStream
inflating: scripts/ffmpeg
inflating: scripts/ffmpeg-convertMP4v3.sh
inflating: scripts/running3.sh
inflating: scripts/ffmpeg-convertMP4v4.sh
inflating: scripts/ffmpeg-convertMP4v5.sh
```
#### dmg (macOS)
Créer:
```bash
bruno@SilverBook:~$ hdiutil create -format UDZO -srcfolder hubiC/ hubic.dmg
.........
created: /Users/bruno/hubic.dmg
```
Différents formats d'image:
- UDZO Compressed image (default)
- UDRO Read only image
- UDBZ Better compressed image
- UDRW Read/Write image
- UDTO DVD disk image
Monter:
```bash
bruno@SilverBook:~$ hdiutil attach hubic.dmg
Calcul de la somme de contrôle de Protective Master Boot Record (MBR : 0)
Protective Master Boot Record (MBR : : vérifiée CRC32 $DC586CEA
Calcul de la somme de contrôle de GPT Header (Primary GPT Header : 1)
GPT Header (Primary GPT Header : 1) : vérifiée CRC32 $4EE88DC7
Calcul de la somme de contrôle de GPT Partition Data (Primary GPT Table : 2)
GPT Partition Data (Primary GPT Tabl : vérifiée CRC32 $42D33ACB
Calcul de la somme de contrôle de (Apple_Free : 3)
(Apple_Free : 3) : vérifiée CRC32 $00000000
Calcul de la somme de contrôle de disk image (Apple_HFS : 4)
.........................................................................................................................
disk image (Apple_HFS : 4) : vérifiée CRC32 $D4406A43
Calcul de la somme de contrôle de (Apple_Free : 5)
(Apple_Free : 5) : vérifiée CRC32 $00000000
Calcul de la somme de contrôle de GPT Partition Data (Backup GPT Table : 6)
GPT Partition Data (Backup GPT Table : vérifiée CRC32 $42D33ACB
Calcul de la somme de contrôle de GPT Header (Backup GPT Header : 7)
GPT Header (Backup GPT Header : 7) : vérifiée CRC32 $16D559B6
vérifiée CRC32 $BE421D06
/dev/disk3 GUID_partition_scheme
/dev/disk3s1 Apple_HFS /Volumes/hubiC
```
Voir:
```bash
bruno@SilverBook:~$ ls -lah /Volumes/hubiC/
total 8
drwxr-xr-x 11 bruno staff 442B 12 aoû 12:05 .
drwxr-xr-x@ 6 root wheel 204B 12 aoû 12:07 ..
drwxr-xr-x 2 bruno staff 68B 6 aoû 17:39 Documents
drwxr-xr-x 3 bruno staff 102B 6 aoû 17:39 HubiC
-rw-r--r-- 1 bruno staff 669B 6 aoû 17:39 HubiC readme.txt
drwxr-xr-x 2 bruno staff 68B 6 aoû 17:39 Images
drwxr-xr-x 2 bruno staff 68B 6 aoû 17:39 Videos
drwxr-xr-x 9 bruno staff 306B 6 aoû 17:39 scripts plex 0.9xx
drwxr-xr-x 9 bruno staff 306B 6 aoû 17:39 scripts plex 1.0xx
```
Ejecter:
```bash
bruno@SilverBook:~$ hdiutil eject /Volumes/hubiC/
"disk3" unmounted.
"disk3" ejected.
```
#### Archiver et compresser en même temps (gzip)
Archiver et compresser en gzip: **tar -zcvf**
```bash
root@DiskStation:~ # tar -zcvf archive.tar.gz .bashrc .profile test-dossier/
.bashrc
.profile
test-dossier/
test-dossier/test-copy-scp.txt
root@DiskStation:~ # ls
archive.tar.gz
```
Voir le contenu de l'archive gzip: **tar -ztf**
```bash
root@DiskStation:~ # tar -ztf archive.tar.bz2
```
Décompresser: **tar -xzvf**
```bash
root@DiskStation:~ # tar -xzvf archive.tar.gz
.bashrc
.profile
test-dossier/
test-dossier/test-copy-scp.txt
root@DiskStation:~ # ls -la
drwxr-xr-x 3 root root 4096 Aug 6 07:45 .
drwx—— 8 root root 4096 Aug 6 07:18 ..
-rw-rr 1 root root 953 Aug 5 11:04 .bashrc
-rw-rr 1 root root 497 Aug 5 10:15 .profile
-rw-rr 1 root root 925 Aug 6 07:42 archive.tar.gz
drwxr-xr-x 2 root root 4096 Aug 6 07:04 test-dossier
# décompresser dans un dossier cible
root@DiskStation:~ # tar -xzvf archive.tar.gz -C /tmp/
```
#### Archiver et compresser en même temps (bz2)
Décompresser: **tar -xf (+ v pour mode verbose)**
```bash
root@DS916:/volume1/web/_archives# tar -xf nextcloud-11.0.2.tar.bz2
root@DS916:/volume1/web/_archives# ls -la
total 137156
d---------+ 1 root root 308 Apr 15 16:58 .
d---------+ 1 root root 306 Apr 15 16:57 ..
----------+ 1 bruno users 3045723 Oct 20 07:07 gitlist-0.5.0.tar.gz
drwxr-xr-x 1 nobody 65534 414 Feb 26 20:44 nextcloud
----------+ 1 bruno users 38598274 Apr 15 09:48 nextcloud-11.0.2.tar.bz2
```
#### Extraire un seul fichier d'une archive tar.gz
Extrait le fichier README de l'archive automysqlbackup-v3.0_rc6.tar.gz
```bash
bruno@SilverBook:~/Downloads$ tar --extract --file=automysqlbackup-v3.0_rc6.tar.gz README
```
Extrait le fichier book.enchant.html du dossier php-chunked-xhtml de l'archive php*manual*fr.tar.gz
```bash
bruno@SilverBook:~/Downloads$ tar --extract --file=php_manual_fr.tar.gz php-chunked-xhtml/book.enchant.html
```
Extraire plusieurs fichiers d'archive:
```bash
bruno@SilverBook:~/Downloads$ tar xvf php_manual_fr.tar.gz php-chunked-xhtml/book.enchant.html php-chunked-xhtml/function.mysql-connect.html
```
#### Extraire un seul fichier d'une archive zip
Connaitre la liste des fichiers de l'archive:
```bash
bruno@SilverBook:~/Downloads$ unzip -l zenphoto-zenphoto-1.4.14.zip
```
Extraire des fichiers de l'archive:
```bash
bruno@SilverBook:~/Downloads$ unzip zenphoto-zenphoto-1.4.14.zip zenphoto-zenphoto-1.4.14/zp-core/zp-extensions/zenpage/zenpage.css zenphoto-zenphoto-1.4.14/zp-core/zp-extensions/tinymce4/skins/lightgray/img/anchor.gif
Archive: zenphoto-zenphoto-1.4.14.zip
4c21854e7a7950ec8d9644a959da019d9781d36c
inflating: zenphoto-zenphoto-1.4.14/zp-core/zp-extensions/tinymce4/skins/lightgray/img/anchor.gif
inflating: zenphoto-zenphoto-1.4.14/zp-core/zp-extensions/zenpage/zenpage.css
```