Find files and tar them (with spaces)

后端 未结 10 1842
北海茫月
北海茫月 2020-11-29 15:35

Alright, so simple problem here. I\'m working on a simple back up code. It works fine except if the files have spaces in them. This is how I\'m finding files and adding th

10条回答
  •  执念已碎
    2020-11-29 16:36

    Use this:

    find . -type f -print0 | tar -czvf backup.tar.gz --null -T -
    

    It will:

    • deal with files with spaces, newlines, leading dashes, and other funniness
    • handle an unlimited number of files
    • won't repeatedly overwrite your backup.tar.gz like using tar -c with xargs will do when you have a large number of files

    Also see:

    • GNU tar manual
    • How can I build a tar from stdin?, search for null

提交回复
热议问题