gzipping up a set of directories and creating a tar compressed file

后端 未结 5 1515
孤独总比滥情好
孤独总比滥情好 2020-12-29 07:26

My bash fu is not what it should be.

I want to create a little batch script which will copy a list of directories into a new zip file.

There are (at least) t

5条回答
  •  粉色の甜心
    2020-12-29 08:13

    You can create a gzipped tar on the commandline as follows:

    tar czvf mytar.tar.gz dir1 dir2 .. dirN
    

    If you wanted to do that in a bash script and pass the directories as arguments to the script, those arguments would end up in $@. So then you have:

    tar czvf mytar.tar.gz "$@"
    

    If that is in a script (lets say myscript.sh), you would call that as:

    ./myscript.sh dir1 dir2 .. dirN
    

    If you want to read from a list (your option 1) you could do that like so (this does not work if there is whitespace in directory names):

    tar czvf mytar.tar.gz $(

提交回复
热议问题