Home  >  Article  >  System Tutorial  >  Three commonly used Linux command tools

Three commonly used Linux command tools

WBOY
WBOYforward
2024-01-20 08:15:151266browse

But, actually...you can find a lot of commands in the Linux system. For example, if you just look at the /usr/bin directory, you can find many command execution files (you can run ls/usr/bin/ | wc -l to see how many commands there are in this directory in your system). Of course, they are not all executable files for users, but they can give you a feel for the number of Linux commands. On my Elementary OS system, there are 2029 executable files in the directory /usr/bin. Even though I will only use a small part of it, how can I remember this part?

Fortunately, there are tools and tricks you can use so that you don't have to struggle to remember these commands every day. I'd like to share a few of these tips with you in the hope that you can use the command line a little more efficiently (and save some brainpower in the meantime).

We will start with a tool built into the system, and then introduce two very practical programs that can be installed.

Bash command history

Whether you know it or not, Bash (the most popular Linux shell) keeps a history of the commands you have executed. Want to see it in action? There are two ways. Open a terminal window and press the up arrow key. You should see the commands appear, one after the other. Once you find the command you want to use, you can press the Enter key to execute it directly without modifying it, or press the Enter key after modifying it.

This is a good way to re-execute (or modify and re-execute) a previously run command. I use this feature often. Not only does it save me from having to remember all the details of a command, but it also saves me from having to type the same command over and over again.

Speaking of Bash’s command history, if you execute the command history, you can list the commands you have executed in the past (Figure 1).
Linux 三个命令工具!

Figure 1: Can you find the error in the command I typed?

The number of historical commands saved in your Bash command history can be set in the ~/.bashrc file. In this file, you can find the following two lines:

HISTSIZE=1000
HISTFILESIZE=2000

HISTSIZE is the maximum number of commands recorded in the command history list, and HISTFILESIZE is the maximum number of lines in the command history file.

Obviously, by default, Bash will record your 1000 historical commands. This is already a lot. Sometimes this is also considered a security hole. If you care, you can feel free to reduce this value to balance security and practicality. If you don't want Bash to record your command history, you can set HISTSIZE to 0.

If you modify the ~/.bashrc file, remember to log out and then log in again (otherwise the changes will not take effect).

apropos

This is the first tool I want to introduce to help you memorize Linux commands. apropos (meaning "about") can search Linux help documentation to help you find the command you want. For example, you can't remember what firewall tool your distribution uses. You can type apropos “firewall” and the tool will return the relevant commands (Figure 2).
Linux 三个命令工具!

Figure 2: What firewall are you using?

What if you need a command to operate a directory, but you don’t know which one to use? Typing apropos "directory" will list all commands in the help document that contain the character "directory" (Figure 3).

Linux 三个命令工具!

Figure 3: What are the tools that can operate directories?

apropos tool is installed by default in almost all Linux distributions.

Fish

There is another great tool that can help you remember commands. Fish is a command line shell for Linux/Unix/Mac OS that has some useful features.

  • Automatic recommendation
  • VGA Color
  • Perfect script support
  • Web-based configuration
  • Help document auto-completion
  • Syntax Highlighting
  • and more

The automatic recommendation function makes fish very convenient (especially when you can't remember some commands).

You may think this is fine, but fish is not installed by default. For Ubuntu (and its derivatives), you can install it with the following command:

sudo apt-add-repository ppa:fish-shell/release-2
sudo apt update
sudo apt install fish

For CentOS-like systems, you can install fish like this. Use the following command to add a warehouse:

sudo -s
cd /etc/yum.repos.d/
wget http://download.opensuse.org/repositories/shells:fish:release:2/CentOS_7/shells:fish:release:2.repo

Use the following command to update the warehouse:

yum repolist
yum update

Then use the following command to install fish:

yum install fish

fish may not be as intuitive to use as you think. Remember, fish is a shell, so you need to be logged in before using commands. In your terminal, run the command fish and you will see that you have opened a new shell (Figure 4).

Linux 三个命令工具!

Figure 4: Fish’s interactive shell.

When you start entering a command, fish will automatically complete the command. If the recommended command isn't what you want, press your keyboard's Tab key to browse for more options. If it's exactly what you want, press the right arrow key on your keyboard to complete the command, then press Enter to execute it. When you're done with fish, type exit to exit the shell.

Fish can do more things, but here we only introduce them to help you remember the commands. The automatic recommendation function is enough.

Keep learning

There are too many commands on Linux. But you don't have to remember all the commands. Thanks to the Bash command history and tools like apropos and fish, you don't have to use too much memory to recall the commands that got you done.

The above is the detailed content of Three commonly used Linux command tools. For more information, please follow other related articles on the PHP Chinese website!

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