Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the practical Linux terminal commands?

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail what the practical Linux terminal commands are, and the editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Automatic completion of Tab key

Using the Tab key to automatically complete is a basic skill. It can save you a lot of time, and it's also useful when you're not sure how to spell a file name or command.

For example, for example, in the current directory you have a file with the name "really long file nam" and you want to delete it. You can enter the entire file name, but you have to be careful of typing the wrong space character (need to be escaped with\). If you type "rm r" and press the Tab key, Bash will automatically complete the name of the file for you.

Of course, if you have many files in the current directory that begin with the letter r, Bash will not know which one you are referring to. For example, in the current directory you have another text called "really very long file name". When you press the Tab key, Bash will complete the "really\" section, because both files begin with this. Then, press the Tab key and you will see a list of all the files that match the beginning, as shown below.

Then enter the file name you want and press Tab. In this way, when we type "l" and then press the Tab key, Bash will automatically complete the file name we want.

This method is also suitable for entering commands. When you are not sure what command you want, just remember to start with "gnome", type "gnome" and press the Tab key, and you will see all possible results.

Pipe command

The pipe command allows you to transfer the output of one command to another. In Unix's design philosophy, each program has only a few but sophisticated functions. For example, the "ls" command displays a list of all the files in the current directory, while the "grep" command searches for the entered string in the specified place.

By combining the two through the pipe command (represented by the "|" symbol), you can search for a file in the current directory, and the following command is used to search for "really":

Ls | grep really

Wildcard character

The asterisk "*" is a wildcard that matches anything. For example, if we want to delete both "really long file name" and "really very long file name" from the current directory, we can use the following command:

Rm really*name

This command deletes all files that start with really and end with name. If you use the "rm *" command, all files in this directory will be deleted, all should be used with caution.

Output redirection

The ">" character redirects the output of a command to a file without the need for another command. For example, the code in the following figure uses the "ls" command to list all the files in the current directory and inputs the output list into a file called "file1" instead of just displaying the output on the terminal.

Ls > file1

Command line history

Bash will remember the history of the commands you used. You can use the up and down arrow keys to flip through the commands you have already used. Using the "history" command will print out all the historical commands, so you can use the pipe command to search for your most recent commands.

There are many other techniques that can be used about command line history:

~,. &.

The wavy character "~" represents the home directory of the current user. So, you can use "cd ~" to change to your home directory instead of typing "cd / home/name". This is also used for relative paths, such as "cd ~ / Desktop" to switch to the current user's desktop directory.

Similarly, "." Represents the current directory, ".." Represents the parent directory. All, "cd..." Jumps to the parent directory. This is also valid for relative paths, such as if you are in the Desktop directory, and if you want to change to the Document directory at the same level as the Desktop directory, you can use the "cd.. / Documents" command.

Run commands in the background

By default, Bash will run your commands on the current terminal. Normally there is no problem, but what if you want to run an application at the same time and continue to use the terminal? For example, if you enter the "firefox" command to run Firefox, Firefox will occupy your terminal and display some error messages and other output until you close it. But adding a "&" symbol after the command causes Bash to run the program in the background:

Firefox &

Conditional execution

You can also use Bash to run two commands, one after another. The second command will not be run until the * commands have been successfully run. To do this, separate the two commands with "&" on the same line.

For example, the "sleep" command takes a parameter in seconds and then countdown to allow it to end. If used alone, this command is of no use, but you can use it as a delay before running the next program. The following command pauses for 5 seconds and then runs gnome's screenshot tool:

Sleep 5 & & gnome-screenshot about "what are the practical Linux terminal commands" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report