Autocomplete commands from history
To autocomplete commands that you have entered in history, follow these steps and you do not have to remember stuff you write in terminal any more, great time saver.
Edit the .inputrc file
$ sudo gedit ~/.inputrc
then add the following lines to the file (file is empty by default):
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char
This is a very useful and powerful feature, that will saves you a lot of time, to find a previous command, enter the first 2 or 3 letters and the Up arrow key, it will autocomplete the command once you have typed it in the past.
Looking four commands you entered previously into the CLI
To scroll trought the commands you have entered previously, use Up or Down keys on your keyboard.
Displaying previous commands, that you have typed in the CLI
Enter the history command to display a complete and numbered list of commands from history.
$ history
or use less option for scrollable list
$ history | less
or search for ‘something’ in the history file and expect only the matching lines as a outcome.
$ history | grep something
Search in the list of history of commands
Press Ctrl + r and as you start typing characters one by one, a match of the command entered by you in past will be displayed on the right of the semicolon. Use backspace to delete last characters if you make a mistake.
Run specific command from the numbered history list
When you enter the history command, you will get output with number and a line, to run a command with a specific number, use ! followed by the number of the command in the line.
$ !4331
Editing the history file
History of commands is stored in hidden file called .bash_history in users home folder, /home/username/.bash_history
$ sudo gedit ~/.bash_history
Autocomplete commands or filenames
Use Tab key on your keyboard to autocomplete the command for you, if there are more option, you will be served with a list, otherwise your command will be completed for you, this is one of the biggest time-savers. Alt + c capitalizes the character over the cursor and moves to the end of the word.