晶品空间装饰设计工作室王金平 发表于 2023-3-10 11:49:40

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

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
# date
2023年 03月 10日 星期五 09:15:33 CST
# date +%m
03
# date "+%Y -%m-%d %H:%M:%S"
2023 -03-10 09:16:221.2 cal

显示日历
cal    显示当月日历
cal 年份    显示某一年日历
# cal
      三月 2023   
日 一 二 三 四 五 六
          1234
56789 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 312 搜索查找指令

 2.1 find

从指定目录向下遍历所有目录查找指定文件。
find 指定目录 -name  指定文件      从指定目录向下遍历所有目录按名称查找指定文件
find 指定目录 -user  指定用户名          查找指定目录下指定用户的所有文件
find 指定目录 -size  文件大小            查找指定目录下符合大小所有文件(+n 大于n   -n 小于n  n 等于   单位:k,M或G)
# find /home -name test      
/home/test
# 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
# find /home -size +5M
/home/laffy/.cache/mozilla/firefox/ri8vp6vr.default-default/startupCache/scriptCache.bin2.2 locate

locate可以实现快速定位文件路径,利用建立的路径系统可以在无需遍历整个系统的情况下快速查找文件。
locate  文件名
注:使用前先利用指令updatedb更新路径。
# updatedb
# locate Sora.PNG
/home/sora/Sora.PNG
/opt/tmp/home/sora/Sora.PNG3 grep&|

grep :过滤查找。
管道符“|”:表示将前一个命令的处理结果输出传递给后面的命令处理。
grep -n 查找内容 文件    在文件中查找相关内容且显示行号
grep -i 查找内容 文件    在文件中查找相关内容且忽略大小写(无论大小写都会被查找出来)
# 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.
# 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  路径 文件                解压文件到指定路径
# ls
jack laffy murasame myroot sora test
# 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%)
# ls
jack laffy murasame myroot mytest.zip sora test


# 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
# ls sora
Sora.PNG test
来源:https://www.cnblogs.com/lyf-cnblogs/p/17199065.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: linux基础(3)--实用指令2(时间指令、搜索指令和压缩指令)