LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-03-2013, 04:55 PM   #1
jim.thornton
Member
 
Registered: May 2007
Posts: 404

Rep: Reputation: 19
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.
 
Old 05-03-2013, 05:23 PM   #2
spiky0011
Senior Member
 
Registered: Jan 2011
Location: PLANET-SPIKE
Distribution: /LFS/Centos6.3/Debian
Posts: 2,171
Blog Entries: 1

Rep: Reputation: 326Reputation: 326Reputation: 326Reputation: 326
Hi

How about find -maxdepth

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

find Pictures -maxdepth 2 -name file

Last edited by spiky0011; 05-03-2013 at 05:31 PM.
 
Old 05-03-2013, 05:56 PM   #3
spiky0011
Senior Member
 
Registered: Jan 2011
Location: PLANET-SPIKE
Distribution: /LFS/Centos6.3/Debian
Posts: 2,171
Blog Entries: 1

Rep: Reputation: 326Reputation: 326Reputation: 326Reputation: 326
Try this

du -h Pictures --max-depth=2

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

Last edited by spiky0011; 05-03-2013 at 06:10 PM.
 
Old 05-04-2013, 08:23 AM   #4
jim.thornton
Member
 
Registered: May 2007
Posts: 404

Original Poster
Rep: Reputation: 19
I knew about max depth, but I really want to show everything that is level 3 or higher. Not a maximum of level 2.
 
Old 05-04-2013, 08:35 AM   #5
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
find and rename files / folders.. need some assistance. Springs Linux - General 4 04-08-2013 09:18 AM
Best applications for girls to find assistance... in foreign cities Novatian Linux - Mobile 4 09-15-2012 01:01 AM
Command Assistance stevo520 Linux - Newbie 2 06-26-2012 06:38 PM
[SOLVED] Command Expansion Assistance hattori.hanzo Programming 1 11-02-2010 02:59 AM
Assistance with 'find -exec cp' shell script dick.swift Linux - Software 6 01-23-2006 11:00 AM


All times are GMT -5. The time now is 09:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration