Finding file in specific subdirectories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding file in specific subdirectories
# 1  
Old 06-20-2009
Finding file in specific subdirectories

Hi

experts

problem:

i have a directory "DATA" with lots of subdirectories named as date with hudge data containning files.

Directory = "DATA"
subdirectory = "20090611" & "20090612" ......
20090611 = thousands of files

i wanna apply find command to find all files in subdirectory starting pattren 200906
which also mean i wanna find all files for the month of June.

find . will find all files in all sub directories
# 2  
Old 06-20-2009
have you tried:
Code:
find . -type f -name '200906*'

# 3  
Old 06-20-2009
Code:
find 200906* -type f

will be faster since it only searches in the right directories

Last edited by pbillast; 06-20-2009 at 06:34 PM.. Reason: readability
# 4  
Old 06-20-2009
Assuming only one depth of directories under /DATA and no files with names starting with a full stop.
First find the relevant directories and then list the filenames.
The "2>/dev/null" deals with empty directories.

Code:
#!/bin/ksh
find /DATA -type d -name 200906\* -print | while read DIR
do
          ls -1d "${DIR}"/* 2>/dev/null | while read FILENAME
          do
                 if [ -f "${FILENAME}" ]
                 then
                            ls -1d "${FILENAME}"
                 fi
          done
done


Last edited by methyl; 06-20-2009 at 07:52 PM.. Reason: Belt and braces. Allow for non-files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Finding specific string in file and storing in another file

Text in input file is like this <title> <band height="21" isSplitAllowed="true" > <staticText> <reportElement x="1" y="1" width="313" height="20" key="staticText-1"/> <box></box> <textElement> <font fontName="Arial" pdfFontName="Helvetica-Bold"... (4 Replies)
Discussion started by: aankita30
4 Replies

2. Shell Programming and Scripting

Finding duplicates in a file excluding specific pattern

I have unix file like below >newuser newuser <hello hello newone I want to find the unique values in the file(excluding <,>),so that the out put should be >newuser <hello newone can any body tell me what is command to get this new file. (7 Replies)
Discussion started by: shiva2985
7 Replies

3. Shell Programming and Scripting

Finding 4 current files having specific File Name pattern

Hi All, I am trying to find 4 latest files inside one folder having following File Name pattern and store them into 4 different variables and then use for processing in my shell script. File name is fixed length. 1) Each file starts with = ABCJmdmfbsjop letters + 7 Digit Number... (6 Replies)
Discussion started by: lancesunny
6 Replies

4. Shell Programming and Scripting

finding file with a specific range

Hi All, Thanks in advance File is generated with following format 31000000.xml to 48999999.xml 74000000.xml to 88999999.xml Above range should be find and moved into the folder named abc and below is another range should should be find and moved into folder named xyz ... (1 Reply)
Discussion started by: sujit_kashyap
1 Replies

5. UNIX for Advanced & Expert Users

Finding a specific range of character in file

hi, I want to store from 102 character to 128 character to a variable of header record which can be identified as 'HDR' which is the first 3 characters in the same line of a same.txt file. Please advise. Thanks (4 Replies)
Discussion started by: techmoris
4 Replies

6. Shell Programming and Scripting

add newline in file after finding specific text

Hi All, I am tring to insert a newline with "/" in a text file whenever there is the text "end;" right now I have inside file: . . end; I want to have: . . end; / I tried doing the following within the file :g/^end;/s//end; \/ / (4 Replies)
Discussion started by: jxh461
4 Replies

7. Shell Programming and Scripting

Finding what pages link to a specific file

First time poster (so please excuse me in advance) ;) I have a webserver running linux, apache, etc. I have a list of HTML webpages that I want to delete because I think they are old. While I could delete them then check for broken links, I'd like to be more pro-active. I want to write a... (2 Replies)
Discussion started by: iansocool
2 Replies

8. UNIX for Dummies Questions & Answers

Finding files in subdirectories from one location

Using ssh, is there a simple command to find files in subdirectories from, let's say, the home directory on a shared server? (2 Replies)
Discussion started by: endl
2 Replies

9. UNIX for Advanced & Expert Users

tar subdirectories for specific files

I have a sample directory structire like following # pwd /user/test and I have files like following out.txt A/a.txt B/b.txt C/c.txt (A,B,C are directories ) # tar cvf test.tar * a A/a.txt 1 blocks a B/b.txt 1 blocks a C/c.txt 1 blocks a out.txt 1 blocks But whenever I give (4 Replies)
Discussion started by: ronald_brayan
4 Replies

10. UNIX for Dummies Questions & Answers

finding specific values in a within a file

Hi everyone, Can anyone guide me on how to search through a huge file and look on specific column and if it finds a discrepancy on that column that does not conform to the specified criteria, ie (1) Numeric and (3) alpha chars F123 or G333..etc, etc! then idientify it and redirect... (3 Replies)
Discussion started by: Gerry405
3 Replies
Login or Register to Ask a Question