This article has participated in the call for good writing activities, click to view: back end, big front end double track submission, 20,000 yuan prize pool waiting for you to challenge!

A lifelong learner, practitioner and sharer committed to the path of technology, a busy and occasionally lazy original blogger, an occasionally boring and occasionally humorous teenager.

Welcome to dig friends wechat search “Jie Ge’s IT journey” attention!

How to quickly recall a Forgotten Linux command?

preface

On The Linux operating system, I can’t remember too many commands. But that’s okay. It’s not possible, it’s not necessary, and it’s not always going to work. Sometimes I even stare at a Linux terminal to find a file or because I can’t remember what to do with a command. We tried to type commands on a Linux terminal, but we still couldn’t get the output we wanted.

So, use the Apropos command and the BASH history command to quickly recall forgotten Linux commands.

Apropos — Quick recall of forgotten Linux commands

Apropos command: a Linux command that locates the name and description section of a man page with a specified keyword search.

If you can’t remember which command can print the contents of the directory, you can list some commands that match the search string by executing apropos “list directory” command. As shown in the following output, dir, ls, vdir can list the contents of the directory. This will greatly increase your productivity.

# apropos "list directory"
dir                  (1)  - list directory contents
ls                   (1)  - list directory contents
ls                   (1p)  - list directory contents
vdir                 (1)  - list directory contents
Copy the code

For example, if you want to search for a string about ABC, you can use the command: apropos “ABC” to search for any string, but the search string should be accurate enough.

# apropos "abc"
XmTabCreate          (3)  - A convenience function that creates a tab stop
XmTabListTabCount    (3)  - A convenience function that counts the number of tabs
XTestGrabControl [XTestQueryExtension] (3)  - XTest extension functions
Copy the code

For example, when you want to query information about a CPU, but forget which command to use, you can do this.

# apropos "cpu"
Copy the code

Or without double quotation marks

# apropos cpu
Copy the code

From the output, you can use the lscpu command to display information about the CPU.

# lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 2 On-line CPU(s) list: 0,1 Thread(s) per core: 1 core (s) per socket: 1 socket (s): 2 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 61 Stepping: 4 CPU MHz: 2194.921 BogoMIPS: 4389.84 Hypervisor Vendor: VMware Virtualization type: Full L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 3072K NUMA node0 CPU(s): 0,1Copy the code

Note: Search strings that contain more than one word should be enclosed in quotes.

SCP is used to copy files to the remote server, but SSH is used to connect to other servers remotely.

# apropos "remote"
......
scp                  (1)  - secure copy (remote file copy program)
ssh                  (1)  - OpenSSH SSH client (remote login program)
ssh [slogin]         (1)  - OpenSSH SSH client (remote login program)
Copy the code

When querying a particular string, there may be many, and you have to keep scrolling through the terminal search list to find the command you need. For more information on how to use the apropos command, you can use the man manual to execute the command man apropos.

# man apropos
Copy the code

Two, a long list of commands forget how to do?

Often in our work, hard to avoid can one-time output long command to find a particular file or even execute a script, but a day for two days, or we can use the direction key command history to find, once a week or even longer time, that the way of how to quickly find a long chain of command?

On a Linux terminal, press Ctrl+R and simply type the characters of the command to quickly search backwards for the entered commands. You can see a series of commands that appear in Bash History. Use UP/DOWN to switch commands. When you find the desired command, press TAB or the right arrow key to select the command and then press ENTER to run the command.

(reverse-i-search)`ls': lscpu
Copy the code

Recommended reading

SAO | how to elegant under Linux terminal operation on video?

How to efficiently manage the network with Linux command line?

With this technique, even if your boss is staring at you, you can do something new for him!


Original is not easy, if you think this article is useful to you, please kindly like, comment or forward this article, because this will be my power to output more high-quality articles, thank you!

By the way, please give me some free attention! In case you get lost and don’t find me next time.

See you next time!