Find command - First file only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find command - First file only
# 1  
Old 04-23-2008
Find command - First file only

How can I use the find command to list only first file that matches the name

for example

dir/dir1/file1
dir/dir2/file1
dir/dir3/dir4/file1

find dir -name file1

I just want to print

dir/dir1/file1


Thanks
# 2  
Old 04-23-2008
Quote:
Originally Posted by neeto
How can I use the find command to list only first file that matches the name

for example

dir/dir1/file1
dir/dir2/file1
dir/dir3/dir4/file1

find dir -name file1

I just want to print

dir/dir1/file1


Thanks
Try find dir -name file1 | head -1
# 3  
Old 03-16-2009
Solution

In unix ,
$ls filename_*.txt | head -1
This User Gave Thanks to raghav525 For This Post:
# 4  
Old 03-17-2009
find / -name name*.txt | head -1


i hope this will give you the proper output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

wanted to find both link file and ordinary file using single find command

find . -type fl o/p is only the ordinary file. where in it wont give the link files. (2 Replies)
Discussion started by: nikhil jain
2 Replies

2. Shell Programming and Scripting

find specific file names and execute a command depending on file's name

Hi, As a newbie, I'm desperate ro make my shell script work. I'd like a script which checks all the files in a directory, check the file name, if the file name ends with "extracted", store it in a variable, if it has a suffix of ".roi" stores in another variable. I'm going to use these two... (3 Replies)
Discussion started by: armando110
3 Replies

3. Shell Programming and Scripting

Find multiple string in one file using find command

Hi, I want find multiple string in one file using find coomand. And keeping it in one variable.grep is not working. (5 Replies)
Discussion started by: vivek1489
5 Replies

4. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

5. Linux

Simplified find command to find multiple file types

Hi, I'm using the following command to find the multiple requierd file types and its working fine find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f Though... (2 Replies)
Discussion started by: vickramshetty
2 Replies

6. Shell Programming and Scripting

how to use find command to get latest file

Is there a way to use find command to get the latest file and cp it into a certain dir at the same try. example find the latest file and cp to a diff dir. (5 Replies)
Discussion started by: shehzad_m
5 Replies

7. UNIX for Dummies Questions & Answers

how to find a file named vijay in a directory using find command

I need to find whether there is a file named vijay is there or not in folder named "opt" .I tried "ls *|grep vijay" but it showed permission problem. so i need to use find command (6 Replies)
Discussion started by: amirthraj_12
6 Replies

8. UNIX for Advanced & Expert Users

get file name from find command

how can i get the find command to display the filename without the path. example: find /tmp/test /tmp/test1 /tmp/test2 /tmp/test3 should return test1 test2 test3 i'm using bash. also, whats the best way to ignore the . and .. directories? (5 Replies)
Discussion started by: kuliksco
5 Replies

9. UNIX for Advanced & Expert Users

How to use the command Tar to find a file

Hello, I am just using the command Tar to find if a file was backuped on my tape. Can you help me with that command. I am using the command : tar -tvf /dev/rmt/4m /kcc_dms/AC7/c15a* > toto.txt to find all files c15a* in these subdirectories on my tape. But it doesn't work correctly. Can... (2 Replies)
Discussion started by: steiner
2 Replies

10. Shell Programming and Scripting

how to find a file in UNIX without find command?

given a start directory,a filename,how to find it? (3 Replies)
Discussion started by: bluo
3 Replies
Login or Register to Ask a Question