How to search in specific directory using find?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to search in specific directory using find?
# 1  
Old 12-02-2014
How to search in specific directory using find?

Hi,
Is there any way to use find command and search only specific subdirectories in a directory.
for example
Code:
/home/d1
/home/d2
/home/d3

i want to search in the following directories
Code:
/home
/home/d1
/home/d2

i do not want the find command to search the /home/d3 directory.

Last edited by vbe; 12-02-2014 at 01:55 PM.. Reason: code tags not icode!
# 2  
Old 12-02-2014
What about /home/d2/subfolder/...?

Is your system Linux?
# 3  
Old 12-02-2014
The general way of excluding (all!) d3 directories is
Code:
find /home -type d -name d3 -prune -o -print

GNU find (Linux) can be told to only prune the search at /home/d3
Code:
find /home -type d -path /home/d3 -prune -o -print

You can replace -print by other actions.
# 4  
Old 12-02-2014
Yes its linux ubuntu 14.04

---------- Post updated 12-03-14 at 12:06 AM ---------- Previous update was 12-02-14 at 11:46 PM ----------

Quote:
Originally Posted by MadeInGermany
The general way of excluding (all!) d3 directories is
Code:
find /home -type d -name d3 -prune -o -print

GNU find (Linux) can be told to only prune the search at /home/d3
Code:
find /home -type d -path /home/d3 -prune -o -print

You can replace -print by other actions.
I want to search for a particular file say f1 in
/home
/home/d1
/home/d2

excluding /home/d3

In the above example you gave, where should i specify the filename?
# 5  
Old 12-02-2014
Since you apparently don't want recursion, that's simpler without find...

Code:
FILES=$(ls /home/d1/f1 /home/d2/f1 /home/f1)

# 6  
Old 12-02-2014
Regarding find, the 1st part up to the -o is the exclusion. So you must put your tests to the 2nd part
Code:
find /home -type d -path /home/d3 -prune -o -type f -name f1 -print

Meaning: if type is file and if name is f1 then print.
# 7  
Old 12-02-2014
You need two finds in parentheses, one for /home -depth 1 and one for /home/d[12].
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find Large Files Recursively From Specific Directory

Hi. I found many scripts in the web of achieving this. But I like to use this one find /EDWH-DMT03 -xdev -size +10000 -exec ls -la {} \;|sort -n -k 5 > LARGE.rst But the problem is, why it still list out files with 89 bytes as the output? Is there anything wrong with the command? My... (7 Replies)
Discussion started by: aimy
7 Replies

2. Shell Programming and Scripting

Find specific files only in current directory...not sub directories AIX

Hi, I have to find specific files only in the current directory...not in the sub directories. But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help.. I am using the below command. And i am... (2 Replies)
Discussion started by: aakishore
2 Replies

3. Shell Programming and Scripting

Find all the files under a specific directory and zip them into a single file.

Hi, Is there a way to find all the files from a specific location and then zip them into a single file, even if they are in multiple directories? (3 Replies)
Discussion started by: rudoraj
3 Replies

4. UNIX for Dummies Questions & Answers

How to search directory for specific file?

I am new to Unix scripting and would like some help. Here is my scenario: 1) I have a text files that contains two fields: file name and retention period in months: File1 36 file2 24 File3 12 2) The directory I am searching contains sequential files. 3) I need to be able to take the file name... (10 Replies)
Discussion started by: Mustafa19804
10 Replies

5. UNIX for Advanced & Expert Users

Recursive directory search using ls instead of find

I was working on a shell script and found that the find command took too long, especially when I had to execute it multiple times. After some thought and research I came up with two functions. fileScan() filescan will cd into a directory and perform any operations you would like from within... (8 Replies)
Discussion started by: newreverie
8 Replies

6. Shell Programming and Scripting

Find files of specific size excluding search in a subdirectory

Hi All, I was exploring find command and came across -prune option which would exclude search in a mention subdirectory. My quesry is to search all files more that 100 MB size but exclude search in a subdirectory. I am using below command,but somehow it is not working. Can anybody help me... (6 Replies)
Discussion started by: usha rao
6 Replies

7. UNIX for Dummies Questions & Answers

How to search all the files in a directory for a specific string

Hi Guys, I want to search the content of all the files (of a particular type like .txt) in a directory for a specific string pattern. Can anyone help me? Thanks (7 Replies)
Discussion started by: mwrg
7 Replies

8. Shell Programming and Scripting

Search for a file in specific directory

I have to search a file in a prticular directory. filename will be passed through command line. The directory may contain subdirectory. i.e. suppose directory in /u03/appl (it can hard coded in script). This directory may contain subdirectory. $ scriptname.sh filename output should be... (2 Replies)
Discussion started by: jadoo_c2
2 Replies

9. UNIX for Dummies Questions & Answers

Linux shortcutkey to search specific file from a list of directory?!

Hi, I'm the new user of linux/unix. Can I ask that anybody know how to use the linux/unix shortcut key to search a specific file from a list of directory? For example, I know the file name that I want to search. But I forget which directory or location is my desired file put.Got any shortcut... (7 Replies)
Discussion started by: patrick87
7 Replies

10. Shell Programming and Scripting

How to find a specific files in a many directory

Dear All, Appreciate some help here. I have a log of report. It located in several directory as below: Directory: mysscpr1 mysscpr2 mysscpr3 my_scnpr4 In the directory it contain hundred of files. i need to find a specific files that contain 'invc2345' in the directory. How... (7 Replies)
Discussion started by: selamba_warrior
7 Replies
Login or Register to Ask a Question