Posts Tagged ‘copy’

Don’t paste blindly to your terminal

January 27, 2017 2 comments

Most of the time when we see a code snippet online to do something, we often blindly copy paste it to the terminal.

Well, the copied text may contain some malicious code. Here is a post about that with a demo.

Categories: bash Tags: , ,

Copy and paste the output of a program

February 24, 2011 Leave a comment

It is a common task to copy the output of a program/script and paste it somewhere else. If the output is short (just some lines), we can select the text easily with the mouse. What about longer outputs?

Old method

Until now I’ve been using the following method:

  • ./produce-long-output >a (redirect the output to a temporary file)
  • gedit a (open the temp file with a text editor)
  • CTRL+A (select the whole text)
  • copy selected text to the clipboard
  • paste text to somewhere else
  • rm a (remove the temp file)

New method

Recently, I discovered some tools (xclip and xsel) that can copy a text to the clipboard. With them, it is unnecessary to use a temporary file.

./produce-long-output | xsel

It’ll copy the text to the “primary” clipboard that you can paste with the middle mouse button. If you prefer pasting with Shift + Insert, then copy texts to the 3rd clipboard (it is simply called “clipboard”).

./produce-long-output | xsel -b

Life has become a little bit less complicated :)

Categories: bash Tags: , , , ,

Copy string to X clipboard in shell

February 24, 2011 6 comments

This entry is based on the post Copy Shell Prompt Output To Linux / UNIX X Clipboard Directly.


Under Linux, you want to copy a given text to the X clipboard. How to do that?

Three different clipboards

First of all, we should know that under X there are three clipboards :)

  • “primary”: The primary one’s paste operation is usually accessed with the middle mouse button.
  • “secondary”: This one didn’t really work for me…
  • “clipboard”: Its paste operation is accessed with Shift + Insert (or right mouse click and Paste in popup menus).

The xclip command

Reads from standard in, or from one or more files, and makes the data available as an X selection for pasting into X applications. Prints current X selection to standard out.


sudo apt-get install xclip

Copy a string to the clipboard. By default, xclip copies to the “primary” clipboard.

echo "this is a test" | xclip
echo "this is a test" | xclip -selection primary
echo "this is a test" | xclip -selection p

The three variations are equivalent.

Copy a string to the “clipboard” (3rd clipboard).

echo "another test" | xclip -selection clipboard
echo "another test" | xclip -selection c

The two variations are equivalent.

Copy the contents of a file to the clipboard.

cat file.txt | xclip

Print the contents of the clipboard to the standard output.

xclip -o

Of course, you can use redirection.

xclip -o > out.txt

The xsel command

Retrieve and set the X selection.

xsel is similar to xclip, but it offers some additional features like append, clear, etc.


sudo apt-get install xsel

Copy a string to the primary clipboard (default).

echo "1" | xsel
echo "1" | xsel -p

The two variations are equivalent.

Copy a string to “clipboard” (3rd clipboard).

echo "1" | xsel -b

Copy the contents of a file to the clipboard.

cat file.txt | xsel

Print the contents of the clipboard to the standard output.

xsel -o


Find a solution to copy a string to the “primary” and “clipboard” clipboards, i.e. on both. Hint: “echo homework | xsel -p -b” and “echo homework | xclip -selection p -selection c” won’t work. Post your solution in the comments.

Categories: bash Tags: , , ,

My vimperator settings

January 6, 2011 1 comment

Update (20110502): This post was updated for Vimperator 3.1. Copy/paste is corrected in this new version, thus the plugin mswin.vimp is not needed anymore. I removed that part from the post.

Vimperator is a Firefox browser extension with strong inspiration from the Vim text editor, with a mind towards faster and more efficient browsing. It has similar key bindings and you could call it a modal web browser, as key bindings differ according to which mode you are in. For example, it has a special Hint mode, where you can follow links easily with the keyboard only. Also most functionality is available as commands, typing :back will go back within the current page history, just like hitting the back button in the toolbar.” (source)

Vimperator is a very useful Firefox add-on. When I reinstall a system, this is one of the first add-ons that I need to install in order to be able to work efficiently :)

Here are my config files:

Useful commands:

To tell the truth, I only use a very small subset of the features offered by Vimperator. Here are my favourites:

  • ESC (hitting the ESC key => enter command mode)
  • j, k (Scroll down and up. To memorize: j looks like a down arrow.)
  • r (reload the page)
  • o URL (open URL in the current tab)
  • t URL (open URL in a focused new tab)
  • T URL (Open URL in an unfocused new tab. This is a custom feature added to my config file.)
  • / SEARCH_TERM (Vim-like, case-insensitive incremental search. Pressing n you can jump to the next the search hit.)
  • d (close the current tab)
  • u (Restore a closed tab. Can be used repeatedly to restore several closed tabs.)
  • :res (Restart the browser. It’ll restore the tab set.)
  • gu (From the current URL, remove the part after the last ‘/’. Example: becomes
  • gU (In the current URL, leave the host name only. Example: becomes
  • gg (jump to the top of the page)
  • G (jump to the end of the page)
  • y (copy the current URL to the clipboard)
  • ALT+y (Copy page title to the clipboard. This is a custom feature added to my config file.)
  • Shortcuts; I just love them. You have a favourite site, say, and you want to assign an alias to this site, for instance “sd”. Then, you’d like to open this site by using the command “:o sd“. To this end, visit the site (here, and assign a bookamark to it by “:bma -k=sd“. From now on, “sd” is associated to You can type “sd” in the address bar too.

If you know some cool tips, please share with us in the comments.