Execute commands in Linux

1. Classification of commands

1.1. Built-in commands

Built-in commands provided by shell programs

1.2. External commands

Commands installed using third-party software consist of independent executable files and command names

2. View command help

2.1、man

1. The man command provides online help, and the user is the user when using permissions.

2. Use the man command to call the help information, which is very convenient to use.

  • man command
[root@server ~]# man ls

In the man command help information interface, the commonly used operation keys for the shift call are as follows:

button effect
Spacebar, PaGe Down

Turn down one page

RaGe up,b turn one page up
home Go directly to home page
end Go directly to the last page
/ Search for a keyword from top to bottom, such as ""
from below
n Locate the next searched keyword
N Locate the keyword in the previous search band
q Exit help document

The structure of the help information for the man command is as follows:

Structure name Representative meaning
NAME command name
SYNOPSIS General usage of parameters
DESCRIPTION Reduce description
EXAMPLES Demo (with simple instructions)
OVERVIEM Overview
DEFAULTS
Default function
OPTIONS
Specific options available
ENVIRONMENT
environment variables
FILES
Files used
SEE ALSO
relating documents
HISTORY
Maintenance history and contact information

2.2. Several parts of the man manual

  • Section 1 : User instructions, view help for commands
  • Section 2 : System calls, view help for functions that can be called by the kernel
  • Section 3 : Library calls, view help for functions and function libraries
  • Section 4 : Device, view help for special files (mainly files in the /dev directory)
  • Section 5 : File format, see help for the configuration file
  • Section 6 : Game, view the game's help
  • Section 7 : Miscellaneous, conventions and protocols, etc., such as descriptions of Linux file systems, network protocols, ASCII code, etc.
  • Section 8 : System Commands, view help for commands available to system administrators
  • Section 9 : Kernel internal instructions, see help for kernel-related files
Use the following command to know which section of man has relevant help documentation for a command:
[root@server ~]# whatis man
man (7) - macros to format man pages
man (1) - an interface to the on-line reference manuals
man (1p) - display system documentation
[root@server ~]# man -f man
man (7) - macros to format man pages
man (1) - an interface to the on-line reference manuals
man (1p) - display system documentation
[root@server ~]# man 1 man
[root@server ~]# man 7 man

2.3、info page

1. The uses of info and man are actually similar. They are both used to query the usage of commands or the format of files.
2. But unlike the man page , the info page splits the file data into paragraphs. Each paragraph is written on its own page, and there are "hyperlinks" similar to web pages in each page to jump to. into different pages, each independent page is also called a
node . _
3. However, the description file of the target data you want to query must be written in the format of info before you can use the special functions of info ( such as hyperlinks ) . The file that supports the info command is placed in the /usr/share/info/ directory by default.
[root@server info]# info info

The first line of information indicates:

Next: The name of the next node is stand-alone info. You can also press n to go to the next node;

Up: Return to the node overview screen of the previous layer. You can also press u to bring up the next layer;

After entering n/N, the display is as follows:

Prev : the previous node, enter p to return to the previous node.
Keys that can be used in the info page :
shortcut key effect
up arrow move up one line
down arrow Move down one line
PgUp turn one page up
PgDn Turn down one page
Tab  Switch between nodes with * symbol
Enter Enter the subpage with * symbol to view detailed help information
u Go to the previous level of information
Go to the next section of information
p Return to the previous section of information
s or / Use keyword search in info page
View help information
q Exit info

3. data command

3.1. Function

  • data is used to display or set the system time and date

Format: data - parameter + displayed date and time format

3.2. Common date and time formats

time date format effect
%Y Full date (eg: 2023)
%m

Month (1-12)

%d What day of the month
%H Hours (00.23)
%M

Minutes (00-59)

%S Seconds (00-59)
%j What day of the year is it?
%X

Equivalent to %H:%M:^%S

%Z Show time zone
%A Day of the week
%p  Show local AM or PM

3.3. Example

[root@server ~]# date
2023年 04月 27日 星期四 14:51:22 CST
[root@server ~]# date "+%j"
117
# %j表示今天为本年度第几天,一般用于备份文件,当查看时数字越大文件越新
[root@server ~]# date "+%Y-%m-%d"
[root@server ~]# date "+%H:%M:%S"
[root@server ~]# date +%Y-%m-%d %H:%M:%S # 报错,需要加双引号
date: 额外的操作数 “%H:%M:%S”
请尝试执行 "date --help" 来获取更多信息。
[root@server ~]# date "+%Y-%m-%d %H:%M:%S" # 参数中有空格需要加双引号
2023-04-27 15:03:57
[root@server ~]# date "+%Y年%m月%d日" # %Y等参数为单独个体,相互之间无直接联系
2023年04月27日
[root@server ~]# date "+ %Y年%m月%d日"
2023年04月27日
[root@server ~]# date "+%Y-%m-%d %p %H:%M:%S %A %Z"
2023-04-27 下午 15:05:28 星期四 CST
[root@server ~]# date "+%Y-%m-%d %p %H:%M:%S %A %Z 今天为今年第%j天"
2023-04-27 下午 15:05:50 星期四 CST 今天为今年第117天

3.4. Modification time and date

Format: data -s date time

Example:

[root@server ~]# date
2023年 04月 27日 星期四 15:27:10 CST
[root@server ~]# date -s 20230501
2023年 05月 01日 星期一 00:00:00 CST
[root@server ~]# date -s 15:28:50
2023年 04月 27日 星期四 15:28:50 CST
[root@server ~]# date -s "20230427 15:44:30"
2023年 04月 27日 星期四 15:44:30 CST

4. timedatectl command

4.1. Function

  • Set system time

4.2. Format

timedatectl -parameter command

4.3. The command function of timedatectl

  • status : display status information
  • list-timezones : List known time zones
  • set-timezone : Set the effective time zone
  • set-time : Set system time

4.4. Query system time and time zone

[root@server ~]# timedatectl status
Local time: 四 2023-04-27 15:48:55 CST
Universal time: 四 2023-04-27 07:48:55 UTC
RTC time: 四 2023-04-27 07:48:38
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: no
NTP service: active
RTC in local TZ: no

4.5. Manually set time

[root@server ~]# timedatectl set-time 18:00
Failed to set time: Automatic time synchronization is enabled
[root@server ~]# timedatectl set-ntp no # 注意:必须先关闭ntp时间同步
[root@server ~]# timedatectl set-time 18:00
# 可以开启ntp时间同步协议
[root@server ~]# timedatectl set-ntp yes
[root@server ~]# date
2023年 04月 27日 星期四 15:53:50 CST

5. Check the calendar

5.1. Format

cal month year

5.2. Example

[root@server ~]# cal
[root@server ~]# cal 2023
[root@server ~]# cal 5 2023

6. ls command

6.1、作用

  • 浏览目录及文件

6.2、格式

ls   -参数   路径

6.3、参数

参数 作用
-l 以列表的形式显示目录内的文件详细信息
-d 显示指定目录本身的信息
-c 按文件的修改时间
-h

以易于理解的方式显示目录或文件的大小,如:KB、MB、GB

-R 以递归形式显示指定目录内所有文件
-a 显示目录内所有文件,一般用于隐藏文件
-A 同-a,不显示点和点点的目录
-i 显示文件的索引节点(inode)

6.4、ls浏览后的颜色展示

  • 蓝色:目录文件
  • 白色:普通文件
  • 黄色:设备文件
  • 绿色:可执行文件
  • 浅蓝色:链接文件
  • 红色:压缩文件

Guess you like

Origin blog.csdn.net/2301_77475090/article/details/132920323