MoonPoint Support Logo


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals

Advanced Search
Sun Mon Tue Wed Thu Fri Sat

Tue, Apr 12, 2016 11:18 pm

Excluding certain directories when using the find command

If I want to find all files with an HTML extension beneath the current directory and its subdirectories, but skip one directory, on a Linux system, I can perform a recursive search using the following command, which will exclude the contents of the directory named "private" which is directly below the current directory. The results will be placed in a file named htmlfiles.txt.

$ find . -path ./private -prune -o -name '*.html' -print > htmlfiles.txt

The period immediately after the find, i.e., find . tells find to start its search from the current directory from which the command is being executed; I could use something like find /somedir to start the search in a different directory.

The -path ./private -prune -o tells find that for the directory path that is ./private - the dot (.) represents the current directory, so the path is the private directory below the current directory - don't include it in the search, i.e., "prune" that directory from the search path. Including -prune indicates, if the file is a directory, do not descend into it. But it is the "dash o", i.e., -o which ensures that nothing is printed from within that directory.

[ More Info ]

[/os/unix/commands] permanent link

Once You Know, You Newegg AliExpress by

Shop Amazon Local - Subscribe to Deals in Your Neighborhood

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo