If you spend a lot of time working from the command line on your server, you will undoubtedly grow tired of having to type the same ones repeatedly in a session. And if you are anything like me, you might grow tired of having to look up long strings of old commands even within a new session. Fortunately, those of you on Linux servers have the “history” command.
An easy way to scroll through the immediate history is to press the up arrow key. You can press it as many times as you want to go through the entire command history. To find something specific, executed several sessions ago, the history command is more efficient. To execute, simply type “history” from the command prompt. To execute a particular command type “!” followed by the number. For example: “!477”.
To write your history to a file, type:
history -w filename, and to append the current history to the end of an already created history file, type
history -a. You can also do the reverse, appending whatever you have in the history file to your current list with
history -r. Finally, if you need an empty list,
history -C will clear it completely. For more information about “history”, type
man history from the command line.
Photo Source: Flickr