xclip in CentOS

Introduction

To save time when working with files and when processing command output, you can install xclip and redirect the output straight to the clipboard.

This saves you from wasting time on selecting text and copying it for pasting.

Installation

First you need to install epel-release

sudo yum install epel-release
…
sudo yum install xclip

Extra Packages for Enterprise Linux Modular 8 - x86_64 1.5 MB/s | 931 kB 00:00 Extra Packages for Enterprise Linux 8 - x86_64 4.7 MB/s | 10 MB 00:02 Last metadata expiration check: 0:00:02 ago on Mon 30 Aug 2021 09:46:37 AM EDT. Dependencies resolved. ====================================================================================================== Package Architecture Version Repository Size ====================================================================================================== Installing: xclip x86_64 0.13-8.el8 epel 35 k Transaction Summary ====================================================================================================== Install 1 Package Total download size: 35 k Installed size: 60 k Is this ok [y/N]: y Downloading Packages: xclip-0.13-8.el8.x86_64.rpm 257 kB/s | 35 kB 00:00 ------------------------------------------------------------------------------------------------------ Total 65 kB/s | 35 kB 00:00 warning: /var/cache/dnf/epel-6519ee669354a484/packages/xclip-0.13-8.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY Extra Packages for Enterprise Linux 8 - x86_64 1.0 MB/s | 1.6 kB 00:00 Importing GPG key 0x2F86D6A1: Userid : "Fedora EPEL (8) <epel@fedoraproject.org>" Fingerprint: 94E2 79EB 8D8F 25B2 1810 ADF1 21EA 45AB 2F86 D6A1 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8 Is this ok [y/N]: y Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : xclip-0.13-8.el8.x86_64 1/1 Running scriptlet: xclip-0.13-8.el8.x86_64 1/1 Verifying : xclip-0.13-8.el8.x86_64 1/1 Installed products updated. Installed: xclip-0.13-8.el8.x86_64 Complete!

File to the clipboard

Using the example of an SSH certificate for GitLab

xclip -sel clip < ~/.ssh/gitlab_com_rsa.pub

Result of the command execution to the clipboard

The syntax is as follows

COMMAND | xclip

For example

ls | xclip

You can paste the result by pressing the middle mouse button.

Article author: Andrei Olegovich