18 Mapuslanon nga Tar Command Ehemplo alang sa Matag Linux Sysadmin
Ang Linux tar nagpasabut sa tape archive, nga gigamit sa daghang mga administrador sa sistema sa Linux/Unix aron atubangon ang backup sa tape drive.
Ang tar command gigamit sa pag-rip sa usa ka koleksyon sa mga file ug mga direktoryo ngadto sa usa ka highly compressed archive file nga sagad gitawag nga tarball o tar, gzip ug bzip sa Linux.
Ang tar mao ang labing kaylap nga gigamit nga sugo sa paghimo og mga compressed archive nga mga file ug sayon nga mabalhin gikan sa usa ka disk ngadto sa laing disk o makina ngadto sa makina.
Niini nga artikulo, atong hisgotan ug hisgotan ang lainlaing mga pananglitan sa tar command lakip na kung giunsa paghimo ang mga file sa archive gamit ang (tar, tar.gz, ug tar.bz2) compression, kung giunsa pagkuha ang file sa archive, pagkuha usa ka file, pagtan-aw sa sulud sa file, pamatud-i ang usa ka file, idugang ang mga file o mga direktoryo sa kasamtangan nga archive file, banabanaa ang gidak-on sa tar archive file, ug uban pa.
[ Tingali ganahan ka usab: 7-Zip - I-compress ug I-uncompress ang mga File nga adunay Taas nga Compression Ratio]
Ang nag-unang katuyoan niini nga giya mao ang paghatag og lain-laing mga tar command nga mga pananglitan nga makatabang kanimo nga masabtan ug mahimong eksperto sa tar archive manipulation.
Ang ubos nga pananglitan nga sugo maghimo ug tar archive file tecmint-14-09-12.tar para sa direktoryo /home/tecmint sa kasamtangang working directory. Tan-awa ang pananglitan nga sugo sa aksyon.
# tar -cvf tecmint-14-09-12.tar /home/tecmint/ /home/tecmint/ /home/tecmint/cleanfiles.sh /home/tecmint/openvpn-2.1.4.tar.gz /home/tecmint/tecmint-14-09-12.tar /home/tecmint/phpmyadmin-2.11.11.3-1.el5.rf.noarch.rpm /home/tecmint/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
Hisgutan nato ang matag opsyon nga gigamit sa sugo sa ibabaw sa paghimo og tar archive file.
- c – Naghimo ug bag-ong .tar archive file.
- v – Lisod ipakita ang .tar file nga pag-uswag.
- f – Uri sa ngalan sa file sa archive file.
Aron makahimo og compressed gzip archive file among gigamit ang opsyon isip z. Pananglitan, ang ubos nga sugo maghimo ug compressed MyImages-14-09-12.tar.gz file para sa direktoryo /home/MyImages. (Note: tar.gz ug tgz parehas ra).
# tar cvzf MyImages-14-09-12.tar.gz /home/MyImages OR # tar cvzf MyImages-14-09-12.tgz /home/MyImages /home/MyImages/ /home/MyImages/Sara-Khan-and-model-Priyanka-Shah.jpg /home/MyImages/RobertKristenviolent101201.jpg /home/MyImages/Justintimerlake101125.jpg /home/MyImages/Mileyphoto101203.jpg /home/MyImages/JenniferRobert101130.jpg /home/MyImages/katrinabarbiedoll231110.jpg /home/MyImages/the-japanese-wife-press-conference.jpg /home/MyImages/ReesewitherspoonCIA101202.jpg /home/MyImages/yanaguptabaresf231110.jpg
Ang bz2 nga feature nag-compress ug nagmugna og archive file nga ubos pa sa gidak-on sa gzip. Ang bz2 compression nagkinahanglag daghang oras sa pag-compress ug pag-decompress sa mga file kaysa sa gzip, nga gamay ra ang oras.
Aron makamugna og usa ka highly compressed tar file among gigamit ang opsyon nga j. Ang mosunod nga pananglitan nga sugo maghimo ug Phpfiles-org.tar.bz2 file para sa direktoryo /home/php. (Note: tar.bz2 ug tbz susama sa tb2).
# tar cvfj Phpfiles-org.tar.bz2 /home/php OR # tar cvfj Phpfiles-org.tar.tbz /home/php OR # tar cvfj Phpfiles-org.tar.tb2 /home/php /home/php/ /home/php/iframe_ew.php /home/php/videos_all.php /home/php/rss.php /home/php/index.php /home/php/vendor.php /home/php/video_title.php /home/php/report.php /home/php/object.html /home/php/video.php
Sa pag-untar o pagkuha sa usa ka tar file, i-isyu lang ang mosunod nga command gamit ang option x (extract). Pananglitan, ang ubos nga sugo mag-untar sa file public_html-14-09-12.tar sa kasamtangan nga working directory.
Kung gusto nimo nga untar sa usa ka lahi nga direktoryo unya gamita ang kapilian ingon -C (specified directory).
## Untar files in Current Directory ## # tar -xvf public_html-14-09-12.tar ## Untar files in specified Directory ## # tar -xvf public_html-14-09-12.tar -C /home/public_html/videos/ /home/public_html/videos/ /home/public_html/videos/views.php /home/public_html/videos/index.php /home/public_html/videos/logout.php /home/public_html/videos/all_categories.php /home/public_html/videos/feeds.xml
Sa Uncompress tar.gz archive file, padagana lang ang mosunod nga command. Kung gusto namon nga untar sa lainlaing mga direktoryo, gamita lang ang kapilian -C ug ang agianan sa direktoryo, ingon sa gipakita sa pananglitan sa ibabaw.
# tar -xvf thumbnails-14-09-12.tar.gz /home/public_html/videos/thumbnails/ /home/public_html/videos/thumbnails/katdeepika231110.jpg /home/public_html/videos/thumbnails/katrinabarbiedoll231110.jpg /home/public_html/videos/thumbnails/onceuponatime101125.jpg /home/public_html/videos/thumbnails/playbutton.png /home/public_html/videos/thumbnails/ReesewitherspoonCIA101202.jpg /home/public_html/videos/thumbnails/snagItNarration.jpg /home/public_html/videos/thumbnails/Minissha-Lamba.jpg /home/public_html/videos/thumbnails/Lindsaydance101201.jpg /home/public_html/videos/thumbnails/Mileyphoto101203.jpg
Para Uncompress ang highly compressed tar.bz2 file, gamita lang ang mosunod nga command. Ang ubos nga panig-ingnan nga sugo magwagtang sa tanang .flv files gikan sa archive file.
# tar -xvf videos-14-09-12.tar.bz2 /home/public_html/videos/flv/katrinabarbiedoll231110.flv /home/public_html/videos/flv/BrookmuellerCIA101125.flv /home/public_html/videos/flv/dollybackinbb4101125.flv /home/public_html/videos/flv/JenniferRobert101130.flv /home/public_html/videos/flv/JustinAwardmovie101125.flv /home/public_html/videos/flv/Lakme-Fashion-Week.flv /home/public_html/videos/flv/Mileyphoto101203.flv /home/public_html/videos/flv/Minissha-Lamba.flv
Aron ilista ang mga sulod sa tar archive file, padagana lang ang mosunod nga command nga adunay opsyon t (listahan ang sulod). Ang ubos nga sugo maglista sa sulod sa uploadprogress.tar file.
# tar -tvf uploadprogress.tar -rw-r--r-- chregu/staff 2276 2011-08-15 18:51:10 package2.xml -rw-r--r-- chregu/staff 7877 2011-08-15 18:51:10 uploadprogress/examples/index.php -rw-r--r-- chregu/staff 1685 2011-08-15 18:51:10 uploadprogress/examples/server.php -rw-r--r-- chregu/staff 1697 2011-08-15 18:51:10 uploadprogress/examples/info.php -rw-r--r-- chregu/staff 367 2011-08-15 18:51:10 uploadprogress/config.m4 -rw-r--r-- chregu/staff 303 2011-08-15 18:51:10 uploadprogress/config.w32 -rw-r--r-- chregu/staff 3563 2011-08-15 18:51:10 uploadprogress/php_uploadprogress.h -rw-r--r-- chregu/staff 15433 2011-08-15 18:51:10 uploadprogress/uploadprogress.c -rw-r--r-- chregu/staff 1433 2011-08-15 18:51:10 package.xml
Gamita ang mosunod nga sugo aron ilista ang sulod sa tar.gz file.
# tar -tvf staging.linux-console.net.tar.gz -rw-r--r-- root/root 0 2012-08-30 04:03:57 staging.linux-console.net-access_log -rw-r--r-- root/root 587 2012-08-29 18:35:12 staging.linux-console.net-access_log.1 -rw-r--r-- root/root 156 2012-01-21 07:17:56 staging.linux-console.net-access_log.2 -rw-r--r-- root/root 156 2011-12-21 11:30:56 staging.linux-console.net-access_log.3 -rw-r--r-- root/root 156 2011-11-20 17:28:24 staging.linux-console.net-access_log.4 -rw-r--r-- root/root 0 2012-08-30 04:03:57 staging.linux-console.net-error_log -rw-r--r-- root/root 3981 2012-08-29 18:35:12 staging.linux-console.net-error_log.1 -rw-r--r-- root/root 211 2012-01-21 07:17:56 staging.linux-console.net-error_log.2 -rw-r--r-- root/root 211 2011-12-21 11:30:56 staging.linux-console.net-error_log.3 -rw-r--r-- root/root 211 2011-11-20 17:28:24 staging.linux-console.net-error_log.4
Aron ilista ang sulod sa tar.bz2 file, i-isyu ang mosunod nga sugo.
# tar -tvf Phpfiles-org.tar.bz2 drwxr-xr-x root/root 0 2012-09-15 03:06:08 /home/php/ -rw-r--r-- root/root 1751 2012-09-15 03:06:08 /home/php/iframe_ew.php -rw-r--r-- root/root 11220 2012-09-15 03:06:08 /home/php/videos_all.php -rw-r--r-- root/root 2152 2012-09-15 03:06:08 /home/php/rss.php -rw-r--r-- root/root 3021 2012-09-15 03:06:08 /home/php/index.php -rw-r--r-- root/root 2554 2012-09-15 03:06:08 /home/php/vendor.php -rw-r--r-- root/root 406 2012-09-15 03:06:08 /home/php/video_title.php -rw-r--r-- root/root 4116 2012-09-15 03:06:08 /home/php/report.php -rw-r--r-- root/root 1273 2012-09-15 03:06:08 /home/php/object.html
Aron makuha ang usa ka file nga gitawag cleanfiles.sh gikan sa cleanfiles.sh.tar gamita ang mosunod nga sugo.
# tar -xvf cleanfiles.sh.tar cleanfiles.sh OR # tar --extract --file=cleanfiles.sh.tar cleanfiles.sh cleanfiles.sh
Aron makuha ang usa ka file nga tecmintbackup.xml gikan sa tecmintbackup.tar.gz archive file, gamita ang mando ingon sa mosunod.
# tar -zxvf tecmintbackup.tar.gz tecmintbackup.xml OR # tar --extract --file=tecmintbackup.tar.gz tecmintbackup.xml tecmintbackup.xml
Aron makuha ang usa ka file nga gitawag og index.php gikan sa file Phpfiles-org.tar.bz2 gamita ang mosunod nga opsyon.
# tar -jxvf Phpfiles-org.tar.bz2 home/php/index.php OR # tar --extract --file=Phpfiles-org.tar.bz2 /home/php/index.php /home/php/index.php
Aron makuha o i-untar ang daghang mga file gikan sa tar, tar.gz, ug tar.bz2 archive file. Pananglitan, ang ubos nga sugo magkuha sa file 1 file 2 gikan sa mga file sa archive.
# tar -xvf tecmint-14-09-12.tar "file1" "file2" # tar -zxvf MyImages-14-09-12.tar.gz "file1" "file2" # tar -jxvf Phpfiles-org.tar.bz2 "file1" "file2"
Aron makuha ang grupo sa mga file among gigamit ang wildcard-based pagkuha. Pananglitan, aron makuha ang usa ka grupo sa tanan nga mga file kansang pattern nagsugod sa .php gikan sa tar, tar.gz, ug tar.bz2 archive file.
# tar -xvf Phpfiles-org.tar --wildcards '*.php' # tar -zxvf Phpfiles-org.tar.gz --wildcards '*.php' # tar -jxvf Phpfiles-org.tar.bz2 --wildcards '*.php' /home/php/iframe_ew.php /home/php/videos_all.php /home/php/rss.php /home/php/index.php /home/php/vendor.php /home/php/video_title.php /home/php/report.php /home/php/video.php
Aron makadugang sa mga file o mga direktoryo sa kasamtangan nga mga file sa tar archive atong gamiton ang opsyon r (idugang). Pananglitan, atong idugang ang file nga xyz.txt ug directory php sa kasamtangan nga tecmint-14-09-12.tar archive file.
# tar -rvf tecmint-14-09-12.tar xyz.txt # tar -rvf tecmint-14-09-12.tar php drwxr-xr-x root/root 0 2012-09-15 02:24:21 home/tecmint/ -rw-r--r-- root/root 15740615 2012-09-15 02:23:42 home/tecmint/cleanfiles.sh -rw-r--r-- root/root 863726 2012-09-15 02:23:41 home/tecmint/openvpn-2.1.4.tar.gz -rw-r--r-- root/root 21063680 2012-09-15 02:24:21 home/tecmint/tecmint-14-09-12.tar -rw-r--r-- root/root 4437600 2012-09-15 02:23:41 home/tecmint/phpmyadmin-2.11.11.3-1.el5.rf.noarch.rpm -rw-r--r-- root/root 12680 2012-09-15 02:23:41 home/tecmint/rpmforge-release-0.5.2-2.el5.rf.i386.rpm -rw-r--r-- root/root 0 2012-08-18 19:11:04 xyz.txt drwxr-xr-x root/root 0 2012-09-15 03:06:08 php/ -rw-r--r-- root/root 1751 2012-09-15 03:06:08 php/iframe_ew.php -rw-r--r-- root/root 11220 2012-09-15 03:06:08 php/videos_all.php -rw-r--r-- root/root 2152 2012-09-15 03:06:08 php/rss.php -rw-r--r-- root/root 3021 2012-09-15 03:06:08 php/index.php -rw-r--r-- root/root 2554 2012-09-15 03:06:08 php/vendor.php -rw-r--r-- root/root 406 2012-09-15 03:06:08 php/video_title.php
Ang tar command walay kapilian sa pagdugang sa mga file o mga direktoryo sa usa ka kasamtangan nga compressed tar.gz ug tar.bz2 archive file. Kung atong sulayan makuha ang mosunod nga sayup.
# tar -rvf MyImages-14-09-12.tar.gz xyz.txt # tar -rvf Phpfiles-org.tar.bz2 xyz.txt tar: This does not look like a tar archive tar: Skipping to next header xyz.txt tar: Error exit delayed from previous errors
Aron mapamatud-an ang bisan unsang tar o compressed archive file among gigamit ang opsyon nga W (verify). Aron mahimo kini, gamita lang ang mosunod nga mga pananglitan sa mga sugo. (Pahinumdom: Dili nimo mahimo ang pag-verify sa usa ka compressed ( *.tar.gz, *.tar.bz2) archive file).
# tar tvfW tecmint-14-09-12.tar tar: This does not look like a tar archive tar: Skipping to next header tar: Archive contains obsolescent base-64 headers tar: VERIFY FAILURE: 30740 invalid headers detected Verify -rw-r--r-- root/root 863726 2012-09-15 02:23:41 /home/tecmint/openvpn-2.1.4.tar.gz Verify -rw-r--r-- root/root 21063680 2012-09-15 02:24:21 /home/tecmint/tecmint-14-09-12.tar tar: /home/tecmint/tecmint-14-09-12.tar: Warning: Cannot stat: No such file or directory Verify -rw-r--r-- root/root 4437600 2012-09-15 02:23:41 home/tecmint/phpmyadmin-2.11.11.3-1.el5.rf.noarch.rpm tar: /home/tecmint/phpmyadmin-2.11.11.3-1.el5.rf.noarch.rpm: Warning: Cannot stat: No such file or directory Verify -rw-r--r-- root/root 12680 2012-09-15 02:23:41 home/tecmint/rpmforge-release-0.5.2-2.el5.rf.i386.rpm tar: /home/tecmint/rpmforge-release-0.5.2-2.el5.rf.i386.rpm: Warning: Cannot stat: No such file or directory Verify -rw-r--r-- root/root 0 2012-08-18 19:11:04 xyz.txt Verify drwxr-xr-x root/root 0 2012-09-15 03:06:08 php/
Aron masusi ang gidak-on sa bisan unsang tar, tar.gz, ug tar.bz2 archive file, gamita ang mosunod nga sugo. Pananglitan, ang ubos nga sugo magpakita sa gidak-on sa archive file sa Kilobytes (KB).
# tar -czf - tecmint-14-09-12.tar | wc -c 12820480 # tar -czf - MyImages-14-09-12.tar.gz | wc -c 112640 # tar -czf - Phpfiles-org.tar.bz2 | wc -c 20480
- c – paghimo og archive file.
- x – pagkuha ug archive file.
- v – ipakita ang pag-uswag sa archive file.
- f – ngalan sa file sa archive file.
- t – pagtan-aw sa sulod sa archive file.
- j – filter archive pinaagi sa bzip2.
- z – filter archive pinaagi sa gzip.
- r – idugang o i-update ang mga file o mga direktoryo sa anaa na nga mga file sa archive.
- W – I-verify ang usa ka archive file.
- wildcards – Ipiho ang mga pattern sa UNIX tar command.
Mao na kini sa pagkakaron, hinaut nga ang mga pananglitan sa tar command sa ibabaw igo na aron makat-on ka, ug alang sa dugang impormasyon palihug gamita ang man tar command.
Kung nangita ka nga bahinon ang bisan unsang dako nga file sa tar archive sa daghang mga bahin o bloke, adto lang kini nga artikulo:
- Unsaon Pagbahin sa Tar File Ngadto sa Daghang mga File sa Piho nga Gidak-on
- Unsaon Pag-download ug Pagkuha sa mga Tar File gamit ang Usa ka Sugo
Kung napakyas kami sa bisan unsang mga pananglitan palihug ipaambit kanamo pinaagi sa kahon sa komento ug palihug ayaw kalimti nga ipaambit kini nga artikulo sa imong mga higala. Kini ang pinakamaayong paagi sa pagpasalamat....