lk/basics/archives.md

59 lines
1.1 KiB
Markdown
Raw Normal View History

2020-01-02 00:04:35 +00:00
# Tar Archives
2020-01-10 04:19:29 +00:00
*C*reate *z*e *f*iles!
2020-01-02 00:04:35 +00:00
> tar czf file.tar.gz file1 file2
2020-01-10 04:19:29 +00:00
E*x*tract *z*e *f*iles:
2020-01-02 00:04:35 +00:00
> tar xzf file.tar.gz
The .tar extension means two or more files are bundled together into a single file. The .tar.gz means compression.
Tarballs come with a number of arguments.
2020-01-10 04:19:29 +00:00
## More Compression
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
Extremely compressed files take longer to compress, but take up less disk space.
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
> tar cfj super-compressed.tar.bz2 file1 file2
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
# ssh backup
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
Back up an unmounted partition with ssh:
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
> sudo dd if=/dev/sda1 | ssh -C ghost@192.168.0.10 "dd of=/home/ghost/backup.img" status=progress
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
# `xz`
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
Install `xz`.
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
Unzip the image with:
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
> unxz void.img.xz
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
This then deletes the .xz file. To keep it:
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
> unxz --keep void.img.xz
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
# `zip`
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
Zip file1-3, and make a zip file called 'newsip.zip'.
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
> zip newsip file1 file2 file3
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
# Automatic Backups with `find`
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
## `tar`
2020-01-05 12:33:53 +00:00
2020-01-10 04:19:29 +00:00
Compressing all Latex Files in /home/.
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
> sudo find ~ -maxdepth 4 -name "*.txt" | xargs tar cvf latex-bundle.tar.gz
2020-01-02 00:04:35 +00:00
2020-11-15 20:49:17 +00:00
## `zip`
2020-01-02 00:04:35 +00:00
2020-01-10 04:19:29 +00:00
Install `zip`.
> find /home/"$(whoami)" -type f -size -2M | xargs zip -u backup
2020-01-02 00:04:35 +00:00