On-the-Fly Web Server

Most of you have a web server installed on your network somewhere. In fact, most of you probably have several. In a pinch, however, getting to the web directory can be difficult. Thankfully, there's a super-simple, incredibly awesome one-liner you can type to get a functional web server running and serving out your current directory:


python -m SimpleHTTPServer

That one-liner (or the Python 3 alternative, python -m http.server) will start a web server on port 8000, serving files from your current directory. Usually pressing ^C will stop the server, but if not, some more command-line fu will stop the process as well:


kill `ps | grep SimpleHTTP | grep -v grep | awk '{print $1}'`

It's possible to change the port by adding it after the SimpleHTTPServer, but since you're running as a user, you won't be able to run on a privileged port.

(Thanks to jafraldo on http://www.commandlinefu.com for the kill script.)

Shawn is Associate Editor here at Linux Journal, and has been around Linux since the beginning. He has a passion for open source, and he loves to teach. He also drinks too much coffee, which often shows in his writing. You can contact Shawn via e-mail, ljeditor@linuxjournal.com.

Load Disqus comments

Corporate Patron

Linode Logo

 

Pulseway Logo

Limited Time Offer

September Cover

 

Take Linux Journal for a test drive. Download our September issue for FREE.

Topic of the Week

Cloud

The cloud has become synonymous with all things data storage. It additionally equates to the many web-centric services accessing that same back-end data storage, but the term also has evolved to mean so much more.