Classification and induction of Linux common commands necessary for daily work



Linux basic command sorting, not including shell knowledge

Basic command

The commands that come with the shell (command interpreter) are called internal commands, and the others are external commands
Internal commands using help help help:help cd
External commands using help help help:ls --help
Type command: used to distinguish between internal and external commands:

#type ls
LS is aliased to ` LS -- color = auto 'ාexternal command
#type cd
CD is a shell builtin internal command

PWD command: display current directory
Ls command: View directory and file names
ls -lView the meaning of each field in the directory
Classification and induction of Linux common commands necessary for daily work

First field: the initial represents the file type, where “-” is a normal file, “d” is a directory file, “C” is a character device file, “B” is a block device file, “P” is a pipeline file, “L” is a link file, “s” is a socket file. “RWX” means to have read, write and execute permissions respectively, “- means to have no corresponding permissions. The three “RWX” represent the file owner, the user group of the file owner, and the permissions of other users to the file.
Second field: number of file hard connections
Third field: file owner
Field 4: the group of file owner
Fifth field: file size (in bytes)
Field 6: last change time of document
Seventh field: file name (if it is a linked file, the path of the original file to which it is linked is appended)

Meaning of other parameters of LS command:
-A show hidden files (. Beginning files)
-R reverse order
-Tdisplay in chronological order
-R recursive display
ls -lartR: display all files and their folders in reverse chronological order

CD command: change the current working directory
cd /path/... Absolute path
cd ./path/... Relative path (. / can be omitted)
cd ../path/...Relative path

MKDIR lifeOrder: create directory
Classification and induction of Linux common commands necessary for daily work
MKDIR - P recursive directory: recursively create directory

Rmdir command: delete directory
rmdir a/b/c/d/e/#Delete empty directory
rm -r a/b/c/d/#Delete directory recursively, but the system will ask many times
rm -rf a/b/c/d/#Delete directory without asking

CP command: copying files and directories
-R copy directory
-P keep file attributes such as user, permission, time, etc

MV command: moving files and renaming
MV *. Log target directory

*Match any string
? match a string
[XYZ] any string
[A-Z] match a range

Cat command: text content display to terminal

Head command: View beginning of file
Head - 3 file name#Display the first 3 lines of the file

Tail command: view end of file
Tail-3 file name#Display the last 3 lines of the file
Common parameter of tail – F. after the file content is updated, the updated file information will be displayed synchronously
Tail - f file name

WC command: Statistics file content information
WC file name

Compression and decompression

Tar packaging command (only packaging function, not compression function)
The compression commands are gzip and bzip2. The compressed files of bzip2 are smaller, but slower
-C packing
-X unpacking
-F specifies that the operation type is file
Classification and induction of Linux common commands necessary for daily work

tar cf ./etc-backup.tar /etc 
tar czf ./etc-backup.tar.gz /etc
tar cjf ./etc-backup.tar.bz2 /etc

tar xf ./etc-backup.tar
tar xzf ./etc-backup.tar.gz 
tar xjf ./etc-backup.tar.bz2 

VI command

Three modes of VI command
Command mode: the command mode is the default mode entered by VIM after the file is opened. It can quickly locate and process the file
Insertion mode: edit file
Row mode: save exit of file

Command mode operation
Input I key: input the current position of the cursor
Input I key: input the position at the beginning of the current line of the cursor
Enter a key: input the current position of the next character of the cursor
Enter a key: enter the position at the end of the current line
Enter o key: enter the position of the new blank line next to the current line
Enter o key: enter the position of the new blank line on the current line
Hjkl: direction keyboard, move the cursor up, right, down, left, and notice that the up, down, left and right keys of the terminal may be scrambled
YY: copy current line
p: Paste copied content
3yy: copy 3 consecutive lines at the beginning of the current line
Y $: copy cursor current position to the end of cursor current line
DD: cut the current line
D $: current position of cutting cursor to the end of this line
u: Undo key
CTRL + R: redo keyboard
G: The cursor quickly switches to which line. For example:11GThe cursor switches to line 11
^: the cursor quickly switches to the beginning of the current line
$: cursor quickly switches to the end of the current line

Last line mode operation:
: W save
: Q exit editing
: WQ save and exit editing
: q! Exit without saving
/What to look for: Global what to look for, next location of what to look for, last location of what to look for
: S / original content / content to be replaced: only the current line content replacement takes effect
:% s / original content / content to be replaced / G: all content will be replaced and take effect
: 11,15s / original content / content to be replaced: line 11,15 content replacement takes effect
: set Nu set display line number
: set nonu set not to display line numbers

Configure / etc / virc
Set the way to display the line number by using VI command by default:
1、vi /etc/virc
2. Add: set Nu at the last line of the file and save to exit

User management and group management

Useradd command: new user
Useradd user name

Userdel command: delete user
Userdel user nameThe user’s home directory will not be deleted
Userdel - R user nameAll user related configurations will be deleted

Passwd command: change user password
Passwd user name

Usermod command: modify user properties

/Etc / passwd file: View user files
tail /etc/passwd

/Etc / shadow file: View user password
tail /etc/shadow

Groupadd command: Add User Group
Groupadd user group

Groupdel command: delete user group
Groupdel user group

User switching
Su user nameSwitch users, but the user’s environment does not change, that is, the PWD path will not change
Su - user nameSwitch the user, and at the same time switch to the user’s home directory, i.e. / home / user name

Sudo command: solutions for ordinary users to execute root privileges

User and user group profile introduction
/Etc / passwd file
Classification and induction of Linux common commands necessary for daily work

1. Account name
2. The encrypted password, if the first character in this column is! Or *, indicates that this is an account that cannot be logged in. As can be seen from the above, Ubuntu does not enable root account by default.

Classification and induction of Linux common commands necessary for daily work

file type
ls -lView file types
-Normal characters
D catalog file
Block B special file
C character special file
L symbolic link
F named pipe
S socket file

File permission representation
R read (number 4), w write (number 2), X execute (number 1)

Directory permission representation
X enters the directory
RX displays the filename in the directory
Wx changes the filename in the directory

Chmod command: modify file permissions
Adding and modifying permissions by characters
u: Modify user rights
g: Modify user group permissions
o: Modify other user rights
+: add permission
-: reduce permissions
=: set permissions
chmod u+r aaa.log#To aaa.log Add read permission for the user who owns the file

Add permissions by numbers
chmod 666 aaa.log #To aaa.log File set read / write permission
It should be noted that the root user’s permissions will not be affected

Chown command: change owner, group
Chown username filename
Chown user name: group name filename

Network configuration command

Configure IP address
Eth0 indicates the first network card. The name of the network card may also be eno1 (onboard network card), ens33 (pec-e network card), enp0s3 (wireless pec-e network card)
Ifconfig interface IP address [netmask subnet mask]#Configure IP address
Ifup interface#Open network card
Ifdown interface#Close network card

Add gateway
Route add default gw gateway IP
Route add – host specifies IP GW gateway IP
Route add – net segment netmask subnet mask GW gateway IP case:route add -net netmask gw

Check network
Ping command#Check whether the network is connected
Traceroute command#Analyze which part of the network has problems when the network is not good
MT command R#Analyze which part of the network has problems when the network is not good
NSLOOKUP commandGet IP based on domain name resolution

Analysis service after network no problem
Telnet domain name port(port closed connection used and port opened connected to…)
Tcpdump command#Capture the transmission data of the network card (i.e. the function of packet capturing)
Netstat command#View local network services

Hostname command#Viewing and modifying host names
Hostname new hostname(note to modify the / etc / hosts file configuration hostname)

Configure network card information
Network card file location / etc / sysconfig / network scripts / ifcfg-eth0
Onboot = yes boot configuration
Bootproto = DHCP get IP address dynamically

Package management

Package manager is an important tool for software installation, uninstallation and software dependency resolution
CentOS and RedHat use Yum package manager, and the format of software installation package is rpm
Debian and Ubuntu use apt package manager, and the format of software installation package is DEB

RPM packages and commands

RPM package format:
Classification and induction of Linux common commands necessary for daily work

-Q query package
RPM - Q installation package name (full name is not required)#Query individual packages
rpm -qa#Query all installation packages

-I install package
Full name of rpm-i package

-E uninstall package
RPM - E installation package name(full name not required)

Yum install package

When RPM installs a software package, it often fails to find the dependent package. It needs to manually solve the dependent installation package, which is more troublesome. At this time, it is more suitable to use Yum to install, which can automatically solve the dependent software package
Alicloud RPM image website and use
Yum common parameters
Yum install package name
Yum remove package name
Yum list to view installed packages
Yum update package name

Source code installation software

Sometimes we need to install the latest version of the software. At this time, the yum library may not have the latest version. We need to manually compile the software source code to install the software, and we need to solve all kinds of dependencies when compiling the source code
Step 1:. / configure — prefix = / usr / local / software name
Step 2: make (sometimes I see that gmake-j2 refers to cross platform installation, while – J2 refers to compiling with multiple CPUs to speed up compilation)
Step 3: make install (install the software to the directory specified in — prefix. The advantage is that you can delete the entire package when deleting the software, otherwise you need to delete a bunch of files in / usr / bin and other directories)

Process management

View commands
ps -ef#View process
pstree#View process tree
Top command
Press 1 under top to view the resource usage of each CPU (multi-core situation);
Top-p process ID#View resource usage of the process separately

Adjust process priority
Nice ranges from – 20 to 19. The smaller the value, the higher the priority, and the more resources are preempted
Nice - N 10 script name
Renice resets the priority of the running program
Renice - N 15 process ID

Process job control
&Symbol, let the process run in the background
Jobs view the processes running in the background
According to the result FG [sequence number] in the first column of jobs, the background process can be moved to the foreground

Kill Command
kill -l #List all signal types related to the process
ctrl + c#Notify the foreground process to terminate the process
Kill - 9 process ID#End process now

Nohup and the & symbol cooperate to make the process continue to run after exiting the terminal
DaemonsIt refers to the relevant process of system startup, which can be started by/Proc / process ID/Directory to view the details of the process running, and through the log file under the / var / log directory to view more process running information, messages system log information, secure log information, cron timing task information
Screen enables the process to continue after recovery even if the network is disconnected
Process management tools Service (configuration file path / etc / init. D) and systemctl (evolution version of service)

Memory and disk management

Top command
Classification and induction of Linux common commands necessary for daily work
If you want to check the memory surplus, you should look at free memory instead of buffers, because some programs, such as jar programs, will take up a lot of memory as a cache, and you can release this part of the cache through commands. When you start using swap, you need to consider whether the memory is enough. When the memory is insufficient, the system will randomly kill the processes that take up a lot of memory, resulting in uncontrollability;

Free command
free -m#Use m as the unit to view the memory. Note that if you use free-g to view the memory, it will be smaller, and the system will delete the insufficient G memory when it is displayed

View disk
Query the overall disk usage of the system
df -h
Query the disk usage of the specified directory
Du-h / Catalogue#Default to current directory
-S specifies the summary of directory usage size
-H with unit of measurement
-A including documents
–Max depth = 1 subdirectory depth
-C. increase the total value of foreign exchange while listing the details

To add a hard disk:
1. Add hard disk
2. Partition fdisk:fdisk /dev/sdb(assume the new disk name is SDB)
3. Format mkfs:mkfs -t ext4 /dev/sdb1
4. Mount Directory: first create a / newdisk to mount in the directorymount /dev/sdb1 /newdisk
5. Settings can be permanently mounted: modify the / etc / fstab file

Recommended Today

Python basics Chinese series tutorial · translation completed

Original: Python basics Python tutorial Protocol: CC by-nc-sa 4.0 Welcome anyone to participate and improve: a person can go very fast, but a group of people can go further. Online reading Apache CN learning resources catalog introduce Seven reasons to learn Python Why Python is great Learn Python introduction Executing Python scripts variable character string […]