More efficient way to find & tar millions of files

前端 未结 9 602
一向
一向 2021-01-30 17:53

I\'ve got a job running on my server at the command line prompt for a two days now:

find data/ -name filepattern-*2009* -exec tar uf 2009.tar {} ;
9条回答
  •  臣服心动
    2021-01-30 18:40

    Here's a find-tar combination that can do what you want without the use of xargs or exec (which should result in a noticeable speed-up):

    tar --version    # tar (GNU tar) 1.14 
    
    # FreeBSD find (on Mac OS X)
    find -x data -name "filepattern-*2009*" -print0 | tar --null --no-recursion -uf 2009.tar --files-from -
    
    # for GNU find use -xdev instead of -x
    gfind data -xdev -name "filepattern-*2009*" -print0 | tar --null --no-recursion -uf 2009.tar --files-from -
    
    # added: set permissions via tar
    find -x data -name "filepattern-*2009*" -print0 | \
        tar --null --no-recursion --owner=... --group=... --mode=... -uf 2009.tar --files-from -
    

提交回复
热议问题