Exclude list of files from find

后端 未结 6 1895
北恋
北恋 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:23

    This solution will go through all files (not exactly excluding from the find command), but will produce an output skipping files from a list of exclusions. I found that useful while running a time-consuming command (file /dir -exec md5sum {} \;).

    1. You can create a shell script to handle the skipping logic and run commands on the files found (make it executable with chmod, replace echo with other commands):
        $ cat skip_file.sh
        #!/bin/bash
        found=$(grep "^$1$" files_to_skip.txt)
        if [ -z "$found" ]; then
            # run your command
            echo $1
        fi
    
    1. Create a file with the list of files to skip named files_to_skip.txt (on the dir you are running from).

    2. Then use find using it:

        find /dir -name "*.gz" -exec ./skip_file.sh {} \;
    

提交回复
热议问题