因为疫情原因工作出现了调整,后续可能常接触这些命令了,发现网上内容很难找到有一个能介绍所有命令的文章,所以这里整理了一些内容。
用户以及用户组管理
压缩和解压、搜索、日期的操作
文件以及目录的操作
权限,线程、系统健康度、磁盘情况
只能压缩为gz类型的文件,也只能解压此类型的文件,操作之后不保存原文件
语法
gzip 文件 (功能描述:压缩文件,只能将文件压缩为*.gz文件) gunzip 文件.gz (功能描述:解压缩文件命令)实际语句
# 压缩 gzip mytest.txt # 解压缩 gunzip mytest.txt.gz实际操作
创建一个mytest.txt文件然后进行压缩,然后对此文件进行解压缩
[root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# touch mytest.txt [root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# ls mytest.txt [root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# gzip mytest.txt [root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# ls mytest.txt.gz [root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# gunzip mytest.txt.gz [root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# ls mytest.txt返回内容解释
语法
zip [选项] XXX.zip 将要压缩的内容 (功能描述:压缩文件和目录的命令) unzip [选项] XXX.zip (功能描述:解压缩文件)可选参数
选项功能-r压缩目录-d{目录}指定解压缩后存放目录实际语句
# 压缩 zip csdn1.zip csdn # 解压缩 unzip csdn1.zip -d /root/csdn实际操作
将csdn目录压缩为csdn1.zip文件,并将文件解压多root/csdn的目录下
[root@iZbp1buyhgwtrw6hrp2ugjZ ~]# zip csdn1.zip csdn adding: csdn/ (stored 0%) [root@iZbp1buyhgwtrw6hrp2ugjZ ~]# ls a.out csdn csdn1.zip [root@iZbp1buyhgwtrw6hrp2ugjZ ~]# unzip csdn1.zip -d /root/csdn Archive: csdn1.zip creating: /root/csdn/csdn/ [root@iZbp1buyhgwtrw6hrp2ugjZ ~]# cd csdn [root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# ls csdn mytest.txt [root@iZbp1buyhgwtrw6hrp2ugjZ csdn]#语法
tar [选项] XXX.tar.gz 将要打包进去的内容 (功能描述:打包目录,压缩后的文件格式.tar.gz)可选参数
选项功能-ctar打包文件地址-v压缩时详细信息-f压缩后的文件名-z打包同时压缩-x解包.tar文件实际语句
# 压缩 tar -zcvf csdn.tar csdn houge.txt # 解压到当前目录 tar -zxvf csdn.tar实际操作
首先压缩csdn文件,然后对其在当前目录进行解压
[root@iZbp1buyhgwtrw6hrp2ugjZ ~]# tar -zcvf csdn.tar csdn csdn [root@iZbp1buyhgwtrw6hrp2ugjZ ~]# ls csdn csdn.tar # 当前目录解压 [root@iZbp1buyhgwtrw6hrp2ugjZ ~]# rm csdn rm: remove regular file ‘csdn’? y [root@iZbp1buyhgwtrw6hrp2ugjZ ~]# ls csdn.tar [root@iZbp1buyhgwtrw6hrp2ugjZ ~]# tar -zxvf csdn.tar csdn [root@iZbp1buyhgwtrw6hrp2ugjZ ~]# ls csdn csdn.tar [root@iZbp1buyhgwtrw6hrp2ugjZ ~]#语法
find [搜索范围] [选项]find的查询基于三种方式:根据指定的文件名称进行查询,查询用户的所有文件,根据文件大小进行查询。使用文件名称进行查询时比较常用的使用情况。
选项的查询
选项功能-name<查询方式>按照指定的文件名进行文件查找-user{用户名}查找属于指定用户名所有文件-size{根据文件大小}根据大小查询文件实际语句
# 寻找文件名中有value2的文件 [root@iZbp1buyhgwtrw6hrp2ugjZ testing]# find /usr/local/testing/confs -name *value2* /usr/local/testing/confs/order_sale_sql_last_value2.yml # 寻找root用户所属的文件 [root@iZbp1buyhgwtrw6hrp2ugjZ testing]# find /usr/local/testing/confs -user root /usr/local/testing/confs /usr/local/testing/confs/order_sale_sql_last_value.yml /usr/local/testing/confs/order_sale_sql_last_value2.yml语法
(1)date (功能描述:显示当前时间) (2)date +%Y (功能描述:显示当前年份) (3)date +%m (功能描述:显示当前月份) (4)date +%d (功能描述:显示当前是哪一天) (5)date "+%Y-%m-%d %H:%M:%S" (功能描述:显示年月日时分秒)实际语句
## 查询时间 [root@iZbp1buyhgwtrw6hrp2ugjZ confs]# date Sat Oct 3 14:14:43 CST 2020 ## 查询时间年份 [root@iZbp1buyhgwtrw6hrp2ugjZ confs]# date +%Y 2020 [root@iZbp1buyhgwtrw6hrp2ugjZ confs]# date "+%Y-%m-%d %H:%M:%S" 2020-10-03 14:14:56语法
(1)date -d '1 days ago' (功能描述:显示前一天时间) (2)date -d '-1 days ago' (功能描述:显示明天时间)实际语句
## 查询前一天的时间,并且使用格式化显示 [root@iZbp1buyhgwtrw6hrp2ugjZ confs]# date -d '1 days ago' Fri Oct 2 14:15:29 CST 2020 [root@iZbp1buyhgwtrw6hrp2ugjZ confs]# date -d '1 days ago' "+%Y-%m-%d %H:%M:%S" 2020-10-02 14:15:39语法
date -s 字符串时间实际语句
date -s "2020-10-02 14:18:39"语法
cal [选项] (功能描述:不加选项,显示本月日历)在选项中可以配置某一年来查看某一年的日历
实际语句
## 查看当前月份的日历 [root@iZbp1buyhgwtrw6hrp2ugjZ confs]# cal October 2020 Su Mo Tu We Th Fr Sa 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 ## 查看2021年6月份的日历,去掉月份参数可以查看一整年的日历 [root@iZbp1buyhgwtrw6hrp2ugjZ confs]# cal 6 2021 June 2021 Su Mo Tu We Th Fr Sa 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个人水平有限,上面的内容可能存在没有描述清楚或者错误的地方,假如开发同学发现了,请及时告知,我会第一时间修改相关内容。假如我的这篇内容对你有任何帮助的话,麻烦给我点一个赞。你的点赞就是我前进的动力。
