LinuxCommandLibrary

xsel

Access and manipulate X server selections

TLDR

Use a command's output as input of the clipboard (equivalent to )

$ echo 123 | xsel [[-ib|--input --clipboard]]
copy

Use the contents of a file as input of the clipboard
$ cat [path/to/file] | xsel [[-ib|--input --clipboard]]
copy

Output the clipboard's contents into the terminal (equivalent to )
$ xsel [[-ob|--output --clipboard]]
copy

Output the clipboard's contents into a file
$ xsel [[-ob|--output --clipboard]] > [path/to/file]
copy

Clear the clipboard
$ xsel [[-cb|--clear --clipboard]]
copy

Output the X11 primary selection's contents into the terminal (equivalent to a mouse )
$ xsel [[-op|--output --primary]]
copy

SYNOPSIS

xsel [options]

PARAMETERS

-a, --append
    Append standard input to the selection.

-b, --clipboard
    Operate on the CLIPBOARD selection (instead of PRIMARY).

-c, --clear
    Clear the selection.

-d, --display displayname
    Specify the X display to use.

-i, --input
    Read standard input into the selection (replaces current content).

-k, --keep
    Keep the selection, even when the window that owns it exits.

-l, --length
    Output the length of the selection in bytes.

-m, --mouse
    Wait for a middle-button press to select the text.

-n, --nodetach
    Do not detach from the controlling terminal.

-o, --output
    Output the selection to standard output.

-p, --primary
    Operate on the PRIMARY selection (the default).

-s, --secondary
    Operate on the SECONDARY selection.

-x, --exchange
    Exchange the PRIMARY and SECONDARY selections.

-V, --version
    Display version information and exit.

-h, --help
    Display this help message and exit.

DESCRIPTION

The xsel command is a command-line utility for accessing and manipulating the X Window System's selection buffers (clipboard). It allows you to get the current contents of the selection buffer, replace the selection buffer with data from standard input, or exchange the primary and secondary selections. xsel supports multiple selection buffers, including PRIMARY (usually used for copy/paste within an application) and CLIPBOARD (usually used for copy/paste between applications). It is a valuable tool for scripting and automating tasks that involve clipboard interaction, such as transferring data between different applications or manipulating text in the clipboard.

By default, xsel operates on standard input or standard output. You can specify which selection to use via command-line options. The command is mostly used within scripts and for integration with other command line utilities.

It should be noted that different desktops have different clipboard managers. Therefore the results might vary. Xsel, by itself, does not notify other applications about changes to the clipboard, therefore, an external program to notify other programs might be required.

EXAMPLES

Copying output of command:
ls -l | xsel -b -i

Pasting output to command:
xsel -b -o | wc -w

Appending to the clipboard:
echo 'more text' | xsel -b -a

SEE ALSO

xclip(1), wl-copy(1), wl-paste(1)

Copied to clipboard