How to gzip all files in all sub-directories into one compressed file in bash

前端 未结 3 684
小蘑菇
小蘑菇 2021-01-29 17:36

Possible Duplicate:
gzipping up a set of directories and creating a tar compressed file

This post describes how t

3条回答
  •  不知归路
    2021-01-29 18:11

    there are lots of compression methods that work recursively command line and its good to know who the end audience is.

    i.e. if it is to be sent to someone running windows then zip would probably be best:

    zip -r file.zip folder_to_zip
    
    unzip filenname.zip
    

    for other linux users or your self tar is great

    tar -cvzf filename.tar.gz folder
    
    tar -cvjf filename.tar.bz2 folder  # even more compression
    
    #change the -c to -x to above to extract
    

    One must be careful with tar and how things are tarred up/extracted, for example if I run

    cd ~
    tar -cvzf passwd.tar.gz /etc/passwd
    tar: Removing leading `/' from member names
    /etc/passwd
    
    
    pwd
    

    /home/myusername

    tar -xvzf passwd.tar.gz
    

    this will create /home/myusername/etc/passwd

    unsure if all versions of tar do this:

     Removing leading `/' from member names
    

提交回复
热议问题