Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
1  
My favorite, when paired with a nice shell script, is Sprunge. –  DopeGhoti Jan 9 at 5:19

2 Answers 2

up vote 6 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

share|improve this answer
    
All of these pale in comparison to Sprunge and Hastebin, IMO. (: –  DopeGhoti Jan 9 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 at 5:34
    
Also notice that pastebinit can post to sprunge.us. It's in the list provided by pastebinit -l. –  slm Jan 9 at 5:35

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.

share|improve this answer
    
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 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 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 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 at 5:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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