如何从命令行轻松将文本片段上传到类似Pastebin的服务中

2023-04-12 01:33:00 命令行 片段 传到

If you want to easily upload text snippets to a service like Pastebin from the command line, there are a few ways to do it.

One way is to use a command like curl or wget. For example, you could use curl to post your text to a Pastebin-like service like this:

curl -d "api_dev_key=YOUR_API_KEY&api_option=paste&api_paste_code=YOUR_TEXT_HERE" https://pastebin.com/api/api_post.php

Replace YOUR_API_KEY with your actual API key from the service, and YOUR_TEXT_HERE with the text you want to upload.

If you have the Python interpreter installed, you can also use a Python script like this one:

#!/usr/bin/env python import sys import urllib2 def main(): if len(sys.argv) != 4: print "Usage: %s api_key text_file output_file" % sys.argv[0] sys.exit(1) api_key = sys.argv[1] text_file = sys.argv[2] output_file = sys.argv[3] with open(text_file, "r") as f: text = f.read() data = urllib2.urlencode({ "api_dev_key": api_key, "api_option": "paste", "api_paste_code": text }) u = urllib2.urlopen("https://pastebin.com/api/api_post.php", data) response = u.read() with open(output_file, "w") as f: f.write(response) if __name__ == "__main__": main()

Save the above script to a file, make it executable (e.g. with chmod +x), and then you can run it like this:

./pastebin.py YOUR_API_KEY YOUR_TEXT_FILE OUTPUT_FILE

Replace YOUR_API_KEY, YOUR_TEXT_FILE, and OUTPUT_FILE with the appropriate values.

There are also a few command-line utilities that can be used to interact with Pastebin-like services. For example, there's a utility called pastebinit that can be used to easily upload text to a service like Pastebin. To install it on Ubuntu, you can use apt-get:

sudo apt-get install pastebinit

Once it's installed, you can use it to upload text to a service like Pastebin like this:

pastebinit -i YOUR_TEXT_FILE -b https://pastebin.com

Replace YOUR_TEXT_FILE with the path to the file containing the text you want to upload.

Another utility that can be used for this purpose is pb. To install it on Ubuntu, you can use apt-get:

sudo apt-get install pb

Once it's installed, you can use it to upload text to a service like Pastebin like this:

pb YOUR_TEXT

Replace YOUR_TEXT with the text you want to upload.

There are also a few GUI applications that can be used to interact with Pastebin-like services. For example, there's an application called Gisto that can be used to easily upload text snippets to a service like Pastebin. To install it on Ubuntu, you can use apt-get:

sudo apt-get install gisto

Once it's installed, you can launch it from the Unity Dash or GNOME Shell Activities Overview.

Another application that can be used for this purpose is Pastie. To install it on Ubuntu, you can use apt-get:

sudo apt-get install pastie

Once it's installed, you can launch it from the Unity Dash or GNOME Shell Activities Overview.

相关文章