Sunday, May 5, 2024
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 4168  / 1 Year ago, tue, march 14, 2023, 4:56:18

Can we copy a string with a command-line and have the ability of pasting it with Ctrl + V shortcut?


More From » command-line

 Answers
3

Yes. You can use xsel tool (a command-line tool to access X clipboard and selection buffers). To install it from terminal, use the following command:



sudo apt-get install xsel


Then, using the following:



<command> | xsel -b


will copy the output of <command> to the clipboard which can be pasted after with Ctrl + V.



For example:



echo -n "string" | xsel -b


or, simple:



xsel -b <<< "string"


will copy to the clipboard the string string (I used -n argument for echo to suppress the trailing newline).



If you want to copy the text from a file named file_name from the current working directory:



cat file_name | xsel -b


or, simple:



xsel -b < file_name

[#28568] Wednesday, March 15, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pilun

Total Points: 270
Total Questions: 100
Total Answers: 94

Location: England
Member since Sat, Feb 13, 2021
3 Years ago
;