{"id":14513,"date":"2026-08-12T02:30:00","date_gmt":"2026-08-12T06:30:00","guid":{"rendered":"https:\/\/www.both.org\/?p=14513"},"modified":"2026-08-12T02:26:37","modified_gmt":"2026-08-12T06:26:37","slug":"copy-data-to-your-clipboard-from-a-terminal-with-wl-copy","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=14513","title":{"rendered":"Copy data to your clipboard from a terminal with wl-copy"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"14513\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p class=\"wp-block-paragraph\">When you spend a lot of time in a Linux terminal, it can become laborious to take your hand off the keyboard to grab the mouse. The habit of selecting text, right-clicking (or pressing keys) to copy, and then right-clicking (or pressing keys) to paste is a strong one, and it seems there&#8217;s always something that needs copying and pasting. Thanks to the <code>wl-copy<\/code> command, you can now copy things to your system clipboard, right from your Linux terminal, without using your mouse.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is wl-copy?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>wl-copy<\/code> command is part of the <code>wl-clipboard<\/code> package, which is a utility for the Wayland graphics server. Wayland is the layer on the Linux operating system that provides everything you see on your screen after you&#8217;ve logged in to a system. The <code>wl-clipboard<\/code> package contains both <code>wl-copy<\/code> for copying and <code>wl-paste<\/code> for pasting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install wl-clipboard<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To make the <code>wl-copy<\/code> (and <code>wl-paste<\/code>) command available on your system, you must install the <code>wl-clipboard<\/code> software package. Before doing that, however, you must confirm that you&#8217;re running Wayland and not its predecessor, X11. You can do this by verifying that <code>echo $XDG_SESSION_TYPE<\/code> returns <code>wayland<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo $XDG_SESSION_TYPE\nwayland<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As long as you get <code>wayland<\/code> back from that command, then you can use <code>wl-copy<\/code> and <code>wl-paste<\/code>. On Fedora and other RPM-based Linux distributions (such as CentOS, OpenSUSE, Mageia, and OpenMandriva), you use <code>dnf<\/code> package manager:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install wl-clipboard<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On Debian and Debian-based distributions, you use the <code>apt<\/code> command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install wl-clipboard<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Using wl-copy<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once it&#8217;s been installed, you can use the <code>wl-copy<\/code> command to copy data to your clipboard. Anything you copy to your system clipboard is available everywhere on your system. You can copy data from one file from a terminal, without ever opening that file in a window of its own, and then paste that data into another application or into another file. That doesn&#8217;t mean that <code>wl-copy<\/code> is the only way to do that, but for now suppose that&#8217;s the workflow you need.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To copy an arbitrary string to your clipboard using <code>wl-copy<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ wl-copy \"hello world\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The string &#8220;hello world&#8221; is now in your system clipboard. You can navigate to any other window on your desktop, right-click and select <strong>Paste<\/strong> (or press <strong>Ctrl+V<\/strong>), and you&#8217;ll get &#8220;hello world&#8221; pasted from your clipboard. Alternately, you can just press <strong>Ctrl+Shift+V<\/strong> in your terminal to paste the string there.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Copy command output with wl-copy<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This can be useful in shell scripts, for example, where you&#8217;re generating output with the expectation that the output is meant to be inserted somewhere else on the system. Suppose your workplace uses two-factor authentication, and you prefer to use a command (rather than a hardware key, or a smart phone app), like <code>pass otp<\/code> to generate tokens. When the <code>pass otp<\/code> command outputs a token, you&#8217;d normally have to select it and copy it with a mouse before you could paste it into the login screen of your workplace intranet. With <code>wl-copy<\/code>, however, you can send the output directly to your system clipboard instead:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ pass otp example.com | wl-copy<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Copy data from a file with wl-copy<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can also copy the contents of a file using the <code>wl-copy<\/code> command so you don&#8217;t have to launch a separate application just to access a file&#8217;s contents. Of course, you&#8217;re still technically &#8220;opening&#8221; the file that you&#8217;re copying, but <code>wl-copy<\/code> does that part, invisibly, for you. Using your terminal, you can redirect the contents of a file into <code>wl-copy<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ wl-copy &lt; example.txt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example, creating a simple file using <code>echo<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo \"This is example text.\" &gt; example.txt\n$ wl-copy &lt; example.txt\n$ wl-paste\nThis is example text.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It doesn&#8217;t have to be just text. You can copy any kind of data. For example, you can copy a JPEG image:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ wl-copy &lt; example.jpg<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You could then paste the image into an application, like GIMP or LibreOffice, that can accept images.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Copying text in a terminal on X11<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>wl-copy<\/code> command is essentially the modern equivalent of the <code>xclip<\/code> command for the X11 graphic server. If you&#8217;re still running X11, you can use <code>xclip<\/code> instead. The syntax is a little different, but the concept is the same.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To copy an arbitrary string to your clipboard using <code>xclip<\/code>, you must pipe data to it and use the <code>-i<\/code> option to read from standard input:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo \"hello world\" | xclip -i<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To copy the contents of a file, you can redirect:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ xclip -i &lt; example.txt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To paste from your clipboard, use the <code>-o<\/code> option:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ xclip -o\nhello world<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Copying from the terminal<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes <code>wl-copy<\/code> is surplus to requirements. If you just need to copy text quickly from a terminal and then back into it, then Bash has built-in functions (like <strong>Ctrl+K<\/strong> and <strong>Ctrl-W<\/strong> and <strong>Alt+D<\/strong>) to copy text and then to &#8220;yank&#8221; it back again (<strong>Ctrl+Y<\/strong>). But when you want to get data from within a terminal and then paste it somewhere else, <code>wl-copy<\/code> is a real convenience. The <code>wl-copy<\/code> (or <code>xclip<\/code>) command can save you several clicks and seconds of launch times.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you spend a lot of time in a Linux terminal, it can become laborious to take your<\/p>\n","protected":false},"author":31,"featured_media":4259,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[321,149,100],"tags":[104,91],"class_list":["post-14513","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-accessibility","category-bash","category-command-line","tag-command-line","tag-linux"],"modified_by":"Jim Hall","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14513"}],"version-history":[{"count":1,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14513\/revisions"}],"predecessor-version":[{"id":14514,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14513\/revisions\/14514"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/4259"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}