We work in the console quickly and efficiently
In the network you can find a lot of tips on how to work effectively in the console. In most of these articles, the authors talk about the banality of the type "learn hot keys" or "
sudo !!launch the last command under sudo". I will tell you what to do when you have already learned the hot keys and know about
The terminal should start instantly.
How much time do you need to start the terminal? And one more? For a long time, my terminal was launched with the Ctrl + Alt + T combination and I thought it was fast. But when I moved from Openbox to i3, I started to run the terminal through Win + Enter, this combination was in the default config. And you know what? I no longer believe that Ctrl + Alt + T is fast.
Of course, the joke is not in winnings of milliseconds, but in the fact that you open the terminal at the level of reflexes, completely ignoring this.
If you often work in the terminal, but to launch it, reach for the mouse, then try setting up a convenient hot key. I am sure you will like it.
Zsh instead of bash
This is a holivar topic, I know. Zsh is worth putting at least for the sake of three features: advanced autocomplete, typo correction and multiple pathname completition: when one Tab turns
/usr/share/doc. Arch Linux has long been migrated to zsh on its installation disc. I hope that one day zsh will become the default shell in Ubuntu. It will be a historic moment.
Starting to use zsh is generally not difficult. Install it through the package manager and take some ready-made config. I recommend the config used in Arch Linux:
wget -O ~/.zshrc https://git.grml.org/f/grml-etc-core/etc/zsh/zshrc
It remains only to change the default shell to zsh and relogin.
chsh -s $(which zsh)
Everything, continue to work as if nothing happened.
What should be the shell prompt
Shell prompt (command line prompt) - this is the little text that is displayed in the terminal in front of your command. It needs to be customized to your character work. Think of it as a car dashboard. Put there useful information, let it help you navigate. Make it comfortable, especially if you see it every day!
Shell prompt should display the current shell directory. If the current directory is not displayed in the shell prompt, you will have to keep it in your head and periodically check with a command
pwd. Do not do it this way. Keep in mind more important things and do not waste time on the team
If you periodically switch from your user to root, you need an indication of the current user. Often it is important not a specific user name, but its status (normal or root). The easiest way to do this is with color: a red shell prompt at the root, green in its user. So you would not confuse the ruety shell with the usual.
If you connect to servers via ssh, then you need to somehow distinguish your local shell from the server shell. For this, the shell prompt should contain the host name, and even better - the ssh connection indicator.
Shell prompt can show the return code of the last command. Let me remind you that the zero return code means that the command completed successfully, non-zero - the command ended unsuccessfully. The return code of the last command can be recognized by the command
echo $?, but typing it all on the keyboard takes too long. Let the shell prompt be better if the command failed.
If you are working with git-repositories, it will be useful to display the status of the repository in the shell prompt: the current branch and the status of the working directory. Thus you will save time in the teams
git branchnot go wrong branch of the commit.
Someone adds a clock or virtual terminal name (tty), or some arbitrary squiggles to its shell prompt. This is all superfluous. It is better to leave more space for teams.
My shell prompt under different conditions looks like this:
The screenshot shows that the title bar of the terminal window performs a similar task. This is also a dashboard piece and can also be customized.
How to realize all this in his
.zshrc? The variable
PROMPTfor the left prompt is answered , for the right one -
RPROMPT. To determine the status of the user (normal or root) will help the variable
EUID, and the presence of ssh-connection -
SSH2_CLIENT. We receive such preparation:
if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; thenif [[ $EUID == 0 ]]; then PROMPT=... else PROMPT=... fielse# not SSHif [[ $EUID == 0 ]]; then PROMPT=... else PROMPT=... fifi
I deliberately do not specify the code ready for copy-paste, because the concrete implementation is a matter of taste. If you do not want to bother and my screenshot does not cause you disgust, you can take the config from the githaba .
- The required minimum is the current directory.
- Route shell should be clearly visible.
- The username does not carry a payload if you always sit under one user.
- Hostname is useful if you connect to servers over SSH. Not required if you always work on the same machine.
- Unsuccessful completion of the last command is useful to see immediately.
- Status git-repository saves time for teams
git branchis more foolproof.
Active use of command history
You enter most of the commands in your life more than once, which means it would be convenient to pull them out of history instead of typing again. All modern shells can memorize command history and provide several ways to search through this history.
Perhaps you already know how to delve into the history of the combination of Ctrl + R. He has two significant drawbacks:
- To start a search, the input field must be empty. Those. in the case of "I started typing a command - I remembered about the search," I’d have to delete what I’ve started, press Ctrl + R and repeat the input. It is too long.
- Search "forward" by default does not work, because Ctrl + S stops the terminal.
How the fastest and most convenient search works:
- you start typing a command,
- you remember the search,
- You press the hotkey and the shell offers commands from the history that started in the same way.
For example, you want to synchronize a local directory with a remote using
rsync. You already did this a couple of hours ago and want to get the team out of the story. You type
rsync, press a combination once or twice, and the cherished team is ready to launch. You do not need to first enable the search mode in the history, the shell prompt does not change to
(reverse-i-search)':, nothing jumps anywhere. You just go through the teams from the history. Just as with the arrows ↑ ↓ you go through the previously entered commands, only with a filter at the beginning of the command. It is damn convenient and saves a lot of time.
In fish and ipython shells such a search is already assigned to arrows. I think that many people switched to fish just for the sake of this behavior of arrows.
In bash and zsh, by default, this search does not work, it must be turned on by hand. I configured PgUp to search backwards and PgDown to search forward. Far to reach them, but I'm used to it. Perhaps in the future I will reassign to something closer, for example, Ctrl + P and Ctrl + N.
For bash, add a couple of lines to
"\e[5~": history-search-backward "\e[6~": history-search-forward
If you have taken ready
zshrc, then the search there most likely has already been assigned to PgUp and PgDown. If not, add in
bindkey"^[[5~"history-beginning-search-backward # pg upbindkey"^[[6~"history-beginning-search-forward # pg down
Curiously, over time, I began to write teams at the rate that I will later raise them from history. Here are a few tricks:
Combining commands that are always executed one after another
ip link set eth1 up && dhclient eth1 mkdir /tmp/t && mount /dev/sdb1 /tmp/t
Absolute paths instead of relative ones allow you to run a command from any directory:
vim ~/.ssh/configinstead of
systemd-nspawn /home/chroot/stretchinstead of
systemd-nspawn stretch, etc.
Wildcard substitution makes teams more versatile. I usually use with
chown root:root /var/www/*.sq && chmod 644 /var/www/*.sq
I will list the required minimum.
Alt +. - substitutes the last argument of the previous command. You can also type a sequence
Ctrl + A, Ctrl + E - go to the beginning and end of the edited command, respectively.
Ctrl + U, Ctrl + Y - cut everything to the clipboard, paste from the buffer. Rescues when you type a complex command, and then you realize that you need to do another before it. Hmmm, where to hide the current input? Here and hide.
Ctrl + W - erases one word to the left of the cursor. If you hold and hold, quickly clears the command line. By default, the text is not deleted, but placed in the buffer (which for Ctrl + Y).
Ctrl + K - deletes from the cursor to the end of the line. Ctrl + A, Ctrl + K quickly clears the command line.
PgUp, PgDown, Ctrl + R - search by history.
Ctrl + L - clear the terminal.
I'll tell you about a small setting that allows you to scroll faster, move through the text or erase. What do we do when we want to erase something long? Hold Backspace and watch the cursor run backwards, taking the extra letters. What happens when this happens? When you press Backspace, one character is erased, then there is a slight delay, then auto-repeat is triggered: Backspace removes the characters one by one, as if they are constantly knocking on it.
I recommend adjusting the delay and frequency of auto-repeat to the speed of your fingers. The delay before the auto-repeat is triggered is needed when you want to delete only one character - it gives you time to release the key. Too long delay makes auto retry waiting. Not long enough to annoy, but enough to slow down the transfer of thoughts from the head to the computer. The higher the repetition rate, the faster the text is erased, and the more difficult it is to stop this process in time. The essence of the setting is to find the golden mean.
So, the magic command:
xset r rate 190 20
190 is the delay in milliseconds,
20 is the frequency in number of repetitions per second.
I recommend starting with these values and gradually reducing the delay until the occurrence of false positives, then slightly back. If you set a very short delay, then the keyboard will become impossible to use. You have to restart the X server or the entire computer. So be careful.
To save the settings, add this command somewhere in the X autostart.
Process completion indicator
I often have to run long processes: some fat backup, copying over the network, unpacking / packing archives, building packages, etc. Usually I start such a process, switch to another task and periodically glance whether my long process has completed. It happens that I immerse myself in work and forget about it. The solution is to add a process completion notification that will lead me out of a trance.
You can use different tools for this: notify-send, dzen2, beep, aplay. All of them are good in their own way, but do not work on ssh. Therefore, I use the terminal beep:
long-running-command; echo $'\a'
In ASCII, there is a 0x7 character called bell . It is designed to beep PC-speaker. The PC speaker is incompatible, it is not everywhere, and it is not even heard in the headphones. Therefore, some terminals use the so-called visual bell. I use urxvt, and it does a visual bell by turning on the urgency flag. This is when the window informs you that it needs attention.
You can check right now how your terminal responds to the bell symbol:
sleep 3; echo $'\a'
Three seconds is given so that you can switch to another window, otherwise it may not work.
Unfortunately, visual bell through urgency is not in all terminals. I checked the most popular.
|terminal||visual bell via urgency|
|konsole||included in the settings|
|xfce4-terminal||included in the settings|
|cool retro term||not|
echo $'\a'too long, so I did an alias
rmshould always work recursively. Argument
-ris just a bad legacy! You
cpcan still find an excuse:
cp * foodir
will copy only files to foodir, and with a key it
-rwill think that you have decided to copy foodir into yourself. But how often do you need this feature?
scpthere are no excuses, they are just boring! A similar situation with the key of
mkdir. So feel free to add to
alias cp='cp -r'alias scp='scp -r'alias rm='rm -r'alias mkdir='mkdir -p'
Wow, how I used to live without it! You can go even further and add
rm, but at your own peril and risk. I'm still holding back.
lsYou probably already use different variations , because these are the most popular aliases.
alias ls='ls -F --color=auto'alias la='ls -A --color=auto'alias ll='ls -l --color=auto -h'alias lla='ll -A --color=auto -h'
Well, color grep is much more pleasant than colorless:
alias grep='grep --colour=auto'
Do not forget that aliases do not work in scripts! There you must specify all the keys.
Blind printing method
No matter how trite it may be, but the blind ten-finger print method allows you to print faster. It will be hard at first, but over time you will accelerate to unprecedented speeds.
To master the blind printing method is best on vacation or on vacation, when no one is rushing you. In the learning process in no case be in a hurry. Your task is to remember where the letter is located. And not so much the brain as the muscles. It is better to type slowly, but without errors, than quickly with errors. Remember: the masters achieve high speeds not at the expense of fast fingers, but because they do not make mistakes.
You should not get carried away at first clavogonkami. It is psychologically difficult to stay cool during the competition. Learn on simulators. Well, when the simulator offers words that can be mentally uttered. I studied on online simulators vse10 and typingstudy . The famous simulator "Solo on the Keyboard" seemed confusing to me.
It is worth starting with the central row of "fyvaprolge". Only after you remember where the key is located, it is worth moving on. Only after that.
Take breaks. Let's rest your mind and fingers. You feel that mistakes have come down - it's time to take a break.
At first, I mastered the blind method of printing in Russian and decided on acceleration. Now I improve the skill in the English layout.