Home >System Tutorial >LINUX >10 Linux commands and tips to improve productivity, take off immediately!

10 Linux commands and tips to improve productivity, take off immediately!

WBOY
WBOYforward
2024-02-09 13:57:24858browse

In this article, I will show you some useful Linux command tricks. These tips will not only help you save valuable time, but also avoid unnecessary trouble in certain situations, thereby improving your work efficiency.

10个提高生产力的 Linux 命令与技巧,用完直接起飞!51Linux.top

2. Use the tab key to complete

The Tab key must be the most frequently used key in Linux. I believe everyone is already familiar with the basic usage of Linux keys. I will briefly introduce it here.

The Tab key, commonly known as the tab character, is located above the CapLock key on the far left side of the keyboard and below the wavy line key. A tab stop represents four spaces that separate characters. can be used to automatically complete commands , option parameters (the latest Redhat7 supports partial parameter completion), and paths in command line operations.

Completing the command line has two major benefits:

  • It can save the number of input characters and improve input efficiency. For example, if you want to use the systemctl command, directly enter systemc to automatically complete the following tl;
  • If it can be completed, it means that there is no problem with the command or path, and there will be no command not found and No such file or directory errors that are often encountered in Linux systems;

2.1 Use the Tab key to complete commands

If we forget a certain command, for example, we want to use the dmesg command, but we forget the full spelling of this command, we only remember that it starts with dm at the beginning, then we can press the Tab key twice to print out all the instructions starting with dm. I believe everyone can remember the complete command after seeing the printed information!

10个提高生产力的 Linux 命令与技巧,用完直接起飞!In addition to using the Tab key when we forget a command, we can also use the Tab command to reduce our input when a command is too long, thereby improving work efficiency.

2.2 Use the Tab key to complete the path

This is also very common during use. For example, if we want to enter a certain directory, we do not need to type out the entire directory. We only need to enter a few letters, and then click the Tab key, and the system will The full name of the directory will be automatically completed for us.

2.3 Use the Tab key to complete parameters

For example, if we want to view dmesg, but we can’t remember which parameters dmesg can follow, then we can click the Tab key twice in a row and let the system print out the corresponding parameters for us. 10个提高生产力的 Linux 命令与技巧,用完直接起飞!

3. Switch back to the previous working directory

For example, due to work needs, we need to create directories /a/b/c/d/e/f and directories /g/h/i/j/k/l If you want to switch back and forth, then the following command is very suitable for you.

We first use the cd command to enter the /a/b/c/d/e/f directory, and then /a/b/c/d/ Continue to use the cd command in the e/f directory to enter the /g/h/i/j/k/l directory. At this time we can use cd - To achieve switching between two directories, the details are as follows: 10个提高生产力的 Linux 命令与技巧,用完直接起飞!

4. Return to the user’s home directory

~ represents the user's home directory in Linux. We generally have the following three ways to enter this directory:

  1. Use the command: cd /home/username
  2. Use command: cd ~
  3. Use command: cd [Enter]

We can see from the length of the above command that the third way is to directly use cd and then press Enter. It is also the most commonly used switching command, but directly## The #cd method cannot root other paths later. At this time, cd ~ shows its advantages. If we want to access other files in the home directory, we can use ~ instead of /home/username, just follow the absolute path directly.

5. Search for commands you have used

In the process of using Linux, there are often many instructions or directory switches that we need to use frequently. At this time, we can use the used command retrieval function that comes with Linux to retrieve the commands we have used in the past, so as to Improve work efficiency.

The specific search steps are as follows:

1. 按ctrl+r,进入搜索界面;
2. 输入关键字,会弹出最近的一条匹配的记录;
3. 若不是预期的命令,继续按ctrl+r查看下一条匹配的记录;
4. 直接按回车,执行命令;
10个提高生产力的 Linux 命令与技巧,用完直接起飞!

This little trick is very useful, especially when we need to use a certain command frequently. Using it can make our work more effective with half the effort.

6. Move to the beginning or end of the line

When we use Linux, we often find that we have entered a long command, and it turns out that there is an error in front of the command we entered. So what should you do? Should I press Enter and re-enter or use the left and right keys to move the cursor to the wrong place?

Now I will tell you a simpler way to move the cursor to the front of the command. We can use the shortcut key ctrl a to move the cursor to the first letter we entered, and use the command Ctrl e Move the cursor to the end of the input. This is really convenient when you enter the wrong command!

10个提高生产力的 Linux 命令与技巧,用完直接起飞!

Careful friends may have discovered that this is the function of the Home key and End key on the keyboard. Yes, but this shortcut key is really useful on notebooks without Home key and End key. Very easy to use!

7. Quick deletion

Think about it, we mistakenly entered some relatively long content into the terminal: aaaaaaaaaaaaaaaaaaaa But we suddenly don’t want to execute this sentence and want to delete it, what should we do? Of course, it can be achieved by continuing to press the backspace key, but now I give you a shortcut key for faster deletion, which is very awesome to use!

Enter the shortcut key ctrl u to delete all the content in front of the cursor. In addition, there are several practical and commonly used shortcut keys as follows:

  • ctrl k: Delete all content behind the cursor.
  • ctrl a: Move the cursor to the beginning.
  • ctrl e: Move the cursor to the end.

In addition, the command line also has many practical and uncommon shortcuts. Interested friends can learn them by themselves.

八、使用 less读取文件

要查看文件的内容,cat不是最佳选择,特别是如果文件很大。cat命令将在屏幕上显示整个文件。

您可以使用Vi、Vim或其他基于终端的文本编辑器,但是如果您只想读取文件,则 less 命令是更好的选择。

less 命令的基本格式如下:

[root@localhost ~]# less [选项] 文件名

其中选项及其含义如下:

10个提高生产力的 Linux 命令与技巧,用完直接起飞!

使用less您可以在更少的范围内搜索字词,按页移动,高亮与行号等,当然对于关键词的搜索也是非常的好用,你可以把它理解为只能进行查看的vim编辑器。

九、格式化输出

我们在使用某些命令的时候可能遇到过终端打印很乱的情况,比如我们执行mount指令时,他的打印信息想必很多轻微强迫症患者都受不了,真的是非常乱,那么对于这些打印信息很乱的情况我们应该如何处理呢?10个提高生产力的 Linux 命令与技巧,用完直接起飞!

为了看清楚些,我们可以把输出转化为一张表格,只需要在我们执行的命令后面加上 | column –t 就可以了:

mount | column –t
10个提高生产力的 Linux 命令与技巧,用完直接起飞!

看一下显示效果是不是好看多了!

结语

关于Linux的使用技巧还有很多,我目前只终结了几个最常用的几个小技巧,后期有新的内容在进行补充,大家也可以在评论区进行补充!

The above is the detailed content of 10 Linux commands and tips to improve productivity, take off immediately!. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:lxlinux.net. If there is any infringement, please contact admin@php.cn delete

Related articles

See more