find files not in a list

后端 未结 2 1554
故里飘歌
故里飘歌 2021-02-04 03:29

I have a list of files in file.lst. Now I want to find all files in a directory dir which are older than 7 days, except those in the file.lst

2条回答
  •  灰色年华
    2021-02-04 03:47

    Pipe your find command through grep -Fxvf:

    find -mtime +7 -print | grep -Fxvf file.lst
    

    What the flags mean:

    -F, --fixed-strings
                  Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.    
    -x, --line-regexp
                  Select only those matches that exactly match the whole line.
    -v, --invert-match
                  Invert the sense of matching, to select non-matching lines.
    -f FILE, --file=FILE
                  Obtain patterns from FILE, one per line.  The empty file contains zero patterns, and therefore matches nothing.
    

提交回复
热议问题