Web server in one line of bash

If you want to quickly save a file through http but you don’t want to install a web server, you can just use netcat.
You can run:

while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html; } | nc -l 8080; done

index.html can be any file you want to serve it.

 

2 thoughts on “Web server in one line of bash

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.