Linux basic commands (middle)-system management and disk management

One, system management

1.1 Time related instructions

<1> View the current calendar: cal

Command format:

cal [parameter] [month] [year]

Common options:

  • -3 Display the calendar of the previous month, current month, and next month of the system
  • -j displays the day of the year (the date of the year is counted by the day, starting from January 1, the default is to display the number of days in the year in the current month)
  • -y displays the calendar of the current year
    Insert picture description here

<2> Display or set time: data

date specifies the format to display the time:

date +%Y:%m:%d

date 用法:date [OPTION]… [+FORMAT]

  • 1. In terms of display, the user can set the format to be displayed. The format is set to a plus sign followed by several marks. The list of commonly used marks is as follows

    • %H: hour (00…23)
    • %M: minute (00…59)
    • %S: second (00…61)
    • %X: equivalent to %H:%M:%S
    • %d: day (01…31)
    • %m: month (01…12)
    • %Y: complete year (0000…9999)
    • %F: equivalent to %Y-%m-%d
      Insert picture description here
  • 2. In terms of setting time

    • date -s //Set the current time, only root privileges can be set, others can only be viewed.
    • date -s 20080523 //Set to 20080523, this will set the specific time to empty 00:00:00
    • date -s 01:01:01 //Set the specific time, the date will not be changed
    • date -s "01:01:01 2008-05-23" //This can set all time
    • date -s "01:01:01 20080523" //This can set all time
    • date -s "2008-05-23 01:01:01" //This can set all time
    • date -s "20080523 01:01:01" //This can set all time
  • 3. Timestamp
    Time -> Timestamp: date +%s
    Timestamp -> Time: date -d@1508749502
    Unix timestamp (English is Unix epoch, Unix time, POSIX time or Unix timestamp) is from January 1, 1970 The number of seconds elapsed since the start of the day (midnight in UTC/GMT), regardless of leap seconds.
    Insert picture description here

1.2 Process related instructions

<1> View process information: ps

The ps command can view the detailed status of the process, and the commonly used options (the options can be omitted) are as follows:

Options meaning
-a Display all processes on the terminal, including processes of other users
-u Display the detailed status of the process
-x Show processes that do not have a controlling terminal
-w The display is widened to show more information
-r Only show the running process

Insert picture description here

<2> Dynamic display process: top

The top command is used to dynamically display the running process. The top command can update the displayed information at a specified time interval after running. You can add -d when using the top command to specify the time interval for updating the display information.
After the top command is executed, you can press the button to sort the displayed results:

button meaning
M Sort by memory usage
P Sort by CPU occupancy
T Sort according to the length of the running time of the process
U You can filter the process based on the user name entered later
K The process can be killed according to the PID entered later.
q drop out
h Get help

Insert picture description here

<3> Terminate the process: kill

Use format:

kill [-signal] pid

The signal value of 9 is absolute termination, which can handle the process where the signal cannot be terminated.
Insert picture description here
Insert picture description here

1.3 Shutdown and restart related instructions: reboot, shutdown, init

command meaning
reboot Restart the operating system
shutdown –r now Restart the operating system, shutdown will prompt other users
shutdown -h now Immediately shut down, where now is equivalent to the state of time 0
shutdown -h 13:25 The system will shut down at 13:25 today
shutdown -h +10 The system will automatically shut down in another minute
init 0 Shut down
init 6 Reboot

1.4 Network operation related instructions: ifconfig, ping

Insert picture description here
Insert picture description here

Two, disk management

2.1 Detection of disk space: df

The df command is used to detect the disk space occupancy and vacancy of the file system, and can display the use of nodes and disk blocks by all file systems.

Options meaning
-a Display disk usage of all file systems
-m Display in units of 1024 bytes
-h Display information in a readable way;
-t Display the disk space usage of each specified file system
-T Display file system

Insert picture description here

2.2 Disk space occupied by the detection directory: du

The du command is used to count the amount of disk space occupied by a directory or file. The execution result of this command is similar to df, and du focuses more on the usage of the disk.
The usage format of the du command is as follows:

du [options] directory or file name

Options meaning
-a Recursively display each file in the specified directory and the data block occupied by the file in the subdirectory
-s Display the data block occupied by the specified file or directory
-b Display disk usage in bytes
-l Calculate the size of all files, and calculate multiple times for hard-linked files

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_40076022/article/details/113807234