-
clear
- Clear the screen. -
history
- Display the contents of the history list.
-
CTRL-A
Move cursor to the beginning of the line. -
CTRL-E
Move cursor to the end of the line. -
CTRL-F
Move cursor forward one character; same as the right arrow key. -
CTRL-B
Move cursor backward one character; same as the left arrow key. -
ALT-F
Move cursor forward one word. -
ALT-B
Move cursor backward one word. -
CTRL-L
Clear the screen and move the cursor to the top left corner. The clear command does the same thing.
-
CTRL-D
Delete the character at the cursor location. -
CTRL-T
Transpose (exchange) the character at the cursor location with the one preceding it. -
ALT-T
Transpose the word at the cursor location with the one pre ceding it. -
ALT-L
Convert the characters from the cursor location to the end of the word to lowercase. -
ALT-U
Convert the characters from the cursor location to the end of the word to uppercase. -
CTRL-K
Kill text from the cursor location to the end of line. -
CTRL-U
Kill text from the cursor location to the beginning of the line. -
ALT-D
Kill text from the cursor location to the end of the current word. -
ALT-BACKSPACE
Kill text from the cursor location to the beginning of the cur rent word. If the cursor is at the beginning of a word, kill the previous word. -
CTRL-Y
Yank text from the kill-ring and insert it at the cursor location.
bash
maintains a history of commands that have been entered. This list of commands is kept in your home directory in a file called .bash_history
.
To view history of commands
himanshu in ~: history
himanshu in ~: history | less # for viewing in less
Or simply press up arrow to start looking the most recent commands you have entered. By default, bash stores the last 500 commands you have entered.
Let’s say we want to find the commands we used to list /usr/bin.
himanshu in ~: history | grep /usr/bin
1711 ls /bin /usr/bin | sort | less
1712 ls /bin /usr/bin | sort | uniq | less
1713 ls /bin /usr/bin | sort | uniq -d | less
1738 ls /usr/bin | tail -n 5
1742 ls /usr/bin
The number 1738 is the line number of the command in the history list.
We could use this immediately with another type of expansion called history expansion. Using an !
mark.
himanshu in ~: !1738
ls /usr/bin | tail -n 5
zipsplit
zjsdecode
zless
zmore
znew
bash
also provides the ability to search the history list incrementally. This means that we can tell bash
to search the history list as we enter characters, with each additional character further refining our search. To start an incremental search, enter CTRL-R
followed by the text you are looking for. When you find it, you can either press ENTER
to execute the command or press CTRL-J
to copy the line from the history list to the current command line.