Let's say I have a directory containing a number of subdirectories, each with a number of files in them. I wish to check which of these directories do not contain a specific file. For example, if these are my directories:
dir/A:
foo
bar
dir/B:
bar
dir/C:
foo
dir/D:
dir/E:
foo
bar
If I wanted to list all directories not containing foo
, I would get:
dir/B
dir/D
Is it possible to do this with unix find
, or do I need to use some alternate tool?
To exclude multiple directories, OR them between parentheses. And, to exclude directories with a specific name at any level, use the -name primary instead of -path .
To exclude specific files, in the Files text box, type the file names and paths to exclude, separated by commas. For example, C:\windows\system32\filename. dll. You can include question mark and asterisk wildcards.
Adding -ls or -exec ls -l {} \; would make it like ls -l without directories.
Prune usage:$ find . -prune . The find command works like this: It starts finding files from the path provided in the command which in this case is the current directory(.). From here, it traverses through all the files in the entire tree and prints those files matching the criteria specified.
I found a good solution after a bit more research:
find . -type d \! -exec test -e '{}/foo' \; -print
Where you replace foo
with whatever file you're looking for.
This will print out a list of all directories that don't contain whatever file you're looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With