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" 設置時間為202 ...
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