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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • 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. “java” command does not run the JVM that has been installed
  2. cryptsetup Command Examples in Linux
  3. Starting udev: udevd inotify_init failed: too many open files
  4. UNIX / Linux : What Is a Shell? What are different Shells?
  5. “docker volume” Command Examples
  6. How to Create and Mount Btrfs Snapshots
  7. smbclient: command not found
  8. dir: command not found
  9. logrotate: command not found
  10. “gitlab-ctl” Command Examples

You May Also Like

Primary Sidebar

Recent Posts

  • “glab pipeline” Command Examples
  • “glab mr” Command Examples
  • “glab mr merge” Command Examples
  • “glab mr” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright