I recently asked a question on Ask Ubuntu (or somewhere else), and a comment or answer asks me to paste the contents of some file or the output of a command to troubleshoot my problem.
How do I do that?
|
I recently asked a question on Ask Ubuntu (or somewhere else), and a comment or answer asks me to paste the contents of some file or the output of a command to troubleshoot my problem. How do I do that? |
||||
|
|
How to easily share all or part of some text file (or the output of a command)You'll paste the file or command output to Ubuntu's "pastebin" service, and then allow others to look at it by simply sharing a link, or use it yourself to further copy and paste a few lines into your question.
1. Start the terminal
2. Install pastebinit, a small tool to paste text from the terminal
3. Pastebin the file or command and paste its URL on AskUbuntu
4. Paste the link into your AskUbuntu question/comment
5. Optional: View your pastebin link, and only paste selected lines from it into your AskUbuntu
Alternate way to pastebin a file using an editorThis may be useful if you are having a problem with Software Center, Update Manager or
|
|||||||||||||||||
|
|
Usually, bash has a utility called "script" that creates a sub-terminal that writes to file. For example, if you do:
It will create a new bash prompt, and all input and output will be stored in the file ask-ubuntu.txt when you exit the sub-shell. You can then obviously copy the contents of the file, or upload the file, wherever you need it. |
|||||||||
|
|
If you don't necessarily want to share the output on Pastebin, another option is to use xclip. It takes what you give it on the standard input and puts it optionally in the X selection, or the clipboard. First, install
By default, xclip puts copied text into the x selection instead of the clipboard. Since standard copy and paste functions use the clipboard, we'll have xclip use it too instead of the default.
To paste, use the standard shorcut Ctrl+V, or right click and select paste. |
||||
|
|
|
I needed something to share terminal output even when X server wasn't loaded so I created this service: termbin.com. The only thing you need is netcat, then you can easily share with anyone anything that can be shown in terminal, there's example:
After running this command you'll get in response url address with text file. To make your life easier you can add such alias to your .bashrc file:
Now sharing will be much simplier:
You can get saved ones for example by using curl. You'll find more examples on termbin.com. You can host your own server as well, there is github repository: https://github.com/solusipse/fiche. If you want to make it private, don't forget to set whitelist parameter. |
||||
|
|
|
I may have missed something in the excellent answers above, but if what you want to copy is relatively small, all you have to do is get it displayed on your screen (e.g. cat filename in a terminal or opening the file in a editor), highlight the desired text with the mouse and copy it into your clipboard. Once there, you can just paste it into your reply on the web or into an email, etc. Using pastebin or pre tags is important with longer material so that it gets separated out from the rest of the question/answer so that it doesn't distract people from the rest of the post. |
|||
|
|
|
I may have misunderstood the question, but I've found that in the terminal you can use the following after selecting what needs to be copied with your mouse:
Obviously once in AskUbuntu or whatever forum with your browser you use your regular Ctrl + C and Ctrl + V. This might be a new addition in 12.04 seeing as I'm a relatively new user and noone else seems to have mentionned it beforehand, but to me this seems an easier and quicker option rather than having to install software or running command lines, especially for relatively new users. Hoping this helps complement Izx's incredibly complete answer. |
||||
|
|
|
I wonder why no one mentioned this SOLUTION. If you wanted the output to be compiled into a text file you just have to add " > filename.txt" ( without quotes) to your terminal command examples
|
||||
|
|