You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

You looking for an easy way to copy and paste text content using Linux command line interface?. This guide will show you the simple ways of copying and pasting contents from a clipboard all in a Linux command line.

Using Xorg Display server

For those using the Xorg display on their Desktop, the best tool for copy and pasting on command line is xclip. This tool can be installed easily using the commands below.

-------- Ubuntu / Debian ------------
$ sudo apt -y install xclip

------- Fedora / CentOS/RHEL 8 ----------
$ sudo dnf -y install xclip

------- Arch / Manjaro ----------
$ sudo pacman -S xclip

Using Xclip

After installation, refer to below few examples to copy and paste contents on Linux terminal.

  • Copy command execution output
$ top | xclip
$ uptime | xclip
  • Copy file content to clipboard
$ xclip /etc/os-release
$ xclip -sel clip /etc/os-release
  • Cat file contents and pipe to copy
$ tail -n 100 /var/log/messages | xclip -sel clip
$ cat myfile.txt | xclip -sel clip
  • Copy with redirection key
$ xclip -sel clip < /etc/passwd
  • Save copied content to file
$ xclip -o -sel clip > mydata.txt

Using Wayland Display server

For Wayland display server, we’ll use wl-clipboard. The wl-clipboard project implements two command-line Wayland clipboard utilities, wl-copy and wl-paste, that let you easily copy data between the clipboard and Unix pipes, sockets, files and so on.

Installing wl-clipboard

---- Debian / Ubuntu ---
$ sudo apt -y install wl-clipboard

---- Fedora ---
$ sudo dnf -y install wl-clipboard

---- Arch / Manjaro ---
$ sudo pacman -S  wl-clipboard


  • Copy output of a command to clipboard
$ uptime | wl-copy
$ ls /etc | wl-copy
  • Copy text message
$ wl-copy "Hello world.."
  • Copy file contents to clipboard
$ wl-copy < /etc/passwd

# Image
$ wl-copy < ~/Pictures/photo.png
  • Paste contents in clipboard to file
$ wl-paste > clipboard.txt
  • Copy previous command
$ wl-copy "!!"
  • Clear the clipboard
wl-copy -c

Other interesting tools to check:

  • xsel — Command-line program for getting and setting the contents of the X selection.\

Also check:

Connect To VPN Server with Cisco AnyConnect from Linux Terminal

How To Connect To Bluetooth Device from Linux Terminal

How To Google Search from a Linux Terminal

Best Console / Terminal File Managers for Linux

10 Best Terminal Emulators for Linux

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF