2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Copying command output directly into clipboard on Linux

Last updated at Posted at 2015-04-12

I am a Linux user and wanted to just copy the output of commands such as pwd to the system clip board without hassles. Here is how:

1) Install xclip with apt-get

$ sudo apt-get install xclip

2) Pipe command output to xclip

$ <your command> | c=tr -d '\n' | xclip -selection clipboard

For example, this one-liner

$ pwd | c=tr -d '\n' | xclip -selection clipboard

copies the current directory path into the system-wide clipboard. Without the trailing option -selection clipboard, the content copied will not be available to other applications.

Command Alias

To make life even easier for lazy people like me, create the alias

alias "c=tr -d '\n' | xclip -selection clipboard"

in your ~/.bashrc, and use it this way:

$ pwd | c

Now you can paste the output of the command anywhere on your machine :)

Reference:
How can I copy the output of a command directly into my clipboard?
http://stackoverflow.com/a/5130969/1478110

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?