Find examples

From lippmann wiki
Revision as of 20:31, 30 August 2013 by Maarten (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 we filter for folders only with the -type d in what is left.