find files not in a list

后端 未结 2 1550
故里飘歌
故里飘歌 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 04:00

    Pipe the find-command to grep using the -v and -f switches

    find -mtime +7 -print | grep -vf file.lst > found.lst
    

    grep options:

    -v : invert the match
    -f file: - obtains patterns from FILE, one per line
    

    example:

    $ ls
    a  b  c  d  file.lst
    
    $ cat file.lst 
    a$
    b$
    c$
    
    
    $ find . | grep -vf file.lst 
    .
    ./file.lst
    ./d
    

提交回复
热议问题