Are there any command line tools on Linux that allow you to post output from commands or text files directly to a sharing service such as pastebin.com?

  • 2
    My favorite, when paired with a nice shell script, is Sprunge. – DopeGhoti Jan 9 '14 at 5:19
up vote 33 down vote accepted

There are several services that provide this but 2 that are pretty easy to use from the command line are fpaste and pastebinit. These 2 tools link to the sites, paste.fedoraproject.org and pastebin.com.

fpaste

NOTE: This is a Fedora/CentOS/RHEL only option

If you're using any of the Red Hat based distros you can install the package fpaste which gives you a command line tool for posting content to paste.fedoraproject.org.

Basic commands

For basic posting of a single text file you can do the following.

$ fpaste hello_unixnlinux.txt 

The above command will return a URL where your content can now be accessed by others.

...
Uploading (0.1KiB)...
http://ur1.ca/gddtt -> http://paste.fedoraproject.org/66894/89230131

Other commands

There are of course a whole host of other options.

  • paste clipboard: fpaste -i
  • paste sytem info: fpaste --sysinfo
  • dry run: `fpaste --printonly somefile.txt

See the man page, man fpaste for more details.

pastebinit

This is probably the more popular of the 2 tools. It's supported on most of the distros I frequent such as Fedora, CentOS, and Ubuntu just to name a few. It has similar features to fpaste but, you can do a whole lot more with it, for example:

list of services

For starters we can get a list of all the "supported" URLs via the -l switch.

$ pastebinit -l
Supported pastebins:
- cxg.de
- fpaste.org
- p.defau.lt
- paste.debian.net
- paste.drizzle.org
- paste.kde.org
- paste.openstack.org
- paste.pocoo.org
- paste.pound-python.org
- paste.ubuntu.com
- paste.ubuntu.org.cn
- paste2.org
- pastebin.com
- pastie.org
- pb.daviey.com
- slexy.org
- sprunge.us

If you don't bother to select one using the -b switch, it will pick one based on your distro, assuming there's one for it, otherwise falling back to pastebin.com. Notice it also supports fpaste.org, for Fedora, so you could use this tool to cover that pasting service as well.

Posting a simple text file

To post a sample file to pastebin.com.

$ pastebinit -i hello_unixnlinux.txt -b http://pastebin.com
http://pastebin.com/d6uXieZj

Posting code

You can also tell that the content you're pasting is code using the -f switch. For example here's a Bash script. We're also going to name the upload using the -a switch, so that it will show up with the name "ex_bash_1".

$ pastebinit -i sample.bash -f bash -a ex_bash_1 -b http://pastebin.com
http://pastebin.com/jGvyysQ9

A full list of syntax's supported, is covered in the pastebin.com FAQ under this topic titled: For which languages do you offer syntax highlighting?.

For further details be cure to check the man pages, man pastebinit.

Samples

Here are 2 examples of the file that I posted to each service.

fpaste - http://ur1.ca/gddtt

   ss of fpaste

pastebin - http://pastebin.com/jGvyysQ9

   ss of pastebinit

References

  • All of these pale in comparison to Sprunge and Hastebin, IMO. (: – DopeGhoti Jan 9 '14 at 5:20
  • Yes I hear about how awesome Sprunge is, BTW never heard of it until today. There website is like /dev/null, and i find the interface awkward vs. an actual tool such as the ones that I've listed. But that is why we have so many options, so that everyone can pick what they like 8-). Hastebin on the other hand seems a bit more polished, I like that you can host your own instance, the duration of 30 days max is a deal breaker for me. – slm Jan 9 '14 at 5:34
  • Also notice that pastebinit can post to sprunge.us. It's in the list provided by pastebinit -l. – slm Jan 9 '14 at 5:35
  • Please add a note that the example pastebinit command uses your local username as the paste title, that was an unpleasant surprise – Dubslow Dec 14 '17 at 19:08

I like the two command line tools that use curl, listed on the Arch Wiki:

<command> | curl -F 'sprunge=<-' http://sprunge.us

<command> 2>&1 | curl -F 'f:1=<-' ix.io

You can make a simple function to save you having to remember the gory details, like so:

sprung() { curl -F "sprunge=<-" http://sprunge.us <"$1" ;}

You can send to an enhanced URL if you would like syntax highlighting for your code paste. For ix, you append either /ID/ to the URL (http://ix.io/ID/) for default syntax based on auto-detection, or /ID/<language>/ to explicitly set the language for pygments highlighting.

For http://sprunge.us, append ?<language> for the same effect.

  • Can you style those or select a code type or is the syntax highlighting, if any, automatic based on what's pasted? – slm Jan 9 '14 at 5:37
  • Not that I am aware of: it just pastes text. But I have not looked any further into it as that is all I need. – jasonwryan Jan 9 '14 at 5:43
  • Very good, I just wasn't sure if there was more to the curl interface in terms of extra switches etc. that you could include in the request. – slm Jan 9 '14 at 5:45
  • I found it. You can tack on a ? followed by the name of the langugae to get highlighting and line numbers. See this example: sprunge.us/MFMY?bash – slm Jan 9 '14 at 5:52
  • simply the best and most simple solution out there. Love archlinux community :) – nXqd Apr 11 '15 at 8:36

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.

  • There is also pastebin-cli, and Welcome to U&L.SE – eyoung100 Sep 10 '14 at 22:24
  • @solusipse; how long the paste will remain on your server. could it be forever? or is there a link to remove the posts – r004 Nov 9 '14 at 23:23
  • 1
    @r004 As they mentioned in termbin.com "Life span of single paste is one month. Older pastes are deleted." – Veerendra Jun 2 '17 at 8:49
  • Very interesting, but useless if you are behind a firewall with port 9999 blocked. Using nc -v you'll get nc: connect to termbin.com port 9999 (tcp) failed: No route to host. – Pablo Bianchi May 23 at 4:49

I use clitxt as no account is required, and there are no parameters or settings to remember. You just pipe the command to clitxt and it returns a URL. e.g.

root@server3219-old7 [~]# yum -y update | clitxt
https://clitxt.com/t/ad7-1426995329.txt

I wrote this website specifically made for pasting through by curl, since I felt no one should have to remember specific syntax like in sprunge. It's also not only open source, but completely portable so you can easily set up your own "curlpaste" with any other domain. i.e. a private paste server.

curl --data-binary @your-file-here.txt https://curlpaste.com

if you visit the website there is also a web interface that provides other options like read once and delete.

Here is another service that seems to offer this: https://ctrlv.link/

Add the code in a file input.txt and run this command from a terminal window:

$ curl --form "expiration=0" --form "code_type=nohighlight" \
     --form "content=<input.txt" https://ctrlv.link/insert.php

An example with C/C++ code (test.cpp):

$ curl --form "expiration=0" --form "code_type=cpp" \
     --form "content=<test.cpp" https://ctrlv.link/insert.php`

I recently created one command line tool for the pastebin https://notepad.pw/ I use frequently

pasting your file is as simple as

npw -lo filename linkpath

so basically it pastes the content to https://notepad.pw/

The l flag is for live update asin if someone else is viewing the page the page will update without reloading.

the 'o' flag is for overwrite if you don't use it, the content will be appended to the existing one.

You can install the tool via pip

using the command.

pip install npw

Here is the github page.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.