Linux – How to select and copy file names in the command line without using the mouse

command linekeyboard shortcutslinuxterminal

Typically, when I want to perform an action on a file I discovered in the terminal after calling [ls], I would have to – with my mouse – highlight, left click, copy file name, type the command in then paste the file name again.

Is there a way to copy a certain string that was previously displayed in the terminal without using my mouse?

Thanks!

Best Answer

sudo apt-get install xclip

Create an alias:

 alias pbcopy='xclip -selection clipboard'

Use this command to copy

ls | pbcopy

(You can also use

ls <filename> | pbcopy 

to copy a specific filename. If you don't know what an alias is: http://www.hostingadvice.com/how-to/set-command-aliases-linuxubuntudebian/ )