Shortcut keys to remember in Linux
In Linux, you can not only operate by entering commands, but also operate efficiently using keyboard shortcut keys.
Especially in server operations and troubleshooting, there are situations where you need to enter the same command repeatedly or correct long commands.
Learning shortcut keys for such times will reduce the effort of command entry and allow for smoother operation.
Here, we will introduce shortcut keys that you should remember for Linux terminal operations.
Shortcuts for operating command history
↑ / ↓By using the up and down arrow keys on your keyboard, you can recall commands executed in the past.
↑ → 1つ前のコマンド
↓ → Next command
For example, if you want to execute the command you just ran again, you can recall it simply by pressing the ↑ key.
This is extremely convenient when executing the same command repeatedly.
Shortcuts for moving the cursor
Shortcut Operation Ctrl + a Move cursor to the beginning of the line Ctrl + b Move cursor one character to the left Ctrl + e Move cursor to the end of the line Ctrl + f Move cursor one character to the right
For example, after entering a long command,
sudo systemctl restart nginx
if you want to correct characters in the middle, you can move the cursor quickly using Ctrl + a or Ctrl + e in addition to the arrow keys.
Shortcuts for deleting characters
Shortcut Operation Ctrl + d Delete character at cursor position Ctrl + h Delete character to the left of the cursor Ctrl + k Delete from cursor position to the end of the line Ctrl + u Delete from cursor position to the beginning of the line Ctrl + w Delete the word to the left of the cursor
The ones you should especially remember are Ctrl + u and Ctrl + k.
Ctrl + u → 行頭まで削除
Ctrl + k → Delete to the end of the line
It is also useful when you have entered a long command and decide you want to re-enter it from the beginning.
Paste deleted text
Ctrl + yPastes text that was deleted using Ctrl + k, Ctrl + u, etc.
Ctrl + k → 行末まで削除
Ctrl + y → Paste deleted content
It is also useful if you have deleted something by mistake, so it is handy to remember it as a set.
Search command history
Ctrl + rYou can search for commands you have executed in the past.
Ctrl + r
For example, if you want to find a command you executed previously, such as
systemctl restart nginx
if you press Ctrl + r and type nginx, you can search through your past history.
This is one of the most useful features among Linux shortcut keys.
It is extremely helpful on servers with a large amount of command history.
Navigate command history
Ctrl + p / Ctrl + nYou can navigate through command history just like with the up and down arrow keys.
Shortcut operation Ctrl + p Recall previous command Ctrl + n Recall next command
Basically, using the up and down arrow keys is fine, but this is convenient when you want to edit commands using only keyboard operations.
Completion using the Tab key
TabIn the Linux terminal, you can use the Tab key for command, file name, and directory name completion.
For example,
cd /var/lo
If you type up to this point and press Tab, it will complete the candidate for you.
cd /var/log/
You can complete the input like this.
This is extremely convenient when entering long file names or directory names.
It also has the advantage of reducing input errors.
Summary of Linux Shortcut Keys
The shortcut keys introduced this time are summarized as follows.
Start with these fiveThere is no need to memorize everything at once.
For Linux beginners, it is practical to first memorize the following five.
↑ → 前回のコマンドを呼び出す
Ctrl + r → Search command history
Ctrl + a → Move to the beginning of the line
Ctrl + e → Move to the end of the line
Tab → Complete input
Just being able to use these will make command entry in Linux much easier.
Linux commands are not just about memorizing command names and options; it is also important to operate efficiently by combining them with these shortcut keys.
Let's gradually increase the number of shortcuts you can use while actually operating the terminal.