Keys shortcuts in Linux and Screen/Byobu session
I’m fascinated with shortcuts – I can’t understand why wouldn’t you want to learn them, cut the process and get the job done in a fast speed.
So, I was going like usually though my duties and had to dig a bit through one of our servers and got annoyed by some typing difficulties and I told myself enough is enough you have to do something about it.
Bash uses a library (a shared collection of routines that different programs can use) called Readline to implement command line editing. We have already seen some of this. We know, for example, that the arrow keys move the cursor, but there are many more features. Think of these as additional tools that we can employ in our work. It’s not important to learn all of them, but many of them are very useful. Pick and choose as desired.
Note: Some of the key sequences below (particularly those that use the ALT key) may be inter-cepted by the GUI for other functions. All of the key sequences should work properly when using a virtual console.
Lists the keys used to move the cursor.
Key | Action |
---|---|
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. |
Cutting and Pasting Text
The Readline documentation uses the terms killing and yanking to refer to what we would commonly call cutting and pasting. The next table lists the commands for cutting and pasting. Items that are cut and stored in a buffer called the kill-ring.
Text Editing Shortcuts
Key | Action |
---|---|
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 |
Ok, that was a bit boring but look at this nice hacks:
// Double !! - will repeat the last command. www-data$ !!
and the best hack (i love this one):
// Go to previous location path www-data$ cd -
I bet there’s not so many who know about it :D.
Before starting you job in command line a tip from my experience:
If you know you have a lot of work to do in command line – follow my advice and open a screen session. You can do by using screen or byobu. Mostly I’m working with the last one as is a configuration layer on top of screen or tmux so they have almost the same commands.
There’s some easy commands to start the session like:
- screen/byobu -S <session name>
Detach from screen/byobu session:
- Ctrl+a d (you just let the session to do it’s job in backend, neat one)
Resuming the session, if you have one session only it enough to input screen/byobu otherwise:
- screen -r <name>
List all ative sessions:
- screen -ls
Now this will be the small pack to ensure you don’t have a disaster when your ssh connection goes away.
Lots from upper is from an awesome book called: The Linux Command Line.