All the commands typed by the user are stored in a file named ".bash_history" (for bash) in the Home directory of the User. It is a hidden file as its name is preceded by a dot (.) and therefore you can view this in the File manager only when you hit the Ctrl-H combination. To view this file in "bash" the option -a has to be used with the ls command, i.e., to view this file in the command line interface, the command ls -a has to be used.
This file contains the list of all the commands typed since the system formatting. The operations on the command history such as retrieval or reuse of the commands depends on the contents of this file.
Type history at the command prompt and you will get the last 500 commands used. If you only want to look at the last 10 commands, you could type the command history 10. Commands are remembered so you can reuse them.
You can reuse any command in the history list by typing its number (as shown by the history command), preceded by an exclamation mark (!). If you want a view a file listing of the Documents folder, and ls Documents is command #31 in the list, you could type !31.
Say you’ve just typed a long file-name copy (cp) command, and want to use it again. Typing !cp will find the last line in your history list that begins with cp and reuse it.
Typing two bangs (!!) will cause the last command you typed to be reused. Finally, typing !? and then part of a recently-typed command will cause bash to auto-complete using the nearest match it can find in the history.
Great knowledge about Unix.U have shared valuable points.
ReplyDeleteThanks a lot... I have posted about Vector operations in C++. Tomorrow I will post the implementation also and you can easily learn it.
ReplyDelete