head

Difference between HTTP HEAD and GET

The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. - Method Definitions

I was a little bit confused when I encoutered the HTTP status code 204, which states that the response MUST NOT include a message body. The HEAD method contains no body content as well. Should I use 204 instead of 200?

The answer is NO. GET method should always return HTTP status code of 200. Since HEAD method is idential to GET, it should return 200 as well. Just keep in mind that the cost of processing both HEAD and GET requests are almost the same.

Insert Text to the Beginning of a File

It is easy to append some text to the end of another file:

$ cat foo >> bar

or even just portion of a file:

$ head -n 2 foo >> bar

but how about to the beginning of a file? Well, it is not that bad to do either:

$ echo "$(cat foo bar)" > bar

just a portion of a file:

$ echo "$(head -n 2 foo)\n$(cat bar)" > bar

Now you can easily add some text such as copyright information to the beginning of another file with one command.