Tar komandos naudojimas (linux)
Aprašysiu Tar komandos naudojimą (išskleisti archyvą ar supakuoti).
1. Jei norime sukurti archyvą tam tikro aplanko, pvz. /etc/ :
tar -czvf /home/etc-archyvas_20030526.tar.gz /etc/
Dažniausiai naudojami parametrai (en):
-c = create
-f = read to/from the named file (instead of the device /tape)
-t = list contents of .tar file
-r = append to a .tar file
-v = verbose (tells you everything its doing)
-z = compress files (not so useful for minc files)
Kelių aplankų archyvavimas į vieną failą:
tar -cvf failovardas.tar /path/to/file1 /path/to/file2 /path/to/file3
Jei norime, kad archyve nebūtų tam dalykų (aplankų/failų), naudojame parametrą –exclude nurodydami ko neįtraukti,pvz:
tar -cvf failovardas.tar /etc --exclude='/etc/httpd'
Jei norime į arcyvą neįtrauti daugiau aplankų ar failų patogiau naudoti sąrašą, sukuriame exclude.txt
nano exclude.txt
įrašome, tai ko norime neįrraukti į archyvą:
abc xyz *.bak
Išsaugome. Dabar galime įvykdyti tokią komandą:
tar -cvf failovardas.tar /etc -X exclude.txt
2. Išskleisime tar failą:
tar -xvf failas.tar
Kad taupyti vietą naudojamas archyvų suspaudimas: gzip (galune tar.gz), bzip2 (tar.bz2). Kad išskleisti gzip (tar.gz galune) archyvus užtenka pridėti parametrą z:
tar -xzvf failas.tar.gz
Išskleisime tar.bz2 failus pridedami parametrą j:
tar -xjvf failas.tar.bz2
Parametrų paaiškinimas (en):
- -x : Extract a tar ball.
- -v : Verbose output or show progress while extracting files.
- -f : Specify an archive or a tarball filename.
- -j : Decompress and extract the contents of the compressed archive created by bzip2 program (tar.bz2 extension).
- -z : Decompress and extract the contents of the compressed archive created by gzip program (tar.gz extension).
Jei norime iš archyvo išskleisti tik vieną failą, pvz. foo.txt :
tar -xvf failas.tar foo.txt tar -xzvf failas.tar.gz foo.txt tar -xjvf failas.tar.bz2 foo.txt
arba specifinį iš tam tikros direktorijos, pvz. etc/resolv.conf:
tar -xvf failas.tar etc/resolv.conf tar -xzvf failas.tar.gz etc/resolv.conf tar -xjvf failas.tar.bz2 etc/resolv.conf
Jei norime iš archyvo išskleisti tam tikrą vieną aplanką, pvz etc aplanką:
tar -xvf failas.tar etc tar -xzvf failas.tar.gz etc tar -xjvf failas.tar.bz2 etc
Tiek trumpai.