OSX command line - how to save commands automatically

I would like to save commands entered into a terminal instance for every console window I bring up. I am envisioning a directory that each time a terminal is opened a new file is created. As I enter in commands like ‘ls’ or ‘pwd’ it would write those commands to that file. Is there a way to do this? I would also like to write it to a database directly or web url through a POST if possible. Is there a way to add code snippets in a terminal window that takes action like this?
OSX command line - how to save commands automatically
 
 
Q