Finding files deep in directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding files deep in directories
# 1  
Old 03-07-2017
Finding files deep in directories

i need to find a portable way to go through multiple directories to find a file.

I've trid something like this:

Code:
find /opt/oracle/diag/*/alert_HH2.log -print

ordinarily, i can run the ls command and it will find it:

Code:
/opt/oracle/diag/*/*/*/*/alert_HH2.log

The problem with this approach is that I have to know how deep the log file is.

there will be instances where I wont know how deep the log file is in a directory.

is there a straightforward way to file a file under however number of subdirectories it may be?


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-07-2017 at 03:44 PM.. Reason: Added ICODE tags.
# 2  
Old 03-07-2017
What's wrong with the find command?
# 3  
Old 03-07-2017
Quote:
Originally Posted by RudiC
What's wrong with the find command?
Code:
# find /opt/oracle/diag/*/alert_HH2.log -print
find: ‘/opt/oracle/diag/*/alert_HH2.log’: No such file or directory
#

the goal is to be able to find a file:

Code:
# ls -ld /opt/oracle/diag/*/*/*/*/alert_DC4WMMH2.log
-rwxr-xr-x 1 oracle oradba 246 Mar  7 14:05 /opt/oracle/diag/rdbms/dc4wmmh/DC4WMMH2/trace/alert_HH2.log
#

without having to specify the
Code:
"/*/*/*/*/"

. Thats because i wont know how deep a file is in a directory all the time.
# 4  
Old 03-07-2017
Hi,

Wouldn't something like this work instead with find ?

find /opt/oracle/diag -type f -name alert_HH2.log -print

This would search through the entire filesystem structure underneath /opt/oracle/diag for a file named alert_HH2.log.
This User Gave Thanks to drysdalk For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding non-existing words in a list of files in a directory and its sub-directories

Hi All, I have a list of words (these are actually a list of database table names separated by comma). Now, I want to find only the non-existing list of words in the *.java files of current directory and/or its sub-directories. Sample list of words:... (8 Replies)
Discussion started by: Bhanu Dhulipudi
8 Replies

2. Programming

Finding duplicate files in two base directories

Hello All, I have got some assignment to complete till this Monday and problem statement is as follow :- Problem :- Find duplicate files (especially .c and .cpp) from two project base directories with following requirement :- 1.Should be extendable to search in multiple base... (4 Replies)
Discussion started by: anand.shah
4 Replies

3. Shell Programming and Scripting

Finding directories with expression

Hi All, I need your help in finding pattern of directories. need to search for all pattern have "mypatern" from base directory folder. example ------- server1 - base directory 100 server1/ab_123456_1/mypattern 100 server1/ab_123456_2/mypattern 200 server1/ab_123457_1/mypattern... (13 Replies)
Discussion started by: lxdorney
13 Replies

4. Shell Programming and Scripting

finding matches between multiple files from different directories

Hi all... Can somebody pls help me with this... I have a directory (dir1) which has many subdirectories(vr001,vr002,vr003..) with each subdir containing similar text file(say ras.txt). I have another directory(dir2) which has again got some subdir(vr001c,vr002c,vr003c..) with each subdir... (0 Replies)
Discussion started by: bramya07
0 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Finding the Files In the Same Name Directories

Hi, In the Unix Box, I have a situation, where there is folder name called "Projects" and in that i have 20 Folders S1,S2,S3...S20. In each of the Folders S1,S2,S3,...S20 , there is a same name folder named "MP". So Now, I want to get all the files in all the "MP" Folders and write all those... (6 Replies)
Discussion started by: Siva Sankar
6 Replies

6. UNIX for Dummies Questions & Answers

Finding size of all directories

Alright so I've tried a couple different things that at first glance, looked like they worked. find . -maxdepth 5 -type d -daystart -mtime 1 | xargs du -h Which seems to ignore the previous commands such as depth and modified time. find .. -maxdepth 2 -type d -daystart -ctime 1 | xargs... (8 Replies)
Discussion started by: Aussiemick
8 Replies

7. Shell Programming and Scripting

Script for parsing directories one level and finding directories older than n days

Hello all, Here's the deal...I have one directory with many subdirs and files. What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file. A script for... (5 Replies)
Discussion started by: ejianu
5 Replies

8. UNIX for Dummies Questions & Answers

finding largest files (not directories)?

hello all. i would like to be able to find the names of all files on a remote machine using ssh. i only want the names of files, not directories so far i'm stuck at "du -a | sort -n" also, is it possible to write them to a file on my machine? i know how to write it to a file on that... (2 Replies)
Discussion started by: user19190989
2 Replies

9. UNIX for Dummies Questions & Answers

Finding executable files in all directories

This is probably very easy but I would like to know a way to list all my files in all my directories that are readable and executable to everyone. I was told to use find or ls and I tried some stuff but couldnt get it to work. I understand that its dangerous to have files with these permissions for... (4 Replies)
Discussion started by: CSGUY
4 Replies

10. UNIX for Dummies Questions & Answers

I need to ls all files in 4-6 deep dirs

I need to print to file , a listing of all files below a certain directory. Example: I need to print to file a listing of all files below the etc dir (including the subdirectories) with their full path. Any ideas on how to do this with one command. Or is this something I need to do on all... (4 Replies)
Discussion started by: gforty
4 Replies
Login or Register to Ask a Question