Ubuntu: How can I easily share the output of a command or a text file with others?


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.

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.

1. Start the terminal

  • The terminal allows you to interact with your system by typing commands, instead of using the mouse/cursor. It's not hard to use when you have instructions, and can make some tasks very easy to accomplish.
  • 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...

    • Lubuntu: Click on the Start button, go to Accessories, and click on LXTerminal
    • Xubuntu: Right-click anywhere on the desktop, and click on Open Terminal Here
    • Kubuntu: Click on the Start button, type konsole in the Search box, and click on Konsole

    How to start a terminal on L/X/K-ubuntu

    • You will get a window with a solid background, showing your username and your computer name, like the below (size/colors may differ!):

    enter image description here

2. Install pastebinit, a small tool to paste text from the terminal

  • In your terminal, type sudo apt-get install pastebinit and press Enter
  • Enter your password and press Enter (what you type won't show, don't worry)
  • When asked Do you want to continue?, type Y and press Enter, and wait for the prompt (user@machine) to return.

    enter image description here

3. Pastebin the file or command and paste its URL on AskUbuntu

  • Go back to your browser, select the exact filename (or command) whose content you were asked to paste, and press Ctrl+C to copy it to the clipboard.
    • A filename may look something like /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.

    enter image description here

  • 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:

    enter image description here

  • 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)

    • The | symbol may be obtained by pressing Shift+\, which is usually below the Backspace key.
    • Move your mouse over the link--it will be underlined--right-click and Copy Link Address as explained above. enter image description here

4. Paste the link into your AskUbuntu question/comment

  • Go back to your browser, and add a comment (or edit your question) with the Pastebin link - just press Ctrl+V to paste it. Save the edited question or add the comment, and that's it!

5. Optional: View your pastebin link, and only paste selected lines from it into your AskUbuntu

  • 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:

    enter image description here

    • Notice the line numbers. You can also copy and paste selected/requested lines from here directly into your AskUbuntu question.
    • Please enclose the pasted lines with the <pre> and </pre> tags as shown below, so that it appears as separate lines in the question instead of being jumbled together: enter image description here

Alternate way to pastebin a file using an editor

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.

  • Select and copy the filename from AskUbuntu into your clipboard with Ctrl-C.
  • 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

    • Lubuntu users type leafpad instead of gedit; Kubuntu users type kate
  • The editor will open with the file:

    enter image description here

  • Click anywhere inside the editor window, and press Ctrl+A. All the text should now be highlighted in another color:

    enter image description here

  • 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:

    enter image description here

  • Click on the Paste button, and in a few seconds you'll see the text you pasted:

    enter image description here

  • 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.

  • Alternately, select a few lines, copy them and then paste them in AskUbuntu as explained in Step 5.


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:

  • Ctrl+ Shift+ c (Copy)
  • Ctrl+ Shift+ v (Paste)

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


eightnoteight@mr:~$ date > date.txt  eightnoteight@mr:~$ echo yes! it really works with echo too > echotest.txt  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »