Here’s another nice trick using Dired. I sometimes want to make an update to a blog post a few days or even weeks after I published it. I have no problem finding the title of the post, if I need to, because I can just search for some keywords and get a list of likely posts. The problem comes when I want to find the original Org file for the post. The file name is only loosely related to the title of the post. For example, this post’s source file is search-blog.org
. So even though I have the title of the post it can be hard to find the right source file.
Here’s one way to do that. I can open a Dired buffer in my org/blog
directory and use 【* .】 to mark all the org files. Then I can search through those files by using dired-do-search
, which is bound to 【A】, to do a regular expression search for the title. If I were searching for this post I would use the regular expression
TITLE:[ ]+Searching For Blog Posts With Dired
(here’s a screenshot of a typical post’s org file). That will search all the marked files for the title and pop the target org file up in a new buffer ready for editing. Using TITLE:
in the regular expression avoids matching a reference to the target post in some other post. When I’m done, I can unmark the files in the Dired buffer with 【Meta+Delete】.
Here’s a slightly easier way. Use 【Ctrl+x d】 to open a Dired buffer but instead of accepting the current directory type *.org
(or ~/org/blog/*.org
if the current directory isn’t org/blog
). That will populate the Dired buffer with just the files you want. Then type 【t】 to mark those files and search for the title as before. When you’re done, just use 【Ctrl+x k】 to get rid of the Dired buffer.
Not everyone needs to find blog post titles, of course, but this little trick is useful for searching a set of files for anything that can be specified with a regular expression. Because dired-do-search
is a variant of a Tags Search, you can use 【Meta+,】 to search for the next occurrence of the match. Searching a set of marked files is just another example of the power of Dired.