Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Say I have a file in some obscure directory that I want to open and edit. I don't want to do something like this...
Code:
vim ~/foo/bar/blah/doh/ugh.txt
I'd rather be able to say find this file and open it. I know there are commands like locate and find to find a file or directory, but I'm not sure whether these can (or even should) be utilized in what I'm trying to do. Basically, what is the simplest way to open a file with a program w/o specifying its exact location? (In cases where there isn't another file with the same name in the entire system, and cases where there are multiple).
if the file is unique locate should work just fine.
Code:
vim $(locate unique_name)
Beware: vim will typically create a backupfile "unique_name~" which
your locate will also find. Make sure you specify a proper filter
for the locate search, e.g.,
Code:
vim $(locate -r 'unique_name$')
Cheers,
Tink
Last edited by Tinkster; 06-15-2010 at 01:56 PM.
Reason: added e.g. part
There isn't a good way. What if there are multiple files with that name? That being said if you don't mind only getting the first one you could do something like...
Code:
'vim $(locate filename.txt | head -1)
alternately if its a file you frequently edit you could make an alias for editing it
Also, if you are worried about possible multiple return, you can issue the '-o' option and it will open all found.
Of course if the number is large it may look a little silly as you may only have one or so lines of each file.
I suppose you could do something like make an alias to a for loop... for a single return it would edit first instance, then next, etc... but that would suck if you were a bit ambiguous.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.