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


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

Install xclip (sudo apt-get install xclip)

If you want to copy text from a file, run

xclip -sel clip < /path/to/file ( This will copy the text to clipboard)

For more info: http://linux.die.net/man/1/xclip

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.