tags:

views:

81

answers:

2

Hi,
How can I list the output of this command
ls -ltDR `find . -maxdepth 4 -type f -name "*.org"`
within dired-buffer. The above command lists all org files sorted by access time.

Thanks,
Sandeep

+2  A: 

You want to use M-x find-dired, with a custom value for the find-ls-option variable.

find-dired:

find-dired is an interactive compiled Lisp function in `find-dired.el'.

(find-dired DIR ARGS)

Run find and go into Dired mode on a buffer of the output. The command run (after changing into DIR) is

find . \( ARGS \) -ls

except that the variable `find-ls-option' specifies what to use as the final argument.

find-ls-option:

find-ls-option is a variable defined in `find-dired.el'. Its value is

("-exec ls -ld {} \\;" . "-ld")

Documentation: Description of the option to find to produce an ls -l-type listing. This is a cons of two strings (FIND-OPTION . LS-SWITCHES). FIND-OPTION gives the option (or options) to find that produce the desired output. LS-SWITCHES is a list of ls switches to tell dired how to parse the output.

phils
Two questions: How do I go into dired-mode on any buffer. There isn't any dired-mode command. Second the output of find . -exec ls -ltu {} \; isn't the same as the command listed above. So I don't think I can use find-dired for the purpose.Thanks Sandeep
Sandeep
Hey Sandeep, check my answer, it orders by access time. Your command line above isn't valid.
justinhj
+1  A: 

First open dired buffer using M-x dired

Sorting by access time in dired buffer

You can change the sort command used to order the dired buffer.

To sort by access time...

C-u s

this will bring up a minibuffer and you type -lutR

The R will make dired recurse subdirectories

Showing only .org files

Following info from this thread here works:

http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/acb20ee78c00e4ec#

(Andreas Politz)

Here is one way :

  1. Mark all files you want to see with `%m'
  2. Expression you need for .org files is ..org
  3. Inverse the marks via `*t'
  4. Invoke dired-do-kill-lines' withk'
  5. When done, Reset the listing with `g'

Wrapped up in a function :

(defun dired-show-only (regexp) 
  (interactive "sFiles to show (regexp): ") 
  (dired-mark-files-regexp regexp) 
  (dired-toggle-marks) 
  (dired-do-kill-lines)) 

(define-key dired-mode-map [?%?h] 'dired-show-only) 
justinhj
Hi Justin, Thanks for taking a look. I am afraid I didn't quite catch your solution. For example ~/*.org doesn't list org files in subdirectories. I can see s s will sort files but I don't know how to change the search type to -lutR. I can use find-dired to list all org files. But I can't sort them because the sort expression happens to be "find . -name "*.org" -exec ls -l<flags> {} \;" which isn't the same as "ls -lutR `find . -name *.org " Essentially the previous command doesn't sort by access time at all. -Sandeep
Sandeep
In my post above I say that s can change the sort, but you need to do C-u s to change the sort type. Try it and it will pop up a prompt for you.
justinhj
Hi Justin, Its lot clearer now. Thanks so much. I learned some new tricks along the way as well. But I am afraid I can not still make it work. The reason being that I cannot list/mark all org files recursively with %m. I tried find-dired method to list the files. But emacs refuses to sort the buffer of find-dired. -Thanks Sandeep
Sandeep
Hi SandeepWhat you do is open dired buffer, then change the sort method to -lutR first, as the R is what lists the directories recursivelyNow you should be looking at all the files in the directory and its subdirectoriesIt's at this stage you mark all the .org files
justinhj
Hi Justin, The above should work. But the issue is that I just have too many directories and files to list them all first and then mark the org files. The org files are themselves very few. Would have been better to list only the org first and then sort only those.But I do appreciate you looking so closely into this. It was fun to figure this one out.-Sandeep
Sandeep