[Linux] Date class and lookup class

content

 time date class

date display time command

set date command

 cal show calendar

 search find class

find command

ls -lh visual display 

 locate locate file path

 which view command location

grep filter directives and pipe symbols |

 time date class

date display time command

Basic syntax:

date   (display current time)

date +%Y    (display current year)

date +%m     (display current month)

date +%d      (displays the current day)

date " +%Y-%m-%d %H:%M:%S"   (display year, month, day, hour, minute, second)

Example: Demonstrate the above command

[root@kongchao02 myroot]# date
2022年 03月 05日 星期六 09:01:17 CST
[root@kongchao02 myroot]# date +%Y
2022
[root@kongchao02 myroot]# date +%m
03
[root@kongchao02 myroot]# date +%d
05
[root@kongchao02 myroot]# 
[root@kongchao02 myroot]# date "+%Y-%m-%d %H:%M:%S"  
2022-03-05 09:03:25 
[root@kongchao02 myroot]# 

set date command

Basic syntax: date -s string time 

The example sets the current time of the system,

[root@kongchao02 myroot]# date
2022年 03月 05日 星期六 09:07:55 CST
[root@kongchao02 myroot]# date -s "2022-3-5 09:07:00"
2022年 03月 05日 星期六 09:07:00 CST
[root@kongchao02 myroot]# date
2022年 03月 05日 星期六 09:07:05 CST
[root@kongchao02 myroot]# 

 cal show calendar

View Calendar Instructions cal

Basic syntax: cal [options]  (display this month's calendar without options)

View a calendar for a year such as 2022, cal 2022

Example 1, display the current month cal


[root@kongchao02 myroot]# cal
      三月 2022     
日 一 二 三 四 五 六
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

[root@kongchao02 myroot]# 

Example 2: Display 2022 calendar   cal 2022

[root@kongchao02 myroot]# cal 2022
                               2022                               

        一月                   二月                   三月        
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
                   1          1  2  3  4  5          1  2  3  4  5
 2  3  4  5  6  7  8    6  7  8  9 10 11 12    6  7  8  9 10 11 12
 9 10 11 12 13 14 15   13 14 15 16 17 18 19   13 14 15 16 17 18 19
16 17 18 19 20 21 22   20 21 22 23 24 25 26   20 21 22 23 24 25 26
23 24 25 26 27 28 29   27 28                  27 28 29 30 31
30 31
        四月                   五月                   六月        
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
                1  2    1  2  3  4  5  6  7             1  2  3  4
 3  4  5  6  7  8  9    8  9 10 11 12 13 14    5  6  7  8  9 10 11
10 11 12 13 14 15 16   15 16 17 18 19 20 21   12 13 14 15 16 17 18
17 18 19 20 21 22 23   22 23 24 25 26 27 28   19 20 21 22 23 24 25
24 25 26 27 28 29 30   29 30 31               26 27 28 29 30

        七月                   八月                   九月        
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
                1  2       1  2  3  4  5  6                1  2  3
 3  4  5  6  7  8  9    7  8  9 10 11 12 13    4  5  6  7  8  9 10
10 11 12 13 14 15 16   14 15 16 17 18 19 20   11 12 13 14 15 16 17
17 18 19 20 21 22 23   21 22 23 24 25 26 27   18 19 20 21 22 23 24
24 25 26 27 28 29 30   28 29 30 31            25 26 27 28 29 30
31
        十月                  十一月                 十二月       
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
                   1          1  2  3  4  5                1  2  3
 2  3  4  5  6  7  8    6  7  8  9 10 11 12    4  5  6  7  8  9 10
 9 10 11 12 13 14 15   13 14 15 16 17 18 19   11 12 13 14 15 16 17
16 17 18 19 20 21 22   20 21 22 23 24 25 26   18 19 20 21 22 23 24
23 24 25 26 27 28 29   27 28 29 30            25 26 27 28 29 30 31
30 31

[root@kongchao02 myroot]# 

 search find class

find command

The find command will recursively traverse its subdirectories from the specified directory downward, and display the files or directories that meet the conditions on the terminal

Basic syntax: find [search scope] [options]

Option Description:

Options Function
-name <query method> Find pattern files by specified filename
-user<username> Find all files belonging to the specified username
-size <file size> Find files by specified file size

 Example 1: Find by file name , find hello.txt under /home

[root@kongchao02 ~]# find /home -name hello.txt
/home/hello.txt
[root@kongchao02 ~]# 

 Example 2: Find kc user in /home by owner

[root@kongchao02 /]# ls /home
hello1.txt  hello.txt  kc  kongchao  kongchao1  kongchao2
[root@kongchao02 /]# find /home -user kc
/home/kc
/home/kc/.mozilla
/home/kc/.mozilla/plugins
/home/kc/.mozilla/extensions
/home/kc/.bash_profile
/home/kc/.bash_logout
/home/kc/.bashrc
[root@kongchao02 /]# 

 Example 3: Find by size , find files larger than 100M in the entire linux system (+n is greater than -n is less than n equal, the unit is k, M, G)

[root@kongchao02 ~]# find / -size +100M
/sys/devices/pci0000:00/0000:00:0f.0/resource1_wc
/sys/devices/pci0000:00/0000:00:0f.0/resource1
/proc/kcore
find: ‘/proc/6122/task/6122/fd/5’: 没有那个文件或目录
find: ‘/proc/6122/task/6122/fdinfo/5’: 没有那个文件或目录
find: ‘/proc/6122/fd/6’: 没有那个文件或目录
find: ‘/proc/6122/fdinfo/6’: 没有那个文件或目录
/var/cache/yum/x86_64/7/updates/packages/firefox-91.6.0-1.el7.centos.x86_64.rpm
/var/lib/rpm/Packages
/run/media/root/CentOS 7 x86_64/LiveOS/squashfs.img
/usr/lib/locale/locale-archive
/usr/lib64/firefox/libxul.so
[root@kongchao02 ~]# 

ls -lh visual display 

 ls -lh displays in human form

[root@kongchao02 ~]# ls -l
总用量 40
-rw-------. 1 root root 1834 2月  28 19:57 anaconda-ks.cfg
-rw-r--r--. 1 root root 1865 2月  28 19:59 initial-setup-ks.cfg
drwxr-xr-x. 2 root root 4096 2月  28 20:00 公共
drwxr-xr-x. 2 root root 4096 2月  28 20:00 模板
drwxr-xr-x. 2 root root 4096 2月  28 20:00 视频
drwxr-xr-x. 2 root root 4096 2月  28 20:00 图片
drwxr-xr-x. 2 root root 4096 2月  28 20:00 文档
drwxr-xr-x. 2 root root 4096 2月  28 20:00 下载
drwxr-xr-x. 2 root root 4096 2月  28 20:00 音乐
drwxr-xr-x. 2 root root 4096 3月   1 21:09 桌面
[root@kongchao02 ~]# ls -lh
总用量 40K
-rw-------. 1 root root 1.8K 2月  28 19:57 anaconda-ks.cfg
-rw-r--r--. 1 root root 1.9K 2月  28 19:59 initial-setup-ks.cfg
drwxr-xr-x. 2 root root 4.0K 2月  28 20:00 公共
drwxr-xr-x. 2 root root 4.0K 2月  28 20:00 模板
drwxr-xr-x. 2 root root 4.0K 2月  28 20:00 视频
drwxr-xr-x. 2 root root 4.0K 2月  28 20:00 图片
drwxr-xr-x. 2 root root 4.0K 2月  28 20:00 文档
drwxr-xr-x. 2 root root 4.0K 2月  28 20:00 下载
drwxr-xr-x. 2 root root 4.0K 2月  28 20:00 音乐
drwxr-xr-x. 2 root root 4.0K 3月   1 21:09 桌面
[root@kongchao02 ~]# 

 locate locate file path

locate command

The locate command can quickly locate the file path. The locate command utilizes the pre-established locate database of all file names and paths in the system to quickly locate a given file. The Locate command does not need to traverse the entire file system, and the query speed is faster. In order to ensure the accuracy of the query results, the administrator must regularly update the locate time

Basic syntax:  locate searches for files

Special Note

Since the locate command performs queries based on the database, you must use the updatedb command to create the locate database before running it for the first time . If the first lookup is not performed, it will not be retrieved

Application Example
Case 1: Please use the locate command to quickly locate the directory where the hello.txt file is located

[root@kongchao02 ~]# updatedb
[root@kongchao02 ~]# locate hello.txt
/home/hello.txt
[root@kongchao02 ~]# 

 which view command location

The which command can check which directory a command is in.

Basic syntax: the which directive

Example: Check which directory the ls and cd commands are in

[root@kongchao02 ~]# which ls
alias ls='ls --color=auto'
	/usr/bin/ls
[root@kongchao02 ~]# which cd
/usr/bin/cd
[root@kongchao02 ~]# 

grep filter directives and pipe symbols |

grep to filter the lookup. The pipe character " |" indicates that the output of the processing result of the previous command is passed to the subsequent command processing

Basic syntax: grep [options] find what source files

Common options:

Options Function
-n Show matches and line numbers
-i Ignore letter case

Example: In the hello.txt file, check the line where "yes" is located, and display the line number

写法①:cat /home/hello.txt | grep -n "yes"
写法②:grep -n "yes" /home/hello.txt
[root@kongchao02 /]# ls /home
hello.txt  kc  kongchao  kongchao1  kongchao2
[root@kongchao02 /]# cat -n /home/hello.txt 
     1	hello world
     2	yes 
     3	NO
     4	are you ok
     5	kongchao who is
     6	yes
     7	
[root@kongchao02 /]# cat /home/hello.txt | grep -n "yes"
2:yes 
6:yes
[root@kongchao02 /]# grep -n "yes" /home/hello.txt
2:yes 
6:yes
[root@kongchao02 /]# 

Guess you like

Origin blog.csdn.net/weixin_60719453/article/details/123400569