Skip to main content

How to Use XCLIP in Linux for Clipboard

How to Use XCLIP in Linux for clipboard




xclip  reads  text  from standard in or files and makes it available to other X applications for pasting as an X selection (traditionally with the middle mouse button). It reads from all files specified, or from  standard  in if no files are specified. xclip can also print the contents of a selection to standard out with the -o option.

xclip  was designed to allow tighter integration of X applications and command line programs. The default action  is to silently wait in the background for X selection requests (pastes) until another X application places  data in  the clipboard, at which point xclip exits silently. You can use the -verbose option to see if and when xclip actually receives selection requests from other X applications.


Install Xclip  in Linux
Xclip program are available in the official repositories of most modern Linux distributions.

On RHEL, CentOS:

$ sudo dnf install epel-release
$ sudo dnf install xclip 

On Fedora:

$ sudo dnf xclip 
On Debian, Ubuntu, Elementary_OS, Linux Mint:

$ sudo apt install xclip 
On openSUSE:

$ sudo zypper install xclip



Xclip command examples

There are 3 selections 

p--> primary
sec--> secondary
clip-->clipboard

xclip -i -sel clip
xclip -i -sel sec
xclip -i -sel p

Copy data to clipboard using Xclip
To copy the output of a command to clipboard using Xclip, run:

$ echo "Welcome To sudofoa" | xclip -selection clipboard

 
You can also use this short version of the above command:

$ echo "Welcome To sudofoa" | xclip -sel c



This copies the output of a Linux command to clipboard using Xclip

Here, -sel represents the -selection and c represents clipboard.

$ uname -r | xclip -sel c
We copied copy the output from stdin into clipboard buffer. 

To copy file contents into clipboard using  command, run:

$ xclip -selection clipboard < sudofoa.txt
Or shortly use this:

$ xclip -sel c < sudofoa.txt

The above commands will not display contents of the files. Instead, they will only copy the file contents to system clipboard.

Paste data from clipboard to console/terminal using Xclip

We know now how to copy the data from standard output and a file to clipboard. How to retrieve the copied data from clipboard? That's simple! Run the following command to paste the contents of the system clipboard to the console:

$ xclip -o -sel clip
Or,

$ xclip -o -sel c
If you want to paste the contents of the X11 primary selection area to the console, run:

$ xclip -o

Paste data from clipboard to file using Xclip
Instead of displaying (pasting) the contents of clipboard, you can also directly paste the contents of the system clipboard or X11 primary selection area into a file like below:

$ xclip -o -sel clip > output_file.txt
Or,

$ xclip -o > output_file.txt

$ xclip -o >> output_file.txt

For more details, refer Xclip manual page

$ man xclip



If you like please follow and comment

Comments

Popular posts from this blog

WebLogic migration to OCI using WDT tool

WebLogic migration to OCI using WDT tool Oracle WebLogic Deploy Tool (WDT) is an open-source project designed to simplify and streamline the management of Oracle WebLogic Server domains. With WDT, you can export configuration and application files from one WebLogic Server domain and import them into another, making it a highly effective tool for tasks like migrating on-premises WebLogic configurations to Oracle Cloud. This blog outlines a detailed step-by-step process for using WDT to migrate WebLogic resources and configurations. Supported WLS versions Why Use WDT for Migration? When moving Oracle WebLogic resources from an on-premises environment to Oracle Cloud (or another WebLogic Server), WDT provides an efficient and reliable approach to: Discover and export domain configurations and application binaries. Create reusable models and archives for deployment in a target domain. Key Pre-Requisites Source System: An Oracle WebLogic Server with pre-configured resources such as: Applica...

Rename a PDB in Oracle Database Multitenant Architecture in TDE and Non TDE Environment

Rename a PDB in Oracle Database Multitenant Architecture I am sharing a step-by-step guide to help you rename a PDB. This approach uses SQL commands. Without TDE or encryption Wallet Initial Check Check the Current Database Name and Open Mode: SQL > SELECT NAME, OPEN_MODE FROM V$DATABASE; NAME OPEN_MODE --------- -------------------- BEECDB READ WRITE List Current PDBs: SQL > SHOW PDBS; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 FUAT READ WRITE NO We need to RENAME FUAT to BEE  Steps to Rename the PDB Step 1: Export ORACLE_SID Set the Oracle SID to the Container Database (CDB): export ORACLE_SID=BEECDB Step 2: Verify Target PDB Name Availability If the target PDB name is different from the current PDB name, ensure no service exists with the target PDB name. Run SQL to Check Exi...

How to make flash work on IE or Edge with IE Compatibility

How to make flash work on IE or Edge with IE Compatibility With flash been ended from 1-Jan-2021, many applications using flash have stopped working the way they were built (like OEM, OBIEE, etc). The option you have to upgrade.  This method will give a workaround in IE or Edge in IE compatibility mode without upgrading. 1. Verify you have installed flash.ocx on your desktop. Typically, flash.ocx file is located in C:\Windows\System32\Macromed\Flash or C:\Windows\SysWOW64\Macromed\Flash according to your laptop OS system. 2. Edit mms.cfg from the location as a System Administrator In the case of the 64bit system, it might have mms.cfg under C:\Windows\SysWOW64\Macromed\Flash 3. Add below options into mms.cfg file. Note: AllowListUrlPattern list is an example. The URLs need to be replaced to your hosts those have Flash pages. SilentAutoUpdateEnable=0 AutoUpdateDisable=1 EOLUninstallDisable=1 EnableAllowList=1 AllowListUrlPattern=http://www.google.com/ AllowListUrlPattern=http://goo...