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 useful Linux commands?

2025-02-28 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 are the Linux commands that are easy to use. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.

1. preparations

Take a deep breath when executing dangerous orders. First execute ifconfig, or ip addr, to make sure you are on the correct server.

$ ip addr 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:16:3e:34:e9:a9 brd ff:ff:ff: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 another deep breath and execute pwd to make sure you are in the correct directory.

$ pwd /etc/nginx

Next, you can see if the command executed is a dangerous command.

2. rm -rf command

-rf parameter will delete files recursively, and accidental deletion of files will lead to data loss, with serious consequences. If there is more than one space, or/is not filled in, or the file has special symbols, it will lead to the misoperation of deleting files by mistake.

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

Execute rm command, hand speed must be slow. Press Complete, be sure to wait for the screen to echo.

In addition, in the script, the rm pit is not small, such as:

rm -rf ${p}/*

If the p variable is not set, it is disastrous, and the command is equivalent to rm -rf /. So rm has another caveat: when executing rm in a script, check whether the associated 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 powerful recovery method. Before executing this command, make a backup of all file permissions. This is where the getfacl command is used.

getfacl -R / > chmod.txt

When restored, execute

setfacl --restore=chmod.txt

It plays back permissions on the file, sometimes lifesaving.

4. cat command

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

If you want to append content to a file, you will use cat >> file. If you accidentally enter a>, then sorry, your file content will be lost.

Similar commands also echo, etc., you can see that the problem is not cat, in the redirect character, too easy to write wrong.

Before you do this, make sure you count the arrows each time you take a deep breath.

5. DD command

The dd command is cool and echoes jj of xjjdog. The order reads 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 it to the command line, your data will evaporate.

6. CP command

The cp command causes overwriting, and if you regret it, it will be very difficult to find the original file.

It is recommended to add alias cp ='cp -i', where the i parameter indicates that a backup will be generated at copy time. Most of the time useless, sometimes useful.

Same reason we buy insurance.

MV command is similar, you can also add-i.

7. tar command

Don't think tar is safe, I've lost data with tar before.

First, tar -xf decompresses files in the current directory, overwriting the original folders and files. Covering these two words often means unsafe.

8. vim command

Vim is easy to open large files, causing the system memory consumption is too high. If the Oom-killer of the operating system is triggered, it will cause the death of other normal processes.

If you move too fast and execute:wq, it will cause inconsistencies or even damage to the file.

Use commands like less or more to view information. More efficient and safer.

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

9. mkfs.*

Instructions like mkfs.ext4 format the hard disk and are typically used for initialization of the online environment, 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 a where condition. The mysql program refuses to execute when it issues UPDATE or Delete without the WHERE or LIMIT keywords.

alias is also our good helper, can be set like this:

alias mysql='mysql -U'

(2)Use transactions for important operations

start transaction confirm commit

(3)DML error operation rollback, you can use binlog2sql

(4)Careful with DDL operations

DDL often implies huge pits, locked tables, false deletions, data transformations, often catastrophic. DDL operates on the entire table, or on all rows and columns of the entire table, generating exclusive locks that generate crazy io and seriously affect production.

Any one of these is fatal.

Examine DDL carefully, try to execute at the lowest peak of the business, and try to operate in-place.

About "what are the good Linux commands" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people 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