• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

xclip Command Examples in Linux

by admin

Linux provides a command, xclip, that connects X selections to stdin and stdout. You can therefore insert copy and paste operations into pipelines and other combined commands. For example, you may have copied text into an application like this:

  • Run a Linux command and redirect its output to a file.
  • View the file.
  • Use your mouse to copy the file’s content to the clipboard.
  • Paste the content into another application.

With xclip, you can shorten the process considerably:

  • Pipe a Linux command’s output to xclip.
  • Paste the content into another application.

xclip Command Examples

1. Copy the output from a command to the X11 primary selection area (clipboard):

# echo 123 | xclip

2. Copy the output from a command to a given X11 selection area:

# echo 123 | xclip -selection primary|secondary|clipboard

3. Copy the output from a command to the system clipboard, using short notation:

# echo 123 | xclip -sel clip

4. Copy the contents of a file into the system clipboard:

# xclip -sel clip input_file.txt

5. Copy the contents of a PNG into the system clipboard (can be pasted in other programs correctly):

# xclip -sel clip -t image/png input_file.png

6. Copy the user input in the console into the system clipboard:

# xclip -i

7. Paste the contents of the X11 primary selection area to the console:

# xclip -o

8. Paste the contents of the system clipboard to the console:

# xclip -o -sel clip

Filed Under: Linux

Some more articles you might also be interested in …

  1. cmus Command Examples in Linux
  2. chsh Command Examples in Linux
  3. nmon Command Examples in Linux
  4. jasmine-node: command not found
  5. nixos-container : Command Examples in Linux
  6. CentOS / RHEL 7 : How to configure kdump using GUI
  7. vim: command not found
  8. test: command not found
  9. Beginners Guide to User and Group Administration in Linux
  10. CentOS / RHEL 6 : How to password protect grub (Password-Protected Booting)

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright