My question is may be too simple or hard

Is there any way I can copy the content of a file using the command line the same as you do with right click + copy? After that I want to paste what I copied somewhere else, but without creating a new file or use > redirections like cat file1 > file2.

1 Answer 1


What you actually want is to copy strings from a file or command output (or any other output) to the clipboard. In windows powershell scripting you have built in clipboard commands, including such syntax: "some_variable_or_output" |clip.

You can do the same in ubuntu using xclip, but you may need to install this package first. The syntax would be cat file | xclip or some_output | xclip. To paste your clipboard content you'll need to use xclip -o with additional parameters depending on where you want to redirect this output.

If needed, install the package using sudo apt-get install xclip.

  • Thank you for you answer , to explain more , i'm connecting to a server , i need to work on some files on my computer that's why i need ro tranform them to my computer by copying the content , thats why i need a command that work exactly like click rigth + copy ( i don't know if there's any other way ) i can't not use sudi do download xclip because i'm just simple user , Thank you .
    – Reda
    Apr 6, 2020 at 17:36
  • How exactly are you connecting to that server? Are all your commands executed on the server environment? Do you share the server's clipboard with your own computer?
    – Pizza
    Apr 6, 2020 at 17:46
  • im connected to the server as normal user , i can't run sudo command
    – Reda
    Apr 6, 2020 at 20:15
  • I mean what method of remote connection are you using? SSH? You have your personal computer and a server, how do you communicate with it? Many protocols and programs offer shared clipboard. In that case you can take the content, refine whatever you need and copy it to your local clipboard. After that redirect it to wherever you need.
    – Pizza
    Apr 6, 2020 at 21:17
  • Ahhh yes im using SSH remote connection , sorry i didn't know what you mean before
    – Reda
    Apr 7, 2020 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .