개발 창고/Server

[CentOS] How to use tar

로이제로 2024. 4. 2. 07:29
반응형


TOC is not supported in this version (ex.Mobile)


 Windows and Macs are often compressed with zip, but Linux often downloads files compressed with tar or tar.gz.

 

 By default, package management is possible in apt/yum, etc., but what should I do if I want to compress the files I downloaded myself or the files I have now? The very answer is tar (there are of course gzip and other utilities)

 

 First of all, you should know that tar is a bundle command, not a compression command. Remember that there is a compression option when you tie it, not just by writing a tar.


Compress (Common)

tar -cvf [filename.tar] [foldername]

 

ex)

$> tar -cvf targetFolder.tar targetFolder

 → compress from targetFolder to targetFolder.tar

 

Try following me

make targetFolder

 If you create a target folder temporarily as follows and look it up, you can see that the target folder has been created as follows.

the result of being made

 And then,

$> tar -cvf targetFolder.tar targetFolder

 when you call this command

execute compress

 The console window calls for compressed targetFolder/ (if there is content inside, the compressed content is listed)

 And then,

 

$ ls -alt

 

 You can see the made a compressed file

the result of being made


Decompress (tar)

 tar -xvf [filename.tar]

 

ex)

$> tar -xvf targetFolder.tar

 → decompress from targetFolder.tar to current folder

 

Try following me

 First, to delete the target folder at the parent folder

$> rm -ivfr targetFolder

 And then,

$> ls -alt

 If you do, you can see that only targetFolder.tar remains as shown below and the targetFolder has been deleted.

the result of being deleted

 In this state, you can execute below command

$> tar -xvf targetFolder.tar

 

 You can see that the decompressed content (only targetFolder/ because there are no files in the folder at this time) is displayed.

 When you executed below command, you can see the decompressed file

$> ls -alt

the result of being decompressed


Compress (gzip)

tar -zcvf [filename.tar.gz] [foldername]

 

 The difference from tar is simple in terms of the difference that you write z in front of the option cvf.


Decompress (gzip)

 tar -zxvf [filename.tar.gz]

 

 The difference from tar is simple in terms of the difference that you write z in front of the option cvf.


Manual Page

 Details of the options are available on the manual page. (The command is available from the root permission.)

man tar

Options for tar seen as manual

 

 Among them, the most common ones I just used are compression (zcvf) and decompression (zxvf), and the options are as follows.

 

z: gzip (ex extension is gz) when you want to compress or decompress a compressed file

c: If you want to compress

x: If you want to decompress

v: Show the contents of the file in the console window when compressing/decompressing (why it is exposed as /targetFolder when executing the top command)

f: Specify a file name


[CentOS] How to use tar

 

🇰🇷 Korean

2020.08.04 - [개발 창고/Server] - [CentOS] 압축관련 Util, tar

 

[CentOS] 압축관련 Util, tar

윈도우나 맥에서는 주로 zip으로 압축된 경우가 많지만, 리눅스에서는 tar 또는 tar.gz로 압축된 파일을 다운로드하는 경우가 많습니다. 기본적으로 apt/yum 등에서 패키지 관리가 가능하지만, 직접

royzero.tistory.com

반응형