LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-01-2009, 06:13 PM   #1
Mr.mick-duck
Member
 
Registered: Aug 2004
Location: Saudi Arabia
Distribution: Mandrake
Posts: 60

Rep: Reputation: 15
Stop find command after the first file ...


Hi guys..
I am working on a Linux script ...but i face a problem regarding the find command
because i want this command to stop after finding the first file
for example

Code:
find *.mp3
i want the command to stop after first mp3 file founded

any help?

Last edited by Mr.mick-duck; 03-01-2009 at 06:22 PM.
 
Old 03-01-2009, 07:19 PM   #2
AsusDave
Member
 
Registered: Jul 2008
Distribution: Debian, Ubuntu 10.04
Posts: 151

Rep: Reputation: 34
what does
Code:
locate *.mp3 --limit=1
do for you?

This should stop after the first file is located

HTH
Dave
 
Old 03-01-2009, 08:07 PM   #3
Mr.mick-duck
Member
 
Registered: Aug 2004
Location: Saudi Arabia
Distribution: Mandrake
Posts: 60

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by AsusDave View Post
what does
Code:
locate *.mp3 --limit=1
do for you?

This should stop after the first file is located

HTH
Dave
Great can till me please how to assign the result to a certain variable
?

Last edited by Mr.mick-duck; 03-01-2009 at 08:18 PM.
 
Old 03-01-2009, 08:13 PM   #4
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Try an obscure parmeter to find :

Code:
find *.mp3 -print -quit
Should work. To assign to the variable myfiles :

Code:
myfiles=$(find *.mp3 -print -quit)

Last edited by bgeddy; 03-01-2009 at 08:15 PM.
 
Old 03-01-2009, 08:21 PM   #5
Mr.mick-duck
Member
 
Registered: Aug 2004
Location: Saudi Arabia
Distribution: Mandrake
Posts: 60

Original Poster
Rep: Reputation: 15
Thank you I LIKE Liverpool.
and also BIG THANK to AsusDave.
 
Old 03-01-2009, 08:35 PM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You could pipe the output through head -1. When the pipe is broken by head, the find command will be killed.
This would allow you to for example limit the output to 10 files.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find a file using the command line matrix13 Linux - Desktop 4 11-13-2006 11:45 PM
Processing file located using the FIND command PirateJack Linux - Newbie 2 04-04-2006 11:24 AM
Command to find file with text chamanrana Linux - Software 10 12-02-2004 10:47 AM
Command to find out which package contains which file ? javeree Slackware 6 07-10-2004 06:35 PM
Makefile:66: *** Cannot find a kernel config file. Stop NHBlacklabs Linux - Newbie 7 03-25-2004 04:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration