In a dired buffer of a directory, how do I copy the file names of all files matching [tT]ypolog[yi]?

Getting them from an elisp list format, \n separated format or otherwise into a python list format will be trivial, so the precise content of the kill ring matters little.

4 Answers 4


Use function directory-files, for which C-h f tells you:

directory-files is a built-in function in `C source code'.

(directory-files DIRECTORY &optional FULL MATCH NOSORT)

Return a list of names of files in DIRECTORY.
There are three optional arguments:
If FULL is non-nil, return absolute file names.  Otherwise return names
 that are relative to the specified directory.
If MATCH is non-nil, mention only file names that match the regexp MATCH.
If NOSORT is non-nil, the list is not sorted--its order is unpredictable.
 Otherwise, the list returned is sorted with `string-lessp'.
 NOSORT is useful if you plan to sort the result yourself.

In this case, you provide your regexp as argument MATCH:

M-: (directory-files default-directory nil "[tT]ypolog[yi]")

And you need not be in a Dired buffer to use this.


If you use counsel-find-file from the counsel MELPA package, you can press M-w to copy all current matches. It works with regex patterns as input. Then press C-g if you don't wont to select a file afterwards.


You can mark all files whose names match a regular expression using dired-mark-files-regexp, and then copy them to the kill ring them (see this answer) using dired-copy-filename-as-kill.

Unfortunately, this does not result in a list that is in any way nicely separated, because the file names are just concatenated using by , so if your file names may contain spaces, you get a mess.


you could use a shell command to list the directory (ls -1), then use keep-lines to delete the lines that do not match your regex. the buffer then contains just the file names that you want, one per line.

  • That is actually (similar to, because using viper it started with something like :!ls) what I did the first time, but I felt like it was more cumbersome than it should be.
    – Anaphory
    Commented Aug 9, 2016 at 7:46

Your Answer

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

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