Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy file contents to the clipboard in Linux terminal [closed]

I'm generating an SSH key but I don't know how to copy the key from id_rsa.pub to the clipboard. I'm using BackBox Linux.

like image 844
Ravi Shankar Avatar asked Aug 16 '15 20:08

Ravi Shankar


People also ask

How do I enable copy and paste in Linux terminal?

Use Ctrl+Insert or Ctrl+Shift+C for copying and Shift+Insert or Ctrl+Shift+V for pasting text in the terminal in Ubuntu. Right click and selecting the copy/paste option from the context menu is also an option.

How do I open clipboard in Linux?

For Ubuntu with default GNOME desktop, open terminal either by searching from overview screen or by pressing Ctrl+Alt+T on keyboard. Other Linux, such as Fedora may install the clipboard manager via sudo dnf install gnome-shell-extension-gpaste command.

How do I copy and paste a file in Linux terminal?

To copy a file in a terminal, you use the cp command, which works exactly like the mv command, except that it duplicates the contents of a file rather than moving them from one location to another. As with the mv command, you can rename a file while copying it.

How do I copy files to clipboard?

Open the file that you want to copy items from. Select the first item that you want to copy, and press CTRL+C. Continue copying items from the same or other files until you have collected all of the items that you want. The Office Clipboard can hold up to 24 items.


2 Answers

xclip -sel c < input_file 

will copy the contents of input_file to clipboard. xclip requires installation. To install

sudo apt install xclip 

-sel stands for -selection. c is for clipboard. Interchangeable.

Capable of much more, I advise reading its man page.

There is also xsel. This answer on Unix SE gives a very thorough answer to this exact question.

like image 69
Haggra Avatar answered Sep 23 '22 06:09

Haggra


xclip -selection clipboard -i < fileName

copies the content of file into clipboard

like image 34
Firoj Siddiki Avatar answered Sep 20 '22 06:09

Firoj Siddiki