Exclude list of files from find

后端 未结 6 1892
北恋
北恋 2021-01-31 07:43

If I have a list of filenames in a text file that I want to exclude when I run find, how can I do that? For example, I want to do something like:

fi         


        
6条回答
  •  无人及你
    2021-01-31 08:26

    I don't think find has an option like this, you could build a command using printf and your exclude list:

    find /dir -name "*.gz" $(printf "! -name %s " $(cat skip_files))
    

    Which is the same as doing:

    find /dir -name "*.gz" ! -name first_skip ! -name second_skip .... etc
    

    Alternatively you can pipe from find into grep:

    find /dir -name "*.gz" | grep -vFf skip_files
    

提交回复
热议问题