There are several main files that are used to configure shell on a system:
- system-wide configuration files
bash.bashrc
(or simplybashrc
) andprofile
, which can be found in/etc/
folder (on Windows it's located inside Git installation directory, such asC:\Program Files\Git\etc
) - user-specific dotfiles
bashrc
and.bash_profile
or.profile
, which are located in the user's home folder (they are covered in Lab 3).
Another file that affects user experience of working with command line is .inputrc
(and its system-wide /etc/inputrc
counterpart). This is the configuration file of Readline — a library which provides line-editing and history capabilities for many command-line utilities, including bash.
I really can't stress enough how useful these hotkeys are in the everyday work. Take some time to remember them.
Tab
– autocompleteCtrl + l
– clear the screenCtrl + k
– cut forwards to the end of the lineCtrl + u
– cut backwards to the start of the lineAlt + d
– cut forwards to the end of the current wordAlt + Delete
/Ctrl + w
– cut backwards to the start of the current wordCtrl + _
– incremental undo for editing commandsCtrl + y
– paste the last deleted snippet (top of the kill ring)Ctrl + t
– transpose charactersAlt + t
– transpose wordsAlt + u
– uppercase the current wordAlt + l
– lowercase the current wordAlt + c
– capitalise the current wordAlt + #
– – comment the current line and start a new one
Let's start with the single most important improvement that you can make to your command line experience — enabling incremental history search.
Create .inputrc
file in your home directory:
touch ~/.inputrc
Add the following snippet to it:
# Up/down arrows to search history
"\e[A": history-search-backward
"\e[B": history-search-forward
After you reload the console you will be able to search history incrementally — that is, filtering the commands that you want to see by providing a few of the starting characters of those commands. This makes a huge difference to your productivity on command line, as repeating the commands that you use often now takes only several keystrokes. The longer you use console to interact with your system, the better bash history works for you.
You can also use Ctrl + ← / →
and Alt + ← / →
to skip words:
# Ctrl + left/right arrows to skip words
"\e[1;5C": forward-word
"\e[1;5D": backward-word
# Alt + left/right arrows to skip words
"\e\e[C": forward-word
"\e\e[D": backward-word
Ignore case in Tab-completions (on Windows this is the default):
set completion-ignore-case on
Add some colour to Tab-completions:
set colored-stats on
Make sure we don't output everything on 1 line:
set horizontal-scroll-mode Off
Show all possible matches immediately, without having to hit Tab
twice:
set show-all-if-ambiguous on