I want to list particular files in a buffer, with each file on its own line. I want to be able to choose the files to list from a Dired buffer.

I tried copying file names to the clipboard, and then pasting what I copied, but that puts all of the file names on the same line. For example if I mark these file nams Slide1.JPG Slide2.JPG Slide3.JPG

issue 0w

then paste and they are all in 1 line:


I instead want each file to have its own line so it will look like this:




any clue?

4 Answers 4


Is it important for you to copy to the clipboard and then paste?

If you just want file names listed in a buffer then you can easily do that using Dired+.

Just mark the files whose names you want to list, then hit C-M-l.

The files are listed in a buffer named *Files*, which you can of course rename.

(If you also mark some directories then they too are listed.)

C-h k C-M-l tells you:

C-M-l runs the command diredp-list-marked, which is an interactive compiled Lisp function in dired+.el.

It is bound to C-M-l, menu-bar operate diredp-list-marked.

(diredp-list-marked &optional ARG PREDICATE)

List the marked files in this Dired buffer. A prefix arg specifies files to use instead of the marked files:

  • Numeric prefix arg N: The next N files (previous -N, if < 0).
  • C-u C-u: All files, but no directories.
  • C-u C-u C-u: All files and directories, except . and ..
  • C-u C-u C-u C-u: All files and directories, including . and ..
  • Any other prefix arg: The current line's file only.

    You can use RET or mouse-2 to visit any of the files. If tooltip-mode is on then moving the mouse over image-file names shows image previews.

    Non-interactively, non-nil arg PREDICATE is a file-name predicate. List only the files for which it returns non-nil.

You can also do the same thing for all marked files including those in marked subdirectories, defined recursively. You do that using M-+ C-M-l (command diredp-list-marked-recursive). (All commands that act on marked files defined recursively are on prefix key M-+.)


A workaround using xargs:

  • Yank the filenames as you did (all in 1 line)
  • Select the line
  • pipe to a command C-u M-|
  • xargs -n 1

This will substitute your selection with one filename per line.


If you are using counsel, when you execute find-file or projectile-find-file and enter a regexp(or a search string) to narrow down the files to search, pressing M-w will copy the file names in as they appear in ivy.

But they don't copy the full path names of the files, only filename is copied OR if you are using projectile, the file names relative to the project root directory is copied. I'm not sure how you can get the full path name from ivy. But, if you're happy with just the file names, you can use this method :)

An alternative solution(this is better than the first solution) would be to use the command directory-files to get the file names. With this, you can also get the full path names of the file. Check help for the function using C-h f for more details.

  • Call dired-do-shell-command on the marked files, which is bound to ! per default
  • Enter echo, which is a shell command that returns whatever you feed it to stdout
  • Observe a new buffer popping up with the output from echo, which contains all filenames separated by new lines.

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.