Summary of the Linux command commonly used in the work

  • 2021-01-22 08:15:18
  • OfStack

Use docker, kubernetes and other open source tools in my work. The operation is basically based on Linux system. Write down the Linux commands commonly used in your work. It is more convenient to use each command with a certain parameter. Only the commonly used commands and parameters are recorded here

1. System working commands

1. echo command

The echo command is used to print the extracted value of a string or variable at the terminal. Format for echo [string] | $variables

Similar to system.out.println in java


[root@k8s-master ~]# echo "hello world"
hello world
[root@k8s-master ~]# str="hello world"
[root@k8s-master ~]# echo $str
hello world

2. date command

Display and set system time in data [Options] [+ Specify format]

data common parameters

%t Hipbox [tab key] %H hours (0~23) %I hours (0~12) %M minutes (0~59) %S seconds (0~59) %J The day of the year

[root@k8s-master ~]# date
Thu Apr 11 13:42:20 CST 2019
[root@k8s-master ~]# date "+%Y-%m-%d %H:%M:%S"
2019-04-11 13:43:41
[root@k8s-master ~]# date "+%j"
101

3. reboot restart command

The reboot command is used to restart the system in the format reboot.


[root@k8s-master ~]# reboot

4. poweroff command

The poweroff command is used to shut down the system in the format poweroff


[root@k8s-master ~]# poweroff

5. wget command

The wget command downloads the network file on the terminal in the format wget [parameters] [download address]
Parameter is introduced

-b background download mode -P download to the specified directory -t maximum number of attempts -c breakpoint continuation -p download all resources in the page -r recursive download

[root@k8s-master ~]# wget http://www.linuxprobe.com/docs/LinuxProbe.pdf

6. ps command

The ps command is used to view the status of processes on the system in the format of [ps parameters]
Parameter is introduced

-a displays all processes - ES79en displays user and other details -x shows a process with no control terminal

[root@k8s-master ~]# ps aux

7. top command

The top command is used to dynamically monitor detailed information such as process conditions and system load. The top command is powerful and corresponds to the "enhanced task manager for windows" in linux.


top - 10:41:34 up 12 days, 19:14, 2 users, load average: 1.00, 1.06, 0.92
Tasks: 635 total,  2 running, 633 sleeping,  0 stopped,  0 zombie
%Cpu(s): 4.6 us, 1.2 sy, 0.0 ni, 92.1 id, 1.7 wa, 0.0 hi, 0.1 si, 0.3 st
KiB Mem : 16268340 total, 7407372 free, 4552160 used, 4308808 buff/cache
KiB Swap:    0 total,    0 free,    0 used. 10456728 avail Mem 

 PID USER   PR NI  VIRT  RES  SHR S %CPU %MEM   TIME+ COMMAND                                                        
32056 root   20  0 868460 790968 42808 S 25.2 4.9  1915:18 kube-apiserver 

The first five lines of the top command are overall system statistics. Represents system load, process condition, cpu, physical memory, and virtual memory usage, respectively.

8. pidof command

The pidof command is used to query the pid value of a service in the format of [pidof parameter service name].


 [root@k8s-master ~]# pidof java
  27775

9. kill and killall commands

The kill command is the process format used to terminate the pid value [kill parameter pid value], and the killall command is all processes that terminate a particular service [killall parameter a process name].

2. State monitoring command

System status monitoring commands enable faster and better understanding of linux servers. Including the system's network card network, system kernel, system load, memory usage, the current number of startup terminals and other related commands.

1. ifconfig command

ifconfig is used to obtain network card configuration and network status and other information. The format is [ifconfig Network Device Parameter]
Just enter ifconfig to view all network card information.


