How to select (copy) an output in terminal without mouse
Using tmux:
I use tmux
in vi mode:
- Go to copy mode (in my config Prefix+escape, Default Prefix is Ctrl+b)
- In config file (
~/.tmux.conf
):bind Escape copy-mode
- In config file (
- Move around (Using arrows)
- Select your desire output (Start selection with Space)
- In my config v:
bind-key -T copy-mode-vi y send-keys -X begin-selection
- In my config v:
- Press Enter to copy the text.
- In my config y:
bind-key -T copy-mode-vi y send-keys -X copy-selection
- In my config y:
- Press Prefix+p to Paste.
Also create a key binding like this:
bind C-c run "tmux save-buffer - | xsel -bi"
So you can save the buffer into system clipboard by pressing Prefix+Ctrl+c.
I have add my configuration cause it's more like vim than default config.
Using commands:
Here is what I do:
- Run the command (eg:
ls -1
) - Process the output to get my desired result
- Pip it to
xsel -bi
In your example:
$ ls -1 | sed -n 2p | xsel -bi
ls -1
prints the outputs each in one linesed -n 2p
get the second linexsel
has been used to copy the final result in clipboard.
If the command takes too long to run, first save the output to a file the process the output:
command > output
head -10 output | whatever | xsel -bi