One of the vital tasks performed by system admins and developers is copying and pasting. This is vital, especially when running commands on the terminal or copying code for an application. Copying and pasting using the long method of right-clicking and selecting the desired copy/paste option can be exhausting when you have tight margins. On the Linux terminal, you can efficiently perform the copy-and-paste activities by highlighting to copy and then the wheel button on the mouse to paste.

In this guide, I want to make it more easier and exhilarating to perform copy-and-paste on the Linux Terminal. Clipboard is a powerful tool that saves you time and effort by eliminating the tussle involved when moving text and files. This in turn increases productivity and makes scenarios simply impractical. This unified clipboard can be used in the terminal just as if you are using it on the GUI.

The main reasons why Clipboard is preferred are:

  • Quick: No configs are required
  • Pretty: Breaks the rules to look beautiful.
  • Easy to use: It is friendly to newbies and power users alike.
  • Compatible: It works on anything that supports C++20.
  • Universal: It supports English, Spanish, Portuguese, and Turkish.
  • Unified: It offers the same functionality everywhere.
  • Integrated: It can connect with many other native GUI clipboards.

Let’s plunge in and see how we can easily set up and use this Clipboard to cut, copy and paste anything on Linux Terminal.

#1. Install Clipboard Tool on Linux

The Clipboard tool can easily be installed on Linux using any of the two methods:

a. Quick Installation

Using this method will require glibc_2.34. It can possibly work on Ubuntu22|Rocky 9|Alma 9|CentOS Stream9. Before we proceed, ensure that cURL and GCC are installed.

##On Debian/Ubuntu
sudo apt update && sudo apt install curl -y gcc

##On RHEL/Rocky Linux/Alma Linux/CentOS Stream
sudo yum install curl gcc -y

If you have multiple GCC versions, configure them with the command:

sudo update-alternatives --config gcc

Verify the selection.

$ gcc --version
gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

With curl installed, execute the below command to perform a quick installation.

curl -sSL https://github.com/Slackadays/Clipboard/raw/main/src/install.sh | sudo bash

Sample Output:

cut copy and paste anything on Linux Terminal

b. Manual Installation

Alternatively, you can manually install the Clipboard tool if the above method fails. This requires build tools installed on the system.

##On Debian/Ubuntu
sudo apt install build-essential cmake -y

##On RHEL/Rocky Linux/Alma Linux/CentOS Stream
sudo dnf groupinstall "Development Tools"

On Rhel-based systems, install CMake:

sudo yum install epel-release -y
sudo yum install snapd -y
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap
sudo snap install cmake --classic

Switch to the root user and execute the command below to allow the Snapd package to be found:

echo -n "export PATH=/snap/bin:\$PATH" >> ~/.bashrc
source ~/.bashrc

Then proceed with the commands as root:

git clone https://github.com/slackadays/Clipboard 
cd Clipboard/build
cmake -DCMAKE_BUILD_TYPE=MinSizeRel ..
cmake --build .
cmake --install .

#2. How to use Clipboard Tool on Linux

The main commands used are:

  • Copy: clipboard ([--]copy|[-]cp)(num)|_(id) [files]
  • Cut : clipboard ([--]cut|[-]ct)(num)|_(id) [files]
  • Paste : clipboard ([--]paste|[-]p)[(num)|_(id)]
  • Pipe In(something) | clipboard [([--]copy|[-]cp)][(num)|_(id)]
  • Pipe Outclipboard [([--]paste|[-]p][(num)|_(id)] | (something) or clipboard [([--]paste|[-]p)][(num)|_(id)] > (some file)
  • Show Contentsclipboard ([--]show|[-]sh)[(num)|_(id)]
  • Clear Contents:clipboard ([--]clear|[-]clr)[(num)|_(id)]

In all the above commands, you can substitute clipboard with cb. At the end of each command, you can either use a number to identify the clipboard to use(default is 0) or _ to use a persistent clipboard.

I will demonstrate how to use the clipboard to perform simple copy-and-paste activities. To be sure that the Clipboard tool is working, issue the command:

$ cb --help
▏This is Clipboard 0.2.1r2, the cut, copy, and paste system for the command line.
▏How To Use
▏clipboard cut (item) [items] (This cuts an item or items.)
▏clipboard copy (item) [items] (This copies an item or items.)
▏clipboard paste (This pastes a clipboard.)
▏clipboard show (This shows what's in a clipboard.)
▏clipboard clear (This clears a clipboard's contents.)
▏You can substitute "cb" for "clipboard" and use various shorthands for the actions to save time.
▏You can also choose which clipboard you want to use by adding a number to the end, or _ to use a persistent clipboard.
▏Examples
▏cb ct Nuclear_Launch_Codes.txt contactsfolder (This cuts the following items into the default clipboard, 0.)
▏clipboard cp1 dogfood.conf (This copies the following items into clipboard 1.)
▏cb p1 (This pastes clipboard 1.)
▏cb sh4 (This shows the contents of clipboard 4.)
▏cb clr (This clears the contents of the default clipboard.)

To copy a text file to a clipboard you can use the command with the syntax:

clipboard copy sample.txt
##OR
cb copy sample.txt

For example

cut copy and paste anything on Linux Terminal 1

It is also possible to copy multiple items. For example:

cut copy and paste anything on Linux Terminal 2

To cut a directory, use the command with the syntax:

clipboard cut sample.txt
##OR
cb cut sample.txt

To paste the contents of the clipboard, switch to the desired directory and execute the command:

mkdir new && cd new
cb paste

Sample Output:

cut copy and paste anything on Linux Terminal 3

You can also assign a number to the clipboard. For example:

$ clipboard cp1 new.yaml
✓ Copied new.yaml

To paste the contents of clipboard 1, use the command:

$ cb p1
✓ Pasted new.yaml

To clear the clipboard, use the command:

$ cb clr
✓ Cleared the clipboard

#3. Simple Clipboard Tool Configurations.

You can use Environment variables to configure the Clipboard Tool as desired. The available environment variables are:

  • CI: This is used to make Clipboard overwrite existing items without a user prompt when pasting. It is essential for Continuous Integration scripts where human interactions are not required.
  • FORCE_COLOR: Set this to make the Clipboard always show colour regardless of what you set NO_COLOR to
  • TMPDIR: This sets the directory that Clipboard will use to hold the items you cut or copy into a temporary directory. Other programs use TMPDIR as well, so be careful about changing this.
  • CLIPBOARD_TMPDIR: Sets the directory that only Clipboard will use to hold the items you cut or copy into a temporary directory.
  • CLIPBOARD_PERSISTDIR: Set this to the directory that only Clipboard will use to hold the items you cut or copy into a persistent directory.
  • CLIPBOARD_ALWAYS_PERSIST: This makes the Clipboard tool have persistent clipboards.
  • CLIPBOARD_NOGUI: Used to disable integration with GUI clipboards.
  • NO_COLOR: This makes the Clipboard not show any colours.

Any of the above variables can be used by following a demo syntax below:

export CLIPBOARD_TMPDIR=~/new

This will set the CLIPBOARD_TMPDIR to ~/new.

Conclusion

That marks the end of this amazing guide on the easy way to cut, copy and paste anything on Linux Terminal. You are now free to explore more functions associated with this tool. I hope this was significant to you.

See more:

How To Copy and Paste Text Content from Linux Terminal

Easily Change Linux/macOS Terminal Theme using theme.sh

Install and Use Micro terminal text editor on Rocky/AlmaLinux 8

How To Run Linux Terminal on Web Browser using Wetty

LEAVE A REPLY

Please enter your comment!
Please enter your name here