We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – How To Copy and Paste Text Content from Linux Terminal

Learn how to – How To Copy and Paste Text Content from Linux Terminal.

You looking for an easy way to copy and paste text content using Linux command line interface?. This guide will show you the simple ways of copying and pasting contents from a clipboard all in a Linux command line.

Using Xorg Display server

For those using the Xorg display on their Desktop, the best tool for copy and pasting on command line is xclip. This tool can be installed easily using the commands below.

### Ubuntu / Debian ###
sudo apt update
sudo apt -y install xclip

### Fedora / CentOS/RHEL 8 ###
sudo dnf -y install xclip

### Arch / Manjaro ###
sudo pacman -S xclip

Using Xclip

After installation, refer to below few examples to copy and paste contents on Linux terminal.

  • Copy command execution output
top | xclip
uptime | xclip
  • Copy file content to clipboard
xclip /etc/os-release
xclip -sel clip /etc/os-release
  • Cat file contents and pipe to copy
tail -n 100 /var/log/messages | xclip -sel clip
cat myfile.txt | xclip -sel clip
  • Copy with redirection key
xclip -sel clip < /etc/passwd

  • Save copied content to file
xclip -o -sel clip > mydata.txt

Using Wayland Display server

For Wayland display server, we’ll use wl-clipboard. The wl-clipboard project implements two command-line Wayland clipboard utilities, wl-copy and wl-paste, that let you easily copy data between the clipboard and Unix pipes, sockets, files and so on.

Installing wl-clipboard

### Debian / Ubuntu ###
sudo apt update
sudo apt -y install wl-clipboard

### Fedora ###
sudo dnf -y install wl-clipboard

### Arch / Manjaro ###
sudo pacman -S  wl-clipboard

Usage:

  • Copy output of a command to clipboard
uptime | wl-copy
ls /etc | wl-copy
  • Copy text message
wl-copy "Hello world.."
  • Copy file contents to clipboard
wl-copy < /etc/passwd

# Image
wl-copy < ~/Pictures/photo.png
  • Paste contents in clipboard to file
wl-paste > clipboard.txt
  • Copy previous command
wl-copy "!!"
  • Clear the clipboard
wl-copy -c

Other interesting tools to check:

  • xsel — Command-line program for getting and setting the contents of the X selection.

Also check:

Cart

Your Cart is Empty

Back To Shop