Detailed explanation of common system management commands in Linux

ps

The ps command is used to view the process status in the system.

Command format:ps [参数]

Command parameter description:

parameter effect
-a Display all programs under the current terminal, including programs of other users
-u Displays program status in a user-focused format
-x Displays processes that do not have a controlling terminal, and displays the specific path of each command
-e When listing programs, show the environment variables used by each program
-f show all current processes
-t Specify a terminal number and list the status of programs belonging to that terminal

Example of use:

ps -ef | grep sshd

The effect is as follows:

pidof

The pidof command is used to query the PID value of the specified service process.

Command format:pidof [服务名称]

Parameter Description:

parameter illustrate
-s only returns a process id
-c Only show processes running in the root directory, this option is only valid for the root user
-O Ignore the process with the specified process ID
-x Show processes started by scripts

Example of use:

Query all process IDs under the sshd service.

pidof sshd

The effect is as follows:

kill

The kill command is used to terminate the service process with the specified PID.

Command format:kill [参数] [进程PID]

kill sends the specified information to the program. The preset information is SIGTERM(15), which can terminate the specified program. If the program still cannot be terminated, use the SIGKILL(9) message to try to forcefully remove the program.

Example of use:

Delete the process with pid 1001.

kill -9 1001

The effect is as follows:

killall

The killall command is used to terminate all processes corresponding to the service with the specified name.

Command format:killall [进程名称]

Example of use:

Delete all processes under the crond service.

killall crond

date

The date command is used to display and set the system time and date.

Command format:date [选项] [+格式]

Among them, some control characters of the time format are as follows:

character illustrate
%a Abbreviated week name in local time (eg: day, for Sunday)
%A Full name of the week in local time (example: Sunday)
%b Abbreviation of the month name in local time (example: one for January)
%B Full name of the month in local time (example: January)
%c Date and time in local time (eg: Thu Jan 27 2021 03:05:15)
%C Century; such as %Y, usually by omitting the last two digits of the current year (eg: 20)
%d Date in month (eg: 01)
%D Date in month; equals %m/%d/%y
%F Full date format, equivalent to %Y-%m-%d
%H hours (00..23)
%I Hours (01..12)
%j Date in Year (001-366)
%m Month (01..12)
%M minutes (00..59)
%p AM or PM local time
%r 12-hour clock time in local time (example: 11:11:04 PM)
%R Hours and minutes of a 24-hour time, equivalent to %H:%M
%s Number of seconds since 1970-01-01 00:00:00 UTC
%S seconds (00..60)
%T time, equal to %H:%M:%S
% U Week of the year, with Sunday as the first day of the week (00-53)
%x Date description in local time (example: 12/31/99)
%X Time description in local time (example: 23:13:48)
%w Day of the week (0-6), 0 means Monday
%W Week of the year, with Monday as the first day of the week (00-53)

Example of use:

  1. View current system time in default format
date

The effect is as follows:

  1. View the current system time according to the specified format
date "+%F %H:%M:%S"

The effect is as follows:

  1. Check the day of the year today is
date "+%j"

The effect is as follows:

  1. Set the current time of the system to 22:30:10 on September 15, 2020
date -s "20200915 22:30:10"

The effect is as follows:

  1. Correct system time and synchronize with network time

Install ntp timing tool

yum -y install ntp

Update time from time server with ntpdate

ntpdate time.nist.gov

The effect is as follows:

echo

The echo command is used to output a string or the extracted value of a variable in the terminal.

Command format:echo [字符串 | $变量]

Example of use:

  1. show normal string
echo '万猫学社'

The effect is as follows:

  1. show variable

First define a temporary variable name in the shell environment.

export name='万猫学社'

Use the echo command to display the value of the variable name to the terminal.

echo $name

The effect is as follows:

  1. Display results directed to file
echo "万猫学社" > name.txt

The output is redirected to the file name.txt, which will overwrite the contents of the file if it already exists, and create it if it does not. where the >symbol indicates output redirection.

The effect is as follows:

You can also use the >>output append redirection symbol to append text to the end of the file content instead of overwriting it.

  1. Display command execution result

The following command will display in the terminal what day of the year today is.

echo `date "+%j"`

Use $(command)form to achieve the same effect.

echo $(date "+%j")

The effect is as follows:

uname

The uname command is used to view information such as the system kernel and system version.

Command syntax:uname [-amnrsv][--help][--version]

Example of use:

  1. show system information
uname -a

The effect is as follows:

  1. Displays the hardware architecture of the current system.
uname -i

The effect is as follows:

  1. Displays the operating system release number.
uname -r

The effect is as follows:

image.png

  1. Displays the operating system name.
uname -s

The effect is as follows:

image.png

  1. Display the hostname.
uname -n

The effect is as follows:

image.png

history

The history command is used to display the commands executed in history.

Bash records 1000 executed historical commands by default, which are recorded in the ~/.bash_history file.

Example of use:

  1. Display the latest 10 executed commands.
history 10

The effect is as follows:

  1. Clear history.
history -c

The effect is as follows:

who

The who command displays information about all users currently on the local system.

Example of use:

  1. Displays the user currently logged in to the system
who

The effect is as follows:

  1. Show user login source
who -l -H

The effect is as follows:

  1. 只显示当前用户
who -m -H

效果如下图:

  1. 精简模式显示
who -q

效果如下图:

image.png

last

last 命令用于显示用户最近登录信息。

使用示例:

显示用户最近登录信息。

last

效果如下图:

由于这些信息都是以日志文件的形式保存在系统中,黑客可以很容易地对内容进行篡改,所以该命令输出的信息并不能作为服务器是否被入侵的依据。

最后,谢谢你这么帅,还给我点赞关注

{{o.name}}
{{m.name}}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324032255&siteId=291194637