LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Stop find command after the first file ... (https://www.linuxquestions.org/questions/programming-9/stop-find-command-after-the-first-file-708460/)

Mr.mick-duck 03-01-2009 06:13 PM

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?

AsusDave 03-01-2009 07:19 PM

what does
Code:

locate *.mp3 --limit=1
do for you?

This should stop after the first file is located

HTH
Dave

Mr.mick-duck 03-01-2009 08:07 PM

Quote:

Originally Posted by AsusDave (Post 3461819)
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
?

bgeddy 03-01-2009 08:13 PM

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)

Mr.mick-duck 03-01-2009 08:21 PM

Thank you I LIKE Liverpool.
and also BIG THANK to AsusDave.

jschiwal 03-01-2009 08:35 PM

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.


All times are GMT -5. The time now is 12:41 AM.