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

后端 未结 5 1530
孤独总比滥情好
孤独总比滥情好 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:22

    Just use the null-byte as delimiter when you write file / directory names to file. This way you need not worry about spaces, newlines, etc. in file names!

    printf "%s\000" */ > listOfDirs.txt    # alternative: find ... -print0 
    
    while IFS="" read -r -d '' dir; do command ls -1abd "$dir"; done < listOfDirs.txt
    
    tar --null -czvf mytar.tar.gz --files-from listOfDirs.txt 
    

提交回复
热议问题