[root@k8s-master ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 192.168.223.16 netmask 255.255.255.0 broadcast 192.168.223.255
    inet6 fe80::20c:29ff:fede:d1af prefixlen 64 scopeid 0x20<link>
    ether 00:0c:29:de:d1:af txqueuelen 1000 (Ethernet)
    RX packets 66 bytes 8951 (8.7 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 88 bytes 10153 (9.9 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

View the network card information is mainly to view the name of the network card, IP after inet address, ether after the physical address, RX and TX received and sent packets and the number of cumulative traffic.

View network card information is mainly to view the network card name, IP after inet address, ether after the physical address, RX and TX received and sent packets and the number of cumulative traffic.

2. uname command

The uname command looks at information such as the system kernel and system version. 1 general collocation -a parameter, complete view of the relevant information.


[root@k8s-master ~]# uname -a
Linux mysql 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Also see the details of the current system version.


[root@k8s-master ~]# date
Thu Apr 11 13:42:20 CST 2019
[root@k8s-master ~]# date "+%Y-%m-%d %H:%M:%S"
2019-04-11 13:43:41
[root@k8s-master ~]# date "+%j"
101
0

3. uptime command

The uptime command can view the load information of the system. This includes the system time, the system uptime, the current end user, and the system stress in the last 1, 5, and 15 minutes. The lower the load value, the better, do not exceed 1 for a long time, and do not exceed 5 for production environment


[root@k8s-master ~]# date
Thu Apr 11 13:42:20 CST 2019
[root@k8s-master ~]# date "+%Y-%m-%d %H:%M:%S"
2019-04-11 13:43:41
[root@k8s-master ~]# date "+%j"
101
1

4. free command

Displays information about how much memory is being used in the current system. The format is [free-h]


[root@k8s-master ~]# date
Thu Apr 11 13:42:20 CST 2019
[root@k8s-master ~]# date "+%Y-%m-%d %H:%M:%S"
2019-04-11 13:43:41
[root@k8s-master ~]# date "+%j"
101
2

5. histroy command

The histroy command displays historically executed commands in the format [history-c]
Executing the history command displays the current user on the local computer
A record of the last 1000 commands executed in. You can also use "! Encode a number "to repeat a command.


[root@k8s-master ~]# history
  1 ls
  2 cd /
  3 ls
  4 hostname
  5 ls
  6 cd mysql/
  7 ls
  8 cd data/

3. Working directory switch command

linux is used during the work process and is almost not installed graphically. In order to reduce overhead. We're basically in command terminal mode. It is not as easy to switch working directories as it is in windows. The working directory even if the user is currently located.

1. pwd command

The pwd command displays the absolute path format of the current working directory [pwd option]


[root@k8s-master ~]# date
Thu Apr 11 13:42:20 CST 2019
[root@k8s-master ~]# date "+%Y-%m-%d %H:%M:%S"
2019-04-11 13:43:41
[root@k8s-master ~]# date "+%j"
101
4

2. cd command

The cd command switches the working path. This is probably the most commonly used command in linux.


[root@k8s-master ~]# date
Thu Apr 11 13:42:20 CST 2019
[root@k8s-master ~]# date "+%Y-%m-%d %H:%M:%S"
2019-04-11 13:43:41
[root@k8s-master ~]# date "+%j"
101
5

3. ls command

The ls command displays the file information. Format [ls option]
-l parameter can view the file properties,


[root@k8s-master ~]# date
Thu Apr 11 13:42:20 CST 2019
[root@k8s-master ~]# date "+%Y-%m-%d %H:%M:%S"
2019-04-11 13:43:41
[root@k8s-master ~]# date "+%j"
101
6

4. File directory management command

1. mkdir command

The mkdir command is used to create an empty directory in the format [mkdir option directory].
Can use -p parameter, recursive creation directory.


[root@k8s-master ~]# date
Thu Apr 11 13:42:20 CST 2019
[root@k8s-master ~]# date "+%Y-%m-%d %H:%M:%S"
2019-04-11 13:43:41
[root@k8s-master ~]# date "+%j"
101
7

2. cp command

The cp command is used to copy files or directories in the format cp [options] source file object file


[root@kubernetes ~]# cp install.log x.log
[root@kubernetes ~]# ls
install.log x.log

3. mv command

mv command is used to shear file or the file renaming, format for mv [option] source file [target path | target file name]


[root@k8s-master ~]# date
Thu Apr 11 13:42:20 CST 2019
[root@k8s-master ~]# date "+%Y-%m-%d %H:%M:%S"
2019-04-11 13:43:41
[root@k8s-master ~]# date "+%j"
101
9

4. rm command

The rm command is used to delete files or directories in the form of rm [options] files
When deleting a file in the Linux system, you will be asked by default if you want to delete the file, if you do not want to always
When you see this repeated acknowledgement, follow the -f parameter after the rm command to force deletion.


[root@kubernetes ~]# rm install.log
rm: remove regular empty file  ' install.log'? y
[root@kubernetes ~]# rm -f linux.log
[root@kubernetes ~]# ls
[root@kubernetes ~]#

Related articles: