LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need some assistance with the find command (https://www.linuxquestions.org/questions/linux-newbie-8/need-some-assistance-with-the-find-command-4175460617/)

jim.thornton 05-03-2013 03:55 PM

Need some assistance with the find command
 
I would like to search through a hierarchy of directories and display all directories that DON'T contain a certain file structure. Is this possible to do with just the find command or will I have to create a script to do it?

In addition, I would like to search through the same hierarchy and find any directories that are only 3 levels deep. For example:

root
- home
+- username
++- Pictures
+++- folder1
++++- folder2

So, let's say I wanted to search the Pictures directory. folder1 is okay, folder2 is okay but I don't want any directories any deeper than that. So, I would like to find any directory that is folder3 or deeper and list it so that I can go through and manually sort my pictures.

spiky0011 05-03-2013 04:23 PM

Hi

How about find -maxdepth

http://www.linux.com/learn/tutorials...using-gnu-find

find Pictures -maxdepth 2 -name file

spiky0011 05-03-2013 04:56 PM

Try this

du -h Pictures --max-depth=2

find Pictures -maxdepth 2 -exec ls -ld {} \;

jim.thornton 05-04-2013 07:23 AM

I knew about max depth, but I really want to show everything that is level 3 or higher. Not a maximum of level 2.

shivaa 05-04-2013 07:35 AM

All you need is find cmd. Just go through it's manual page: http://linux.die.net/man/1/find and it has all answers.

Search according to files hierarchy:
Quote:

-maxdepth levels
Descend at most levels (a non-negative integer) levels of directories below the command line arguments. -maxdepth 0 means only apply the tests and actions to the command line arguments.
-mindepth levels
Do not apply any tests or actions at levels less than levels (a non-negative integer). -mindepth 1 means process all files except the command line arguments.

To exclude certain pattern:
Quote:

! expr
True if expr is false. This character will also usually need protection from interpretation by the shell.

-not expr
Same as ! expr, but not POSIX compliant.



All times are GMT -5. The time now is 11:54 AM.