contenu
commande d'heure d'affichage de la date
commande de réglage de la date
localiser localiser le chemin du fichier
quel emplacement de commande de vue
directives de filtre grep et symboles de canal |
heure date classe
commande d'heure d'affichage de la date
Syntaxe de base :
date (afficher l'heure actuelle)
date +%Y (affiche l'année en cours)
date +%m (affiche le mois en cours)
date +%d (affiche le jour actuel)
date " +%Y-%m-%d %H:%M:%S" (affichage année, mois, jour, heure, minute, seconde)
Exemple : Démonstration de la commande ci-dessus
[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]#
commande de réglage de la date
Syntaxe de base : date -s chaîne heure
L'exemple définit l'heure actuelle du système,
[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]#
calendrier des spectacles cal
Afficher les instructions du calendrier cal
Syntaxe de base : cal [options] (affiche le calendrier de ce mois sans options)
Afficher un calendrier pour une année telle que 2022, cal 2022
Exemple 1, afficher le cal du mois en cours
[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]#
Exemple 2 : Afficher le calendrier 2022 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]#
rechercher trouver la classe
trouver la commande
La commande find parcourra récursivement ses sous-répertoires à partir du répertoire spécifié vers le bas et affichera les fichiers ou répertoires qui remplissent les conditions sur le terminal
Syntaxe de base : trouver [étendue de la recherche] [options]
Description des options :
Choix | Une fonction |
-name <méthode de requête> | Rechercher des fichiers de modèle par nom de fichier spécifié |
-user<nom d'utilisateur> | Trouver tous les fichiers appartenant au nom d'utilisateur spécifié |
-size <taille du fichier> | Rechercher des fichiers par taille de fichier spécifiée |
Exemple 1 : Rechercher par nom de fichier , rechercher hello.txt sous /home
[root@kongchao02 ~]# find /home -name hello.txt
/home/hello.txt
[root@kongchao02 ~]#
Exemple 2 : Rechercher l'utilisateur kc dans /home par le propriétaire
[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 /]#
Exemple 3 : Rechercher par taille , trouver des fichiers de plus de 100 Mo dans l'ensemble du système Linux (+n est supérieur à -n est inférieur à n égal, l'unité est 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 ~]#
affichage visuel ls-lh
ls -lh s'affiche sous forme humaine
[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 ~]#
localiser localiser le chemin du fichier
commande de localisation
La commande de localisation peut localiser rapidement le chemin du fichier. La commande de localisation utilise la base de données de localisation préétablie de tous les noms de fichiers et chemins d'accès dans le système pour localiser rapidement un fichier donné. La commande Locate n'a pas besoin de parcourir tout le système de fichiers et la vitesse de requête est plus rapide. Afin d'assurer l'exactitude des résultats de la requête, l'administrateur doit régulièrement mettre à jour l'heure de localisation
Syntaxe de base : locate recherche des fichiers
Note spéciale
Étant donné que la commande locate effectue des requêtes basées sur la base de données, vous devez utiliser la commande updatedb pour créer la base de données locate avant de l'exécuter pour la première fois . Si la première recherche n'est pas effectuée, elle ne sera pas récupérée
Exemple d'application
Cas 1 : Veuillez utiliser la commande locate pour localiser rapidement le répertoire où se trouve le fichier hello.txt
[root@kongchao02 ~]# updatedb
[root@kongchao02 ~]# locate hello.txt
/home/hello.txt
[root@kongchao02 ~]#
quel emplacement de commande de vue
La commande which peut vérifier dans quel répertoire se trouve une commande.
Syntaxe de base : la directive which
Exemple : Vérifiez dans quel répertoire se trouvent les commandes ls et cd
[root@kongchao02 ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
[root@kongchao02 ~]# which cd
/usr/bin/cd
[root@kongchao02 ~]#
directives de filtre grep et symboles de canal |
grep pour filtrer la recherche. Le caractère pipe " |" indique que la sortie du résultat du traitement de la commande précédente est transmise au traitement de la commande suivante
Syntaxe de base : grep [options] trouve les fichiers source
Options communes :
Choix | Une fonction |
-n | Afficher les correspondances et les numéros de ligne |
-je | Ignorer la casse |
Exemple : Dans le fichier hello.txt, cochez la ligne où se trouve "oui" et affichez le numéro de ligne
写法①: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 /]#