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

前端 未结 3 671
小蘑菇
小蘑菇 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:00

    @amitchhajer 's post works for GNU tar. If someone finds this post and needs it to work on a NON GNU system, they can do this:

    tar cvf - folderToCompress | gzip > compressFileName
    

    To expand the archive:

    zcat compressFileName | tar xvf -
    
    0 讨论(0)
  • 2021-01-29 18:05
    tar -zcvf compressFileName.tar.gz folderToCompress
    

    everything in folderToCompress will go to compressFileName

    Edit: After review and comments I realized that people may get confused with compressFileName without an extension. If you want you can use .tar.gz extension(as suggested) with the compressFileName

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题