11 C
Texas

How To Copy and Paste Text Content from a Linux Terminal

Today we are going to learn that how we can easily copy and paste the text content using command line interface. In this tutorial, you will cover easy steps to learn the process that in what ways you can use clipboard on your Linux command line interface. There are various ways but we will cover few easy methods to save our time. Follow the below steps:

Step 1: Using Xorg Display Server

As defined earlier there are various ways to copy and paste text content from the linux terminal. Some users take advantage of Xorg Display server to copy and paste from the Linux Command line Interface. So I will recommend them to use the xclip tool for copying and pasting data from the command line Interface. It can be installed very easily on your system. Fire the below commands to Install xclip on your Linux Operating System.

For Ubuntu / Debian users

Run the following command to Install xclip on your Ubuntu / Debian system.

- Advertisement -
sudo apt -y install xclip

For Fedora / CentOS / RHEL

Fire the given command to Install xclip on CentOS 8 / RHEL 8 and Fedora Systems

sudo dnf -y install xclip

For Arch / Manjaro

Users who are using the Arch / Manjaro versions of Linux can run the below command to install xclip on their Arch / Manjaro systems.

sudo pacman -S xclip

How To use Xclip?

Follow the below steps to learn how you can use Xclip on your Linux System.

Copy Command Line execution output:

Run the below command to copy the output of CLI

top | xclip
uptime | xclip

You can copy file contents to clipboard by running

xclip /etc/os-release
xclip -sel clip /etc/os-release

To cat file contents and pipe to copy, type

tail -n 100 /var/log/messages | xclip -sel clip
cat myfile.txt | xclip -sel clip

Copy with redirection key

xclip -sel clip < /etc/passwd

You can save copied content to file by

xclip -o -sel clip > mydata.txt

Step 2: By using Wayland Display Server

The second method I would recommend to copy and paste content from the Linux Terminal is Wayland Display server. It is available on GitHub release page.

How Wayland Display server works?

Wayland Display server basically uses two command lines to copy and paste data in Linux Terminal. It uses wl-copy to copy the text content from the command line interface and wl-paste to paste the data between the clipboard and Unix pipes, sockets, files and so on .

How To Install Wl-clipboard?

Follow the below process to Install wl-clipboard on your Linux system.

To install wl-clipboard on Debian / Ubuntu run

sudo apt-y install wl-clipboard

For Fedora users

sudo dnf -y install wl-clipboard

The Arch / Manjaro users can install by typing

sudo pacman -S wl-clipboard

How To Use wl-Clipboard?

Now run the following command to copy the output of a command to the clipboard.

uptime | wl-copy
ls /etc | wl-copy

You can copy text message by

wl-copy "Welcome To OSRadar……."

Copy file contents to the clipboard by running

wl-copy < /etc/passwd
Image
wl-copy < ~/Pictures/photo.png

Use the below command to paste contents in the clipboard to file.

wl-paste > cb.txt

So, Copy the previous command

wl-copy "!!"

Then, clear the clipboard by typing

wl-copy -c

You have all done now, you can easily copy-paste content from Linux Terminal to various places.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article