linux基础(3)–实用指令2(时间指令、搜索指令和压缩指令)

  • linux基础(3)–实用指令2(时间指令、搜索指令和压缩指令)已关闭评论
  • 97 次浏览
  • A+
所属分类:linux技术
摘要

date       显示当前时间date +%Y    显示当前年份date +%m    显示当前月份


1 时间日期指令

1.1 date

date       显示当前时间

date +%Y    显示当前年份

date +%m    显示当前月份

date +%d     显示今天

date "+%Y -%m-%d %H:%M:%S"      显示年月日时分秒

date -s "2023-03-03 03:03:03"      设置时间为2023-03-03 03:03:03

[root@HSP01 ~]# date 2023年 03月 10日 星期五 09:15:33 CST [root@HSP01 ~]# date +%m 03 [root@HSP01 ~]# date "+%Y -%m-%d %H:%M:%S"  2023 -03-10 09:16:22

1.2 cal

显示日历

cal    显示当月日历

cal 年份    显示某一年日历

[root@HSP01 ~]# cal       三月 2023      日 一 二 三 四 五 六           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

2 搜索查找指令

 2.1 find

从指定目录向下遍历所有目录查找指定文件。

find 指定目录 -name  指定文件      从指定目录向下遍历所有目录按名称查找指定文件

find 指定目录 -user  指定用户名          查找指定目录下指定用户的所有文件

find 指定目录 -size  文件大小            查找指定目录下符合大小所有文件(+n 大于n   -n 小于n  n 等于   单位:k,M或G)

[root@HSP01 ~]# find /home -name test       /home/test [root@HSP01 ~]# find /home -user sora /home/sora /home/sora/.bash_logout /home/sora/.config /home/sora/.config/abrt /home/sora/.bash_history /home/sora/.mozilla /home/sora/.mozilla/plugins /home/sora/.mozilla/extensions /home/sora/.bashrc /home/sora/.bash_profile /home/sora/.cache /home/sora/.cache/abrt /home/sora/.cache/abrt/lastnotification [root@HSP01 ~]# find /home -size +5M /home/laffy/.cache/mozilla/firefox/ri8vp6vr.default-default/startupCache/scriptCache.bin

2.2 locate

locate可以实现快速定位文件路径,利用建立的路径系统可以在无需遍历整个系统的情况下快速查找文件。

locate  文件名

注:使用前先利用指令updatedb更新路径。

[root@HSP01 ~]# updatedb [root@HSP01 ~]# locate Sora.PNG /home/sora/Sora.PNG /opt/tmp/home/sora/Sora.PNG

3 grep&|

grep :过滤查找。

管道符“|”:表示将前一个命令的处理结果输出传递给后面的命令处理。

grep -n 查找内容 文件    在文件中查找相关内容且显示行号

grep -i 查找内容 文件    在文件中查找相关内容且忽略大小写(无论大小写都会被查找出来)

[root@HSP01 test]# grep -n life /home/test/app.txt 4:With the quickening pace of urban life and ever-increasing pressure, people in growing numbers are suffering from either the physical or mental problems. [root@HSP01 test]# grep -i it /home/test/app.txt  It is a wonderful day! wherever you are,it is no doubt that i will meet you. With the quickening pace of urban life and ever-increasing pressure, people in growing numbers are suffering from either the physical or mental problems. As the job market is getting gloomy and competition is becoming fierce, it is increasingly difficult for college undergraduates to find a decent job.

4 压缩解压指令

4.1 gzip&gunzip

gzip     压缩文件,不能用于文件夹

gunzip    解压文件,不能用于文件夹

4.2 zip&unzip

压缩或解压文件

zip  文件                  压缩文件

unzip 文件                 解压文件或文件夹

zip -r   压缩后文件名  文件夹              压缩文件夹

unzip -d  路径 文件                解压文件到指定路径

[root@HSP01 home]# ls jack laffy murasame myroot sora test [root@HSP01 home]# zip -r mytest.zip test adding: test/ (stored 0%) adding: test/A/ (stored 0%) adding: test/A/hello.cpp (deflated 48%) adding: test/A/B (deflated 26%) adding: test/A/app.txt (deflated 26%) adding: test/app.txt (deflated 38%) [root@HSP01 home]# ls jack laffy murasame myroot mytest.zip sora test   [root@HSP01 home]# unzip -d /home/sora/ /home/mytest.zip Archive: /home/mytest.zip creating: /home/sora/test/ creating: /home/sora/test/A/ inflating: /home/sora/test/A/hello.cpp inflating: /home/sora/test/A/B inflating: /home/sora/test/A/app.txt inflating: /home/sora/test/app.txt [root@HSP01 home]# ls sora Sora.PNG test