Copying filenames to clipboard in Big Sur aka WTF

That means you have to navigate to the folder with all the files in it in Terminal (which is trivial for someone that knows the command line and how to drag a window’s icon there, but not so much for others), it will probably put the names in columns, you have to open the text file in something and copy its contents, and you have to remember to remove the text file when you’re done with it. Here’s a fix for the last three:

ls -1 | pbcopy

That doesn’t remove having to navigate to the correct folder. However, one advantage it does have is that you can insert a grep (or perl or whatever) in the pipeline. For example:

ls -1 | grep '^A' | pbcopy

copies all the names starting with a capital-A. Obviously that can be arbitrarily complex, limited only by your knowledge of the command line tools available.

However, for someone not familiar with the command line and Terminal, copying the files in the Finder, and then doing a Paste Special (or whatever the application you’re pasting them into calls it), seems much simpler.

1 Like

Yep, sounds right. I will point out that the three-column problem isn’t generally a real problem; piping the output of ls to a file will result in one line per file, if the output isn’t to a terminal.

Also, the pipeline works fine with or without pbcopy, you can certainly write ls -1 | grep '^A' > /tmp/foo

OTOH, I wasn’t familiar with pbcopy, so … I learned something today! Many thanks!

1 Like

Thanks for the clarification. I have since moved onto PopClip which is frequently updated by a very responsive author and has a lot more features that I find useful.