Find examples: Difference between revisions

From lippmann wiki
Jump to navigation Jump to search
(Created page with "==Excluding directories from a find query== For my work I regularly have to investigate how deep directory structures go. Some storage vendors like NetApp have default snapsh...")
 
Line 8: Line 8:
(-name .snapshot -prune) means, once you find .snapshot, don't descend into it. This makes sure that any files inside the .snapshot dir that would not be called .snapshot themselves (but hourly_blablabla) are skipped from the find listing/query.
(-name .snapshot -prune) means, once you find .snapshot, don't descend into it. This makes sure that any files inside the .snapshot dir that would not be called .snapshot themselves (but hourly_blablabla) are skipped from the find listing/query.


Then this entire area (the .snapshot dir, and everything that's inside it) is flagged as a negative match with the -not. After that we filter for folders only with the -type d in what is left.
Then this entire area (the .snapshot dir, and everything that's inside it) is flagged as a negative match with the -not. After that, if needed we can filter for folders only by adding  -type d .

Revision as of 17:30, 20 June 2015

Excluding directories from a find query

For my work I regularly have to investigate how deep directory structures go. Some storage vendors like NetApp have default snapshot directories that allow you to access older revisions of files. When I do a query for the depth of a filesystem diretory tree, I don't want to include these hidden .snapshot directories. A quick command to list all directories, excluding the ones in the .snapshot dir is the command below:

find . -print -not \( -name .snapshot -prune \)

Let me explain

(-name .snapshot -prune) means, once you find .snapshot, don't descend into it. This makes sure that any files inside the .snapshot dir that would not be called .snapshot themselves (but hourly_blablabla) are skipped from the find listing/query.

Then this entire area (the .snapshot dir, and everything that's inside it) is flagged as a negative match with the -not. After that, if needed we can filter for folders only by adding -type d .