Simple Find


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple Find
# 1  
Old 12-17-2008
Java Simple Find

Hi All,

i ahve to find a file "pattern*", from current directory to all its sub directories.
i have tried with this

find . -name "customer*"
but here it displayed files with that name only from current directory, not from all its sub directories.
i want a list of files with matched patterns recursively-sub directories;.

i have issued this also
find $HOME -depth -name "*customer*.scr" -type f | more
here also it displayed only files in home directory alone. not sub-directories...
and if it is a big output list, so i used more - more doesn't effect here.
please guide me.

Last edited by Arunprasad; 12-17-2008 at 06:19 AM..
# 2  
Old 12-17-2008
$ find /home/$USER/* -name "*customer*.scr" | more
# 3  
Old 12-18-2008
dkcl,

its still searching in home directory ony.
its not giving me the file list which resides in sub directories.

please suggest me.
# 4  
Old 12-18-2008
Very strange because find is recursive per default.

Code:
root@isau02:/data/tmp/testfeld> tree
.
|-- bla.pl
|-- dir
|   |-- bla
|   |-- blaa
|   |-- blaaa
|   |-- subdir1
|   |   |-- lala
|   |   |-- lalaa
|   |   |-- lalaaa
|   |   `-- me
|   `-- subdir2
|       |-- me
|       |-- nana
|       |-- nanaa
|       `-- nanaaa
|-- infile
`-- me

3 directories, 14 files
root@isau02:/data/tmp/testfeld> find . -type f -name me -print
./me
./dir/subdir1/me
./dir/subdir2/me

# 5  
Old 12-18-2008
Use this

find /your/directory -name "customer*" -exec ls -lrt '{}' \; -print
# 6  
Old 12-18-2008
In principle your first version of the command is correct. I would add a "-print" clause, because this is not implied on all systems, but that is not contributing to your problem.

Quote:
Originally Posted by Arunprasad
find . -name "customer*"
find $HOME -depth -name "*customer*.scr" -type f | more
You might notice, that the filemask in your first and second example differ: the first one will find only files whose name start with "customer", the second one finds files with "customer" anywhere in the name, but ending in ".scr". It might be that there is only one file in either case that matches this particular pattern. Try

Code:
find . -name "*customer*" -print

and see if this gives you more hits.

If this is not the case: could you please tell us the name and version of your OS? I encountered a similar problem once in AIX 5.1, which turned out to be a bug. It is described here.

I hope this helps.

bakunin
# 7  
Old 12-18-2008
FIND command help

Hi I am new to scripting , need some clarification while assigning the output of 'FIND' command to a variable.

i.e. I am trying to find a file in a directory (I know it exists) and then wish to assign the file_name to a variable say 'file'

Now this is how my shell looks .

${i} # variable for storing file name
for i in `find ${FTP_DIR}/RTM/Outbound -type f -name '*file_name*' -print`;
do cp $i ${TGT_DIR};
done;

Above command works fine (i.e. copies file 'file_name' from RTM/Outbound to TGT_DIR).

Now I wish to store this name of the file to a variable say 'x' so that I can
further work on it.

I wrote the following command for getting the file name from TGT_DIR

${v}
v=`find ${TGT_DIR} -type f -name 'file_name' -printf %f`
echo ${v}

I encounter a error :
find: bad option -printf
find: path-list predicate-list
v=
+ echo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with simple script to find PID of process

Hi everyone. I've been reading around and am a little bit overwhelmed, hoping to find a kind soul out there to hold my hand through writing my first script. This need has emerged at work and I haven't much experience writing shell scripts, but this is a problem we have with a production environment... (13 Replies)
Discussion started by: thirdcoaster
13 Replies

2. Shell Programming and Scripting

Simple script to find common strings in two files

Hi , I want to write a simple script. I have two files file1: BCSpeciality Backend CB CBAPQualDisp CBCimsVFTRCK CBDSNQualDisp CBDefault CBDisney CBFaxMCGen CBMCGeneral CBMCQualDisp file2: CSpeciality Backend (8 Replies)
Discussion started by: ramky79
8 Replies

3. UNIX for Dummies Questions & Answers

Relatively simple question regarding find and cmin

Nuts and bolts: I have a log file that should be updated once every minute called OD_MEM.log. I want to add a check to my CheckSystem script that confirms that the log has been written to in the last 2 minutes. If I use the find command with cmin 1, it finds the file every time. If I use the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

4. Shell Programming and Scripting

Simple find and replace with AWK

I am trying to write a find and replace script with AWK and I can't seem to get it to work. I need it to find this exact string *P*: and replace the P with a T or just replcare the whole thing with *T*:. this is what I have tried awk 'BEGIN {gsub(/\*P*:/,"\*T*:"); print}' ${INFILE} >... (4 Replies)
Discussion started by: wbshrk
4 Replies

5. Shell Programming and Scripting

Simple shell script to find and print data

Hi, I have a log file containing data on emails sent. Looks a bit like this for one email: Content-Type: text/plain; charset="UTF-8" Date: 12 Jun 2008 14:04:59 +0100 From: from@email.com Subject: xcf4564xzcv To: recip@email.co.uk Size = 364 Jun 12 14:04 smtp_234sldfh.tmp I need to... (5 Replies)
Discussion started by: terry2009
5 Replies

6. Shell Programming and Scripting

Simple Find file Script.....

Im trying to make a very simple find the first file with the .zip extension in a specific folder and open that file. The folder path and file name will vary every-time and it may contain spaces. If I try to look For this example the folder directory is /Users/username/Desktop/testfolder/abc... (6 Replies)
Discussion started by: elbombillo
6 Replies

7. Shell Programming and Scripting

simple script detect to find OS version/flavour

Hi, A newbie question. Following script gives no output. =============================== root@srv # cat /etc/redhat-release | awk {'print $1}' Red root@srv # cat 123.sh if (( `cat /etc/redhat-release | awk {'print $1}'` != CentOS )); then { echo "System runs on Redhat Linux. ... (13 Replies)
Discussion started by: fed.linuxgossip
13 Replies

8. Shell Programming and Scripting

A simple find and replace without using any regex (bash)

Hi, I need to do an exact find and replace (I don't want to use regular expressions because the input comes from user). I want to find a line that matches the user's input text and replace it with an empty string. For example, let's say the user enters I love "Unix" and the contents of the... (2 Replies)
Discussion started by: srikanths
2 Replies

9. UNIX for Dummies Questions & Answers

Stuck with a simple find problem

Hi, Need some simple find help. I need to search for all .so files within sol directory. My directory tree has mix of directories and i want to search only inside sol directory. I could get this done combining find with for, any option to do this with find alone. for a in `find .... (13 Replies)
Discussion started by: vibhor_agarwali
13 Replies

10. UNIX for Dummies Questions & Answers

Is a simple one command to find a file?

Hi All, I have did a search in the whole forum about Find, but get too many results, so I hope my message not annoying anyone. How do I do a find for a specific file in the whole machine? I am hoping for something like this. find . -name thanks (11 Replies)
Discussion started by: E-Quality
11 Replies
Login or Register to Ask a Question