I often times want to copy a set of commands from terminal, that do not have an output; say a block like this:

prompt$ less file1.txt
prompt$ less file2.txt
prompt$ dhex file2.txt
prompt$ less file3.txt

Now, if I select this block of text with the mouse, and copy it with Ctrl-Shift-C; then when I paste in a text file, the prompt is there (as expected) - and then I have to waste time deleting the prompt :)

So I was wandering - is there a setting for gnome-terminal, such that when I do the same kind of copying, I end up with only the commands - without the prompt? This is what I want when I finally paste:

less file1.txt
less file2.txt
dhex file2.txt
less file3.txt

I'm interested in a solution that will allow me to get this in clipboard, with just mouse selection and Ctrl-Shift-C; I am aware I could do history X, but then I'd have to grep it - and think of a suitable grep expression (and the same problem is if I record a typescript of terminal session with script).

Any facilities that exist for that? If not for gnome-terminal, any other terminal that can be used under Gnome that offers such facility?

4 Answers 4


In Gnome Terminal, you can select a block of text using Mouse + CTRL key. This way you can copy all of the console output without the prompt. e.g:

enter image description here


Assuming you're using bash as your shell, you might just do something like:

history -a ; tail -5 $HISTFILE

replacing 5 with however many commands you want to go back. That should get you a clean listing that will copy/paste easily. Not exactly the kind of approach you seem to be fishing for, but it might suit.

  • Many thanks for that, @JasonSherman - unfortunately, that only includes the terminal commands, not the output. I did come close in this answer, which I accepted (until I hear of anything better, at least). Cheers!
    – sdaau
    Apr 9, 2013 at 1:19

Well, I was quite bugged by this problem, so finally I coded a solution which comes very close: a filtering plugin for the Glipper clipboard manager, which allows for regex processing in filter functions, which can be applied to the clipboard contents upon a Copy action; released here:

... and here is a screenshot:


However, since I want to use this only occasionally, toggling filtering may not be the best idea (since you have to toggle ON, copy/paste, and then toggle OFF) - so the plugin bypasses normal operation when a filter submenu entry is clicked, if Ctrl, Alt or c are held; so my "minimal" action to perform a one-off prompt filtering is like this:

  • Select a region of text (including prompts) in terminal
  • Press Ctrl+Alt+c (default shortcut) to bring up Glipper menu window
  • Keeping any (or all) of Ctrl, Alt or c held pressed,
    • hover over Filtering menu item
    • hover over and click desired filter (sub)menu item (e.g. TermCmdLog)
  • Glipper menu dissapears - held keys can now be released
  • Move pointer and click to focus text editor
  • Paste - the pasted contents are modified by the clicked filter (e.g. for TermCmdLog the input has prompts removed, and non-prompt lines commented)

In the end, I would still have preferred that the terminal itself has a keyboard chord for filtered output (say, press Ctrl+Shift+a, then release a, then while holding the others press c) - but then that would be OK for a single filter; and if you want to choose one from several filters at runtime, again there is the problem of having of yet another action to do a choice; and if it is solved via GUI window of menu entries - then this pluggin is just as good, I guess. Even better, it works for any GUI source of (copyable) text under Gnome desktop - not just for terminal.

Unfortunately, it's developed for Gnome/Gtk 2 / Python 2.7, so it's already deprecated; still, hope it can hope others (until I hear of a better solution - hopefully in this thread :)),

  • wish the screenshot is not shrinked... Apr 9, 2013 at 1:50

If you use, tmux terminal multiplexer, you can do this easily and much more!

Noam Manos already pointed out in the other answer Gnome Terminal does allow block copy with Ctrl + Mouse click and drag. I just wanted to point out another alternative which is more powerful. The tmux supports putting your terminal in "copy mode" and allows you to do block copy and much more -- It even supports multiple paste buffers that you can copy and use later.

I use following lines in my .tmux.conf file to use vi keybindings for block copy:

bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle 

It does take some effort to learn to setup and use tmux, but it is worth it and I am happy with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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