While considering some refactoring, I made changes throughout a project.

Halfway through the changes, and before saving, I found it doesn't quite work. I exited emacs and restarted. (That's probably not the right approach. There must be some kind of "ignore-all-changes-done-so-far" command I'm missing.)

Regardless, I now have many filename.ext that are left with a trail of #filename.ext#.

I recursively insert directories in dired-mode starting from the project root, and flag (%-d) all files of the regexp ^#.*#$ for deletion.

This expression only captures the files at the root of the hierarchy. Why, and how can I modify it to also catch all files inside the hierarchy?


By way of comparison, marking (or flagging) all files of the pattern ^.*\.js$ does indeed catch all files, in both the root and in recursive directories. So why is ^#.*#$ not good?

  • There is a function diredp-mark-files-regexp-recursive in the package dired+.
    – Tobias
    Dec 18, 2017 at 17:27

1 Answer 1


I think you are asking how to flag all files whose names look like auto-save files—that is, files whose names begin and end with #.

In Dired (including vanilla Dired and Dired+), the key # does exactly that.

C-h k # says:

# runs the command dired-flag-auto-save-files, which is an interactive compiled Lisp function in dired.el.

It is bound to #, menu-bar mark mark-flag marks-flag-auto-save-files.

(dired-flag-auto-save-files &optional UNFLAG-P)

Flag for deletion files whose names suggest they are auto save files.

A prefix argument says to unmark or unflag those files instead.

See also the Emacs manual, node Flagging Many Files.

You can also find this command as menu-item Flag Auto-save Files in menu-bar menu Mark. (In Dired+ this menu item is in menu Marks, submenu Flag.)

As for the question why regexp ^#.*#$ does not work (used with %d or %m, for example) in inserted subdirectories: It's because for subdirectories the full file name is picked up, i.e., including the directory part.

You can use regexp ^.*/?#.*#$ to do what you want for all #...# files in the current Dired buffer, i.e., including all inserted subdirs.

  • That does solve the problem, though understanding the reason why the regex is incorrect would also be nice. I guess hunting in the code for what pressing '#' in Dired does will reveal the correct regexp, and then it will be a matter of understanding why the two do not capture the same set.
    – Calaf
    Dec 18, 2017 at 18:00
  • I've updated the answer to address this.
    – Drew
    Dec 18, 2017 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.