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

In Linux! How to use it

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

Share

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

Editor to share with you in Linux! How to use it? I hope you will get something after reading this article. Let's discuss it together.

Execute the previous order

For example, after executing the previous command, you can execute the previous command again using the following ways:

$whereis bash # execute the command bash: / bin/bash / etc/bash.bashrc / usr/share/man/man1/bash.1.gz $!! # execute the previous command whereis bash bash: / bin/bash / etc/bash.bashrc / usr/share/man/man1/bash.1.gz again

!! Represents the previous order executed. As you can see, when you enter two exclamation marks, it displays the previous command and executes the previous command. Of course, we usually think of using the "UP" key to do this. But if it is based on the previous command expansion,! It would be more convenient to come.

For example, you want to view a file, but forget to enter more:

$/ opt/user/test.txt # forgot to enter more $more!! # isn't that much faster?

Use! Isn't it more convenient?

Execute the command using the arguments of * * or * of the previous command

Use the previous command * a parameter

For example, if you use ls to list the contents of the directory without any parameters, but want to execute it again, take the-al parameter, and do not want to enter long parameters, you can use the following methods:

$ls / proc/1/task/1/net/tcp / proc/1/task/1/net/tc $ls-al! $ls-al / proc/1/task/1/net/tcp-root root 0 December 22 17:30 / proc/1/task/1/net/tcp

The! $here represents a parameter of the previous command.

Use the previous command * parameters

Using the * * parameters of the previous command, you only need to use! ^, for example:

$ls-al! ^

Remove a parameter to execute the previous command

If you want to execute the previous command, but do not want to take a parameter:

$ls-al dir # assumes that dir is a long string $!:-ls-al

In what scenarios might it be used? For example, if your last command * has a long string and you just don't want to use it, and the backspace key is slow to delete, you can use the above method.

Use all the parameters of the previous command

As mentioned earlier, if you use the * parameter of the previous command, how do you use it if it is not a parameter? It's very simple. Use! * you can. For example, when we typed the wrong find command and wanted to correct it:

$fin-name "test.zip" # here find is typed incorrectly. $find! * find. /-name "test.zip". / workspaces/shell/find/test.zip. / workspaces/shell/test.zip

Use the parameters specified by the previous command

Some readers may ask, what if I only want to use one of these parameters? According to! [command name]: [parameter number] rule is fine. For example:

$cp-rf dira dirb/ # copy dira to dirb $ls-l! cp:2 # View the contents of dira ls-l dira total 0-rw-rw-r-- 1 hyb hyb 0 December 22 17:45 testfile

When the parameters of the previous command are very long, and you need to take a parameter in the middle, the effect is more obvious.

Execute commands in history

We all know that you can view previously executed commands through the history command, but how do you execute the commands in history again? We can view it through the "UP" key, but when the history command is very long, it is not very convenient. "!" It came in handy:

$history (more omitted here) 2043 touch. / dira/testfile 2044 cp-rf dira dirb/ 2045 ls-al dira 2046 ls-l dira 2047 ls-al dira 2048 ls-l dira 2049 ls-al dira 2050 ls-l dira 2051 history

We can see that when the history command comes out, you can see the command that has been executed before, and you can see that it is preceded by a number. If we want to execute the previous cp-rf dira dirb/ command, we can actually do it in the following way:

$! 2044 # 2044 is the execution of the n command cp-rf dira dirb/

That is, yes! [historical command value] executes the historical command.

Of course, if we want to execute the penultimate command, there is a way:

The $!-2 # exclamation point is followed by a negative number, which represents the penultimate item.

Execute historical commands according to keywords

! Commands can be executed based on keywords.

Execute the previous command that begins with a keyword

For example, execute the previous find command:

$! find # execute the previous command that begins with find

Execute the previous command containing the keyword

For example, execute the previous command that contains name:

$find. /-name "test". / test. / find/test $!? name? Find. /-name "test". / test. / find/test

Replace the parameters of the previous command

For example:

$find. /-name "old*"-a-name "* .zip"

If we need to change the old in this command to new:

$!: gs/old/new

The function of logical non

This is its most familiar function, such as deleting all files except the end of cfg:

Rm! (* .cfg) # deletion need to read this article carefully, I believe you have a certain understanding of "in Linux! how to use", if you want to know more related knowledge, welcome to follow the industry information channel, thank you for reading!

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