翼度科技»论坛 云主机 LINUX 查看内容

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

8

主题

8

帖子

24

积分

新手上路

Rank: 1

积分
24
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
  1. [root@HSP01 ~]# date
  2. 2023年 03月 10日 星期五 09:15:33 CST
  3. [root@HSP01 ~]# date +%m
  4. 03
  5. [root@HSP01 ~]# date "+%Y -%m-%d %H:%M:%S"
  6. 2023 -03-10 09:16:22
复制代码
1.2 cal

显示日历
cal    显示当月日历
cal 年份    显示某一年日历
  1. [root@HSP01 ~]# cal
  2.       三月 2023     
  3. 日 一 二 三 四 五 六
  4.           1  2  3  4
  5. 5  6  7  8  9 10 11
  6. 12 13 14 15 16 17 18
  7. 19 20 21 22 23 24 25
  8. 26 27 28 29 30 31
复制代码
2 搜索查找指令

 2.1 find

从指定目录向下遍历所有目录查找指定文件。
find 指定目录 -name  指定文件      从指定目录向下遍历所有目录按名称查找指定文件
find 指定目录 -user  指定用户名          查找指定目录下指定用户的所有文件
find 指定目录 -size  文件大小            查找指定目录下符合大小所有文件(+n 大于n   -n 小于n  n 等于   单位:k,M或G)
  1. [root@HSP01 ~]# find /home -name test      
  2. /home/test
  3. [root@HSP01 ~]# find /home -user sora
  4. /home/sora
  5. /home/sora/.bash_logout
  6. /home/sora/.config
  7. /home/sora/.config/abrt
  8. /home/sora/.bash_history
  9. /home/sora/.mozilla
  10. /home/sora/.mozilla/plugins
  11. /home/sora/.mozilla/extensions
  12. /home/sora/.bashrc
  13. /home/sora/.bash_profile
  14. /home/sora/.cache
  15. /home/sora/.cache/abrt
  16. /home/sora/.cache/abrt/lastnotification
  17. [root@HSP01 ~]# find /home -size +5M
  18. /home/laffy/.cache/mozilla/firefox/ri8vp6vr.default-default/startupCache/scriptCache.bin
复制代码
2.2 locate

locate可以实现快速定位文件路径,利用建立的路径系统可以在无需遍历整个系统的情况下快速查找文件。
locate  文件名
注:使用前先利用指令updatedb更新路径。
  1. [root@HSP01 ~]# updatedb
  2. [root@HSP01 ~]# locate Sora.PNG
  3. /home/sora/Sora.PNG
  4. /opt/tmp/home/sora/Sora.PNG
复制代码
3 grep&|

grep :过滤查找。
管道符“|”:表示将前一个命令的处理结果输出传递给后面的命令处理。
grep -n 查找内容 文件    在文件中查找相关内容且显示行号
grep -i 查找内容 文件    在文件中查找相关内容且忽略大小写(无论大小写都会被查找出来)
  1. [root@HSP01 test]# grep -n life /home/test/app.txt
  2. 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.
  3. [root@HSP01 test]# grep -i it /home/test/app.txt
  4. It is a wonderful day!
  5. wherever you are,it is no doubt that i will meet you.
  6. With the quickening pace of urban life and ever-increasing pressure, people in growing numbers are suffering from either the physical or mental problems.
  7. 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  路径 文件                解压文件到指定路径
  1. [root@HSP01 home]# ls
  2. jack laffy murasame myroot sora test
  3. [root@HSP01 home]# zip -r mytest.zip test
  4. adding: test/ (stored 0%)
  5. adding: test/A/ (stored 0%)
  6. adding: test/A/hello.cpp (deflated 48%)
  7. adding: test/A/B (deflated 26%)
  8. adding: test/A/app.txt (deflated 26%)
  9. adding: test/app.txt (deflated 38%)
  10. [root@HSP01 home]# ls
  11. jack laffy murasame myroot mytest.zip sora test
  12. [root@HSP01 home]# unzip -d /home/sora/ /home/mytest.zip
  13. Archive: /home/mytest.zip
  14. creating: /home/sora/test/
  15. creating: /home/sora/test/A/
  16. inflating: /home/sora/test/A/hello.cpp
  17. inflating: /home/sora/test/A/B
  18. inflating: /home/sora/test/A/app.txt
  19. inflating: /home/sora/test/app.txt
  20. [root@HSP01 home]# ls sora
  21. Sora.PNG test
复制代码
来源:https://www.cnblogs.com/lyf-cnblogs/p/17199065.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

举报 回复 使用道具