How to Copy File Content to Clipboard on Linux
Table of Contents
On Linux, the command line interface is a powerful tool that can be used to perform a wide variety of tasks. One such task is copying the contents of a file to the clipboard. This can be particularly useful when working with large amounts of data or when you need to transfer data between different applications. In this how-to guide, we will explore how to copy the contents of a file to the clipboard from the command line on Linux.
Using xclip
xclip is a command-line utility for copying and pasting text between the clipboard and the terminal. It is commonly used on Linux and Unix-like operating systems to copy text from the terminal to the clipboard, or to paste text from the clipboard into the terminal.
Step 1: Open Terminal
Open the terminal by pressing Ctrl + Alt + T on your keyboard or by searching for it in the applications menu.
Step 2: Install xclip
To install xclip from the command line:
On Debian/Ubuntu-based distros, run:
sudo apt install xclip
On Fedora/RPM-based distros, run:
sudo dnf install xclip
On Arch-based distros, run:
sudo pacman -S xclip
Once installed, you can use the xclip command to manipulate the clipboard contents.
Step 3: Copy Contents
To copy the content of a file to the clipboard, use the xclip command with the -selection option and the c flag:
xclip -selection c < file.txt
This will copy the contents of file.txt to the clipboard.
You can then paste the contents of the file into another application using the standard paste command (Ctrl+V or right-click and select Paste).
That’s it! You have now copied the content of a file to the clipboard from the command line on Linux.