Shell Script — Get all files modified after

前端 未结 9 2485
礼貌的吻别
礼貌的吻别 2020-12-12 09:57

I\'d rather not do this in PHP so I\'m hoping a someone decent at shell scripting can help.

I need a script that runs through directory recursively and finds all fil

相关标签:
9条回答
  • 2020-12-12 10:32

    This will work for some number of files. You want to include "-print0" and "xargs -0" in case any of the paths have spaces in them. This example looks for files modified in the last 7 days. To find those modified before the last 7 days, use "+7".

    find . -mtime -7 -print0 | xargs -0 tar -cjf /foo/archive.tar.bz2
    

    As this page warns, xargs can cause the tar command to be executed multiple times if there are a lot of arguments, and the "-c" flag could cause problems. In that case, you would want this:

    find . -mtime -7 -print0 | xargs -0 tar -rf /foo/archive.tar
    

    You can't update a zipped tar archive with tar, so you would have to bzip2 or gzip it in a second step.

    0 讨论(0)
  • 2020-12-12 10:34

    well under linux try reading man page of the find command

    man find
    

    something like this should

     find . -type f -mtime -7 -print -exec cat {} \; | tar cf - | gzip -9
    

    and you have it

    0 讨论(0)
  • 2020-12-12 10:38

    This should show all files modified within the last 7 days.

    find . -type f -mtime -7 -print
    

    Pipe that into tar/zip, and you should be good.

    0 讨论(0)
提交回复
热议问题