Browse current Terminal directory in a web browser

Apr 23, '09 07:30:00AM

Contributed by: robg

While browsing commandlinefu.com (a very useful site, by the way), I found this gem that uses Python to quickly set up a webserver for the current directory in Terminal. First launch Terminal and cd to the directory you'd like to access via your web browser. Then just use this command to start a webserver serving just that folder (and folders within it):

python -m SimpleHTTPServer
The webserver runs on port 8000, so to access the pages in your browser, you'd use http://localhost:8000. If you'd rather run the webserver on another port, just include the port number on the python line: python -m SimpleHTTPServer 8080.

Depending on which browser you're using and the files you're browsing, you may be able to open the files in the browser, or via a helper application. Safari, unfortunately, wants to download file types it doesn't know about, which may not be all that useful.

To quit the server, press Control-C in Terminal (does anyone know a more graceful way to do this; Control-C throws a bunch of errors as it quits?).

Comments (5)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20090423060145578