How can I easily share the output of a command or a text file with others?
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
- You will get a window with a solid background, showing your username and your computer name, like the below (size/colors may differ!):
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.
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 likedmesg
orgrep -i failed /var/log/auth.log
. The answer or comment will tell you explicitly if it's a file or a command.
- A filename may look something like
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)- 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.
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:
- 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:
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 ofgedit
; Kubuntu users typekate
- Lubuntu users type
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.
- 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.