Linux:xclip,pbcopy,xsel usage terminal copy sticky sticker (Mac, Ubuntu)

Source: Internet
Author: User

http://justcoding.iteye.com/blog/1829963

1. Under Windows

Use the command that comes with your system clip .
# is located C:\Windows\system32\clip.exe .

Example:

C code
    1. echo Hello | Clip
    2. # put the string hello into the Windows clipboard
    3. Dir | Clip
    4. # put the dir command output (current directory list) into the Windows clipboard
    5. Clip < README. Txt
    6. # put Readme.txt text in the Windows clipboard
    7. echo | Clip
    8. # Place a blank line into the Windows clipboard, which clears the Windows clipboard

2. Under Ubuntu

Users under Ubuntu can install with Apt-get only:

C code
    1. sudo apt-get install Xclip
Other releases of the user can choose their own installation method, can also be compiled with the source code installation, Xclip project's home page is: http://sourceforge.net/projects/xclip/

The Xclip can output content to the ' X ' clipboard, such as:

C code
    1. Echo "Hello, World" | Xclip

After executing this command, you can use the middle mouse button to paste the content in the X program. But more often than not just outputting the content to the ' X ' clipboard, we want to be able to paste it in the GUI program (for example, in the Gnome clipboard), and the following command lets you output the content to Gnome's clipboard:

C code
    1. Echo "Hello, World" | xclip-selection clipboard

Then press CTRL + V in a GUI program to see if it's pasted up? Following this command, I also re-wrote the ifconfig, let it input content to the terminal after execution, but also output the IP address to the Clipboard, because generally, the view ifconfig is to obtain the machine's IP address:

C code
    1. Alias ifconfig='/sbin/ifconfig && echo '/sbin/ifconfig | sed-n 2p | awk "{print \\$2}" | grep-o "[0-9]\{1, 3\}\. [0-9]\{1,3\}\. [0-9]\{1,3\}\. [0-9]\{1,3\} ' | xclip-selection Clipboard '

Or

C code
    1. Xclip-sel Clip < file

You can then CTRL + V on the page and other edit boxes.

Project home: http://sourceforge.net/projects/xclip/
Command Man Page:http://linux.die.net/man/1/xclip

- I., -inRead text to X selection from standard input or files (default) - o, -outPrints the selection to standard out (generally-piping to a-file or program) - F, -filterWhen Xclip was invoked in the on mode with output level set to silent (the defaults), the filter option would cause Xclip to Print the text piped to standard on back to standard out unmodified - L, -loopsNumber of X selection requests (pastes into X applications) to wait for before exiting, with a value of 0 (default) causin G Xclip to wait for an unlimited number of requests until another application (possibly another invocation of Xclip) takes Ownership of the selection - D, -displayX display to use (e.g. "localhost:0"), Xclip defaults to the value in $ DISPLAYIf this option is omitted 3. Under Linux

Use the xsel command.

Example:

C code
    1. Cat README. TXT | Xsel
    2. Cat README. TXT | Xsel-b # If you have questions, try the-B option
    3. Xsel < README. Txt
    4. # put Readme.txt text in the Clipboard
    5. Xsel-c
    6. # Empty the Clipboard

4. Under Mac

Use the pbcopy command. # There should be a pbpaste command.

Example:

C code
    1. echo ' Hello world! ' | pbcopy
    2. # Put the string Hello World into the Clipboard
C code
    1. Cat MyFile.txt | Pbcopy
C code
    1. Pbpaste > File.txt
to copy the results and to see the output of the command

Command output is not visible if you give the Copy command (the above-mentioned command, clip, Xsel, pbcopy). If you want to see the output of the command first, you can do so below.

C code
    1. $ echo ' Hello world! ' | tee tmp.file.txt
    2. Hello world!
    3. $ Xsel < Tmp.file.txt
    4. $ RM tmp.file.txt
That is, first use teecommand to export the output to the console and to a file. After the command executes, the output is then placed on the Clipboard. copy SSH's public key

Use the following command:

C code
    1. $ pbcopy < ~/.ssh/id_rsa.pub

Note: Different systems use different copy commands. Avoid using a text editor to open this file, select text, CTRL + C as a tedious operation.

Linux:xclip,pbcopy,xsel usage terminal copy sticky sticker (Mac, Ubuntu)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.