Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Browse current Terminal directory in a web browser UNIX
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?).
    •    
  • Currently 1.88 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (8 votes cast)
 
[7,470 views]  

Browse current Terminal directory in a web browser | 5 comments | Create New Account
Click here to return to the 'Browse current Terminal directory in a web browser' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Browse current Terminal directory in a web browser
Authored by: joem on Apr 24, '09 06:13:13AM
Ctrl-C is the graceful way to end many command line programs, especially long-running processes like servers.

[ Reply to This | # ]
Browse current Terminal directory in a web browser
Authored by: Soliman on Apr 24, '09 06:14:19AM
Errr... I'm probably missing something but what's wrong with open -a Firefox .?

[ Reply to This | # ]
Browse current Terminal directory in a web browser
Authored by: palahala on Apr 24, '09 11:21:47AM

Just opening a HTML file from the filesystem in a browser will not serve index.html by default. For example, the following would not work then:

<a href="subfolder">click me</a>
<a href="..">up</a>
Without a HTTP server, this needs to read:
<a href="subfolder/index.html">click me</a>
<a href="../index.html">up</a>

There may be more examples like this, such as <base href=..>.



[ Reply to This | # ]
Browse current Terminal directory in a web browser
Authored by: mono toto on Apr 24, '09 06:15:46AM

also, this allows you to access the file system through a browser from anywhere on your local network.

Just point a browser towards the ip address of your mac instead of localhost (i.e. something like 192.168.1.2:8000) or you could open up the system preferences, click on the Sharing pane and find your computer's name there. mine says "macbook.local" so i'd point the browser towards macbook.local:8000.

I just tried connecting from my iphone. Loading text or images works but streaming media (even just mp3s) isn't supported, i don't think it likes the way this service buffers.

Also beware, I inadvertently tapped on a 600+ page pdf which crashed my phone fairly convincingly.



[ Reply to This | # ]
Browse current Terminal directory in a web browser
Authored by: ll_owl on Apr 28, '09 12:00:37AM

This doesn't work on the default install of 10.4.11. Probably due to the version of PHP natively installed.



[ Reply to This | # ]