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?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityYou'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.
Note: If your problem involves the Software Center, Update Manager or
apt-get
not working, you may have to use the Alternate Method near the bottom of this answer.
Press the Ctrl+Alt+T keys together (at the same time) to start the terminal. This will work for everyone using regular Ubuntu, but if you're using...
sudo apt-get install pastebinit
and press EnterWhen asked Do you want to continue?, type Y
and press Enter, and wait for the prompt (user@machine
) to return.
/etc/apt/sources.list
, while a command may simply be something like dmesg
or grep -i failed /var/log/auth.log
. The answer or comment will tell you explicitly if it's a file or a command.Now, for a file, type pastebinit
in the terminal, follow with a space; then right-click on the cursor and click on Paste to paste the filename you copied.
Press Enter, and after a few seconds you will see a link of the form http://paste.ubuntu.com/
as shown below. Move your mouse over it, and it will be underlined -- then right-click and click on Copy Link Address to copy it link to your clipboard:
But for a command, copy and paste the command in the terminal first, and then type
| pastebinit
after it, and press Enter (see screenshot below)
You can also paste the link into your browser's address bar, or click on the link after you've added/edited it to AskUbuntu, to view it on pastebin. It will look similar to this:
This may be useful if you are having a problem with Software Center, Update Manager or apt-get
and cannot install pastebinit; it only works for files, not commands.
Open a terminal as shown in Step 1 and type gedit
, followed by a space, and then right-click to paste the filename as in Step 3 and press Enter
leafpad
instead of gedit
; Kubuntu users type kate
The editor will open with the file:
Click anywhere inside the editor window, and press Ctrl+A. All the text should now be highlighted in another color:
Now press Ctrl+C (or the Copy button, if you know where that is) to copy the entire file to the clipboard.
Go to your browser, and open paste.ubuntu.com. Type your name/nickname in the Poster: box; then click in the Content: box and press Ctrl+V to paste the text you just copied from the editor in there:
Click on the Paste button, and in a few seconds you'll see the text you pasted:
Select the address shown in the address bar (highlighted orange above), copy it with Ctrl+C, and then go back to AskUbuntu and paste it in as explained in Step 4.
cat file | pastebinit
;)
Usually, bash has a utility called "script" that creates a sub-terminal that writes to file. For example, if you do:
script ask-ubuntu.txt
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 xclip
with this:
sudo apt-get install xclip
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 copy the output of a command to the clipboard:
command | xclip -sel clip
To copy the contents of a file:
xclip -sel clip < file
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:
cat /etc/fstab | nc termbin.com 9999
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:
echo 'alias tb="nc termbin.com 9999"' >> .bashrc
Now sharing will be much simplier:
uname -a | tb
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
eightnoteight@mr:~$ date > date.txt
eightnoteight@mr:~$ echo yes! it really works with echo too > echotest.txt