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

Which Linux commands need to pay attention to

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

Share

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

This article shows you which Linux commands need to pay attention to, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Every year, there is news of deleting the library and running away. In reality, it is easy to delete a repository, but it is difficult to run away, and practitioners are full of tears.

In these actions, there is not always subjective malice, but these commands are too dangerous. When operating online, be sure to keep a clear head and remember carelessness.

You said you operated it by mistake, who believed it?

1. Preparatory work

Please take a deep breath when carrying out dangerous orders. First execute the ifconfig, or ip addr command, to make sure it is on the correct server.

$ip addr 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:16:3e:34:e9:a9 brd ff:ff:ff: inet 127.0.0.1 scope host lo valid_lft forever preferred_lft forever inet6:: 1 eth0 128 qdisc fq_codel state UP group default qlen 2: eth0: Ff:ff:ff inet 172.19.26.39/20 brd 172.19.31.255 scope global dynamic noprefixroute eth0 valid_lft 313267185sec preferred_lft 313267185sec inet6 fe80::216:3eff:fe34:e9a9/64 scope link valid_lft forever preferred_lft forever

At this point, take a deep breath again, and then execute the pwd command to make sure you are in the correct directory.

$pwd / etc/nginx

Next, you can take a look at the command executed to see if it is a dangerous command.

2. Rm-rf command

-rf parameter will delete the file recursively. Accidentally deleting the file will result in data loss, resulting in serious consequences. If there is an extra space, or / is not filled up, or the file has a special symbol, which leads to the misoperation of deleting the file by mistake.

Rm-rf. / * = > rm-rf / rm-rf abc/ = > rm-rf abc/

To execute the rm command, the hand speed must be slow. Press complete, be sure to wait for the screen to display after the operation.

In addition, rm has a lot of holes in the script, such as:

Rm-rf ${p} / *

If the p variable is not set, it can be disastrous, and the command is equivalent to rm-rf /. So rm has another caveat: when executing rm in a script, first determine whether the relevant variable is empty.

3. Chmod command

Chmod is used to change directory and file permissions, and if not handled properly, it will have the same consequences as rm.

Here is a very domineering recovery method. Back up the permissions of all files before executing this command. The command getfacl is used here.

Getfacl-R / > chmod.txt

When restoring, execute

Setfacl-restore=chmod.txt

It will play back the permissions of this file, sometimes life-saving.

4. Cat command

Can the cat command go wrong? Yes, and it's serious, because you've mastered an advanced skill: redirectors.

If you want to add content to the file, you will use cat > > file. If you accidentally type a >, then sorry, your file content will be lost.

There are similar commands such as echo, you can see that the problem is not cat, in the redirector, too easy to make mistakes.

Before you do this, please make sure that you take a deep breath and count the number of arrows before you operate.

5. Dd command

The dd command is cool, echoing xjjdog's jj. The command is as follows:

Dd if=/dev/zero of=/dev/sda bs=512 count=1

The above command is used to format the hard disk. If you have such a command in your clipboard and accidentally stick to the command line, your data will evaporate.

6. Cp command

The cp command produces an overwrite, and if you regret it, it will be very difficult to find the original file.

It is recommended that you add the parameter alias cp ='cp-iPredictionI'to indicate that a backup will be generated at copy time. It doesn't work most of the time, sometimes it works.

It's the same reason as we buy insurance.

The mv command is similar, but you can also add-I.

7. Tar command

Don't think tar is secure. I've lost data because of the tar command.

First, when unzipping tar-xf, if the extracted files are already in the current directory, overwrite the original folders and files. Covering these two words often means that it is not safe.

8. Vim command

Vim is easy to cause excessive memory consumption of the system when opening large files. If the oom-killer of the operating system is triggered, other normal processes will die.

If your hand is too fast, execute: wq, it will cause inconsistency or even damage to the file.

However, use commands like less or more to view the information. More efficient and safer.

If you really have to use vim, keep using the view command, which is vim's read-only mode.

9. Mkfs.*

Instructions such as mkfs.ext4 will format the hard disk and are generally used for online initialization, otherwise do not execute.

10. MySQL

(1) use mysql-U

-safe-updates,-i-am-a-dummy, U

Use mysql-U to prevent delete and update from performing operations without where conditions. When a UPDATE or DELETE without the WHERE or LIMIT keyword is issued, the mysql program refuses to execute.

Alias is also a good helper for us. You can set it like this:

Alias mysql='mysql-U' execute confirmation commit

(2) use transactions for important operations

Start transaction

(3) rollback of DML misoperation. You can use binlog2sql.

(4) be careful with DDL operation

DDL often means a huge pit, and table locking, erroneous deletion, and data transformation are often catastrophic. DDL operates on the whole table, or all the rows and columns of the whole table, resulting in exclusive locks, resulting in crazy io and seriously affecting production.

Any one of these is fatal.

Check the DDL carefully, try to execute at the low peak of the business, and try to use the inplace mode to operate.

It is worth ten thousand dollars online, so it needs to be carried out carefully. Be careful to sail for ten thousand years, in a dangerous online environment, the pursuit is not fast, but stability.

What are the above Linux commands that need to be paid attention to? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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

Wechat

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

12
Report