how to save history of commands in linux

C++
 history > history.txt
# it will save the history of used commands in linux terminal.
Source

Also in C++: