How to extract a single file / directory from tar archive

Posted In Shell - By Tum. On Wednesday, December 12th, 2012 With 0 Comments

tar extract single filename and directoryการ extract บาง file หรือบาง directory ออกจาก tarball บน UNIX หรือ Linux สามารถทำได้โดยไม่ต้องทำการ extract file หรือ directory ออกจาก tar ทั้งหมดก่อน ซึ่งจะช่วยเพิ่มความสะดวกและประหยัดเนื่อที่เมื่อมีการ extract file หรือ directory

วิธีการ extract บาง file หรือบาง directory ออกจาก tar สามารถทำได้ดังนี้

  1. ตรวจสอบก่อนว่ามี file หรือ directory ที่ต้องการอยู่ใน tar หรือไม่ด้วยคำสั่ง
  2. เมื่อตรวจสอบแล้วว่ามี file หรือ directory ที่ต้องการอยู่ใน tar ให้ใช้คำสั่ง

    โดยที่ path-filename และ path-directory-name คือ path ของ file หรือ directory โดยสามารถหาได้จากคำสั่งแรก

ข้อควรระวัง
ถ้าหากใส่ path-filename และ path-directory-name ผิดจะไม่สามารถ extract file หรือ directory ออกมาได้ ดังนั้นจึงควรตรวจสอบให้แน่ใจก่อน

Tips
ถ้าหากต้องการ extract บาง file หรือบาง directory ไปยัง path ที่ต้องการสามารถทำได้โดยเพิ่ม -C และตามด้วย path ที่ต้องการเข้าไป เช่น
ต้องการ extract บาง file หรือบาง directory ไปยัง /tmp สามารถรันคำสั่งได้ดังนี้

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

*