tar

आर्काइव

इस्तेमाल

tar -czf <archive.tar.gz> <path>

फ़ाइलों को एक ही बंडल में बाँधता है पर खुद कुछ छोटा नहीं करता — दबाने का काम `-z` (gzip), `-j` (bzip2) और `-J` (xz) करते हैं; बनाने के `-c`, खोलने के `-x` और सूची के `-t` में से ठीक एक चुनें, और `-f` को सबसे अंतिम फ़्लैग रखें, क्योंकि उसके तुरंत बाद बंडल का नाम आता है।

आम विकल्प

विकल्पअर्थ
-c / -x / -tCreate / extract / list. Exactly one of the three, and it comes first.
-f <file>The archive name, and it must be the last flag before that name.
-z / -j / -Jgzip / bzip2 / xz. GNU tar detects the format when extracting, so -z is optional with -x.
-vPrint the file names as they go past.
-C <dir>Change into that directory first. Position in the command line matters.
--exclude='node_modules'Skip matching paths. Write it before the source paths.
--strip-components=1Drop the top-level directory when extracting.
--zstdUse zstd instead of gzip (GNU tar 1.31 and newer).

उदाहरण

tar -czf site.tar.gz -C /var/www .

Archive the contents of a directory without the leading path.

tar -xzf site.tar.gz -C /tmp/restore

Extract into a directory that already exists.

tar -tzf site.tar.gz | head

Look inside before extracting, so nothing lands in $PWD by surprise.

बाँधना और दबाना अलग काम हैं: tar बाँधता है, gzip छोटा करता है, और .tar.gz दोनों है।

कैसे पढ़ें

  • बड़े कोष्ठक [ ] उस हिस्से को दिखाते हैं जिसे छोड़ा जा सकता है।
  • तीन बिंदु … का मतलब है एक से ज़्यादा दिए जा सकते हैं।
  • विकल्पों में बड़े-छोटे अक्षर मायने रखते हैं — कुछ कमांड में -r और -R अलग काम करते हैं।

आम सवाल

Q. tar क्या करता है?

फ़ाइलों को एक ही बंडल में बाँधता है पर खुद कुछ छोटा नहीं करता — दबाने का काम `-z` (gzip), `-j` (bzip2) और `-J` (xz) करते हैं; बनाने के `-c`, खोलने के `-x` और सूची के `-t` में से ठीक एक चुनें, और `-f` को सबसे अंतिम फ़्लैग रखें, क्योंकि उसके तुरंत बाद बंडल का नाम आता है।

Q. इसे कैसे लिखें?

tar -czf <archive.tar.gz> <path> — बड़े कोष्ठक वह हिस्सा दिखाते हैं जो छोड़ा जा सकता है।

Q. कितने विकल्प जानने लायक़ हैं?

यहाँ 8 दिए हैं; पूरी सूची man tar में है। यह कमांड आर्काइव में आती है।

मिलती-जुलती कमांड

man पेज: man tar