LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-22-2010, 05:06 AM   #1
gleipnir
LQ Newbie
 
Registered: Feb 2010
Location: Santa Monica, CA
Distribution: Darwin 10.5
Posts: 2

Rep: Reputation: 0
find and -exec {}


I'm trying to pull the first result from the set when performing a search. If running this command in OS X, it'll search the Downloads directory for pdf files & open all the results w/ the default app:

$ find ~/Downloads -type f -name '*.pdf' -exec open {} \;

And lets say it returns & opens these three:
AboutDownloads.pdf
PluginUsage.pdf
UISlider_Class.pdf

Now, how do I open the first result (AboutDownloads.pdf) only, any one thereafter (PluginUsage.pdf), or a range of them (AboutDownloads.pdf & PluginUsage.pdf)?


Suggestions much appreciated!
 
Old 02-22-2010, 05:45 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Jessie (Fluxbox WM)
Posts: 1,387
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
You could use '-ok' instead of '-exec' so that it prompts you before opening them (ie, it becomes interactive).

If you add '-quit' at the end, it will only open the first match and then exit.
 
Old 02-23-2010, 02:08 AM   #3
gleipnir
LQ Newbie
 
Registered: Feb 2010
Location: Santa Monica, CA
Distribution: Darwin 10.5
Posts: 2

Original Poster
Rep: Reputation: 0
Awesome! That'll do, thank for the response.
 
Old 02-23-2010, 02:48 AM   #4
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
Quote:
Originally Posted by neonsignal View Post
You could use '-ok' instead of '-exec' so that it prompts you before opening them (ie, it becomes interactive).

If you add '-quit' at the end, it will only open the first match and then exit.
A serious issue I am facing if i try to open a file this way

Code:
find . -type f -name "*.text" -ok vim {} \;
< vim ... ./newfile.text > ? y
Vim: Warning: Input is not from a terminal
< vim ... ./new.text > ? [vinay@linuxcoe4 ~]$ [vinay@linuxcoe4 ~]$
File will open, but the terminal will be hanged. I faced the same issue when i tried with -exec.

why am I getting this wierd errorVim: Warning: Input is not from a terminal ?
 
Old 02-23-2010, 03:35 AM   #5
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Jessie (Fluxbox WM)
Posts: 1,387
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
It is because it is being started in a subshell without a terminal. You can either run the GUI version of vim (gvim), or do something like this with xterm:
Code:
find . -type f -name "*.text" -ok xterm -e vim "{}" \;
Also, if you put quotes around the {}, it will be able to handle filenames that have spaces in them.

Last edited by neonsignal; 02-23-2010 at 03:38 AM.
 
Old 02-23-2010, 04:08 AM   #6
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
Thanks neonsignal
It worked.
Quote:
It is because it is being started in a subshell without a terminal
Sorry, I could not understand above statement properly. Could you please elaborate it ?

Also, then how come this is working nicely. Does working of ls differs from vim in terms of subshell ?
Code:
[vinay@linuxcoe4 ~]$ find . -type f -name "*.text" -ok ls -l "{}" \;
< ls ... ./newfile.text > ? y
-rw-r--r-- 1 vinay vinay 36 Feb 22 16:01 ./newfile.text
< ls ... ./new.text > ? y
-rw-rw-r-- 1 vinay vinay 195 Feb 22 14:10 ./new.text
[vinay@linuxcoe4 ~]$

Last edited by vinaytp; 02-23-2010 at 04:12 AM.
 
Old 02-23-2010, 06:22 PM   #7
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Jessie (Fluxbox WM)
Posts: 1,387
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Because vim is interactive, it requires a terminal for input, unlike ls.
 
  


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
Find with -exec argument - not giving proper output..how to find... hinetvenkat Linux - Server 4 01-25-2010 07:19 AM
Use of find & exec andrew_26 Linux - Newbie 2 08-26-2009 07:15 PM
find -exec syntax: bug in find? mfcarroll Programming 5 06-21-2007 08:13 PM
find -exec help dc144 Linux - Newbie 3 10-12-2006 03:14 AM
find -exec cricbk Linux - Newbie 4 01-05-2004 08:03 PM


All times are GMT -5. The time now is 07:14 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration