tags:

views:

216

answers:

8

What is the easiest way to open a txt file whose path has to be found using the shell find command?

For example, let say I want to open a file that I know is (uniquely) named example.txt and which I know is "somewhere I can find it using the shell find command".

What I do currently is this:

I do C-u (universal-argument) then M-! (shell command)

I then enter the find, for example:

find . -iname "example.txt"

Then the full path (which I didn't know previously) appears in the buffer, I cut it, then I hit C-x C-f, I delete what written by default and then paste what I cut before.

This seems a bit long and requires quite a few keystrokes, cut'n'pasting etc.

Is there an easiest way to do the same (without writing a new custom Emacs command)?

+4  A: 

Try out ifind.el

M-x ifind /some/starting/point/example.txt

Will search for example.txt in directories below /some/starting/point.

Trey Jackson
@Trey Jackson: you again! :) Excellent.
Webinator
+6  A: 

Using only built-in functionality, I would:

  • Go to a shell buffer: M-x shell
  • Run my find command.
  • Move the cursor up so that it's on top of the file path that was found.
  • Run the find-file-at-point command: M-x ffap.

I use find-file-at-point often enough that I have it bound to a dedicated key, s-\ (super-backslash).

Sean
+6  A: 
M-x find-name-dired

Enter the dir (defaults to current) and filename (shell globs work too) and you'll get a virtual dired buffer with the results. Go the file you want and hit 'a'

scottfrazer
A: 

If your folder constitutes a "project" - something under a version control or having a root folder marker such as project.el, .dir-locals.el, etc, you can use the find-file-in-project, which in my opinion is an excellent solution to this problem.

Bozhidar Batsov
A: 

M-x find-dired RET

then you have a dired buffer showing your files returned by find. You can use classic dired command to open/move/rename... files and directories.

Jérôme Radix
A: 

M-x locate is the fastest way to find and open a file, esp. if you know the exact filename, in emacs.

krakit
A: 

Also have a look at LocateFilesAnywhere

I happen to use M-x anything-locate

Joseph Gay
A: 

I am surprised that globalff is not mentioned as one of the viable option. Sure it requires locate command but its quite fast and useful when you can't recall the exact name.

Sandeep