四劍客第一關

liu4356發表於2024-03-13

四劍客第一關

1.修改當前時間為明天日期


date -s "2024-03-14"
date -s "$(date -d tomorrow +%Y-%m-%d)"


修改
date -s "$(date -d tomorrow +%Y-%m-%d)"
[root@master ~]# date -s "2024-03-13"
Wed Mar 13 00:00:00 CST 2024


[root@master ~]# date
Thu Mar 14 04:13:19 CST 2024
[root@master ~]# date -d tomorrow "+%Y-%m-%d"
2024-03-15


[root@master ~]# date -s "$(date -d tomorrow +%Y-%m-%d)"
Fri Mar 15 00:00:00 CST 2024
[root@master ~]# date
Fri Mar 15 00:00:02 CST 2024
[root@master ~]# 


  1. 把當前目錄file檔案複製到/home 顯示格式如下用當前時間 類似這樣/home/file.2022-03-8
cp file /home/file.$(date +%Y-%m-%d)




[root@master ~]# cp file /home/file.$(date +%Y-%m-%d)
[root@master ~]# cd /home
[root@master home]# ls
file.2024-03-13  

3.實時同步時間實操題:

 yum install ntp
 或者
 yum install chrony
    
    啟動服務 或者重新啟動服務
  systemctl start ntp
   systemctl enable ntp
    systemctl status ntp
   systemctl restart ntp 
   
   
 systemctl start chronyd
   systemctl enable chronyd
  systemctl status chronyd
  
  
  
  
  [root@master ~]# systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2024-03-13 00:19:58 CST; 20h ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
 Main PID: 14157 (chronyd)
   CGroup: /system.slice/chronyd.service
           └─14157 /usr/sbin/chronyd

Mar 13 00:19:58 master systemd[1]: Starting NTP client/server...
Mar 13 00:19:58 master chronyd[14157]: chronyd version 3.4 starting (+CMDMON +NTP +R...UG)
Mar 13 00:19:58 master systemd[1]: Started NTP client/server.
Mar 13 00:20:06 master chronyd[14157]: Could not set SO_TIMESTAMPING socket option
Mar 13 00:20:12 master chronyd[14157]: Selected source 211.68.71.118
Mar 13 00:20:12 master chronyd[14157]: System clock wrong by 73380.733755 seconds, a...ted
Mar 13 20:43:13 master chronyd[14157]: System clock was stepped by 73380.733755 seconds
Mar 13 20:43:13 master chronyd[14157]: Selected source 202.118.1.130
Hint: Some lines were ellipsized, use -l to show in full.
[root@master ~]# date
Wed Mar 13 20:47:42 CST 2024

  

4 軟硬連結的區別:

硬連結(ln): 建立指向相同inode的新檔名,刪除任一連線不會影響其他連線和資料
軟連線(ln-s) : 建立符號連結,類似於Windows中的快捷方式,如果原始檔案被刪除,軟連線將失效。


ln -s mysql5.7 mysql rm -rf mysql/ 這樣執行結果是啥 有風險嗎?

執行這個命令後,mysql目錄如果是軟連線且指向的原始目錄被刪除,則軟連線會變成死鏈,如果mysql5.7是一個檔案而不是目錄,那麼連線不會受影響,但原檔案會被刪除,存在誤刪風險。


5 使用find 檢視當前目錄下以a.開頭的所有檔案

find . -maxdepth 1 -type f -name "a.*"


[root@master ~]# find . -maxdepth 1 -type f -name "a.*"
./a.txt

6 檢視/etc/passwd的第六行 使用head和tail

head -n 6 /etc/passwd |tail -n 1



[root@master ~]# head -n 6 /etc/passwd |tail -n 1
sync:x:5:0:sync:/sbin:/bin/sync





[root@master ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
wang:x:1000:1000:wang:/home/wang:/bin/bash
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
it101:x:1001:1001::/home/it101:/bin/bash
it1:x:1002:1002::/home/it1:/bin/bash
it2:x:1003:1003::/home/it2:/bin/bash
it3:x:1004:1004::/home/it3:/bin/bash
it4:x:1005:1005::/home/it4:/bin/bash
it5:x:1006:1006::/home/it5:/bin/bash
it6:x:1007:1007::/home/it6:/bin/bash
it7:x:1008:1008::/home/it7:/bin/bash
it8:x:1009:1009::/home/it8:/bin/bash
it9:x:1010:1010::/home/it9:/bin/bash
it10:x:1011:1011::/home/it10:/bin/bash
it11:x:1012:1012::/home/it11:/bin/bash
it12:x:1013:1013::/home/it12:/bin/bash
it13:x:1014:1014::/home/it13:/bin/bash
it14:x:1015:1015::/home/it14:/bin/bash
it15:x:1016:1016::/home/it15:/bin/bash
it16:x:1017:1017::/home/it16:/bin/bash
it17:x:1018:1018::/home/it17:/bin/bash
it18:x:1019:1019::/home/it18:/bin/bash
it19:x:1020:1020::/home/it19:/bin/bash
it20:x:1021:1021::/home/it20:/bin/bash
it21:x:1022:1022::/home/it21:/bin/bash
it22:x:1023:1023::/home/it22:/bin/bash
it23:x:1024:1024::/home/it23:/bin/bash
it24:x:1025:1025::/home/it24:/bin/bash
it25:x:1026:1026::/home/it25:/bin/bash
it26:x:1027:1027::/home/it26:/bin/bash
it27:x:1028:1028::/home/it27:/bin/bash
it28:x:1029:1029::/home/it28:/bin/bash
it29:x:1030:1030::/home/it29:/bin/bash
it30:x:1031:1031::/home/it30:/bin/bash
it31:x:1032:1032::/home/it31:/bin/bash
it32:x:1033:1033::/home/it32:/bin/bash
it33:x:1034:1034::/home/it33:/bin/bash
it34:x:1035:1035::/home/it34:/bin/bash
it35:x:1036:1036::/home/it35:/bin/bash
it36:x:1037:1037::/home/it36:/bin/bash
it37:x:1038:1038::/home/it37:/bin/bash
it38:x:1039:1039::/home/it38:/bin/bash
it39:x:1040:1040::/home/it39:/bin/bash
it40:x:1041:1041::/home/it40:/bin/bash
it41:x:1042:1042::/home/it41:/bin/bash
it42:x:1043:1043::/home/it42:/bin/bash
it43:x:1044:1044::/home/it43:/bin/bash
it44:x:1045:1045::/home/it44:/bin/bash
it45:x:1046:1046::/home/it45:/bin/bash
it46:x:1047:1047::/home/it46:/bin/bash
it47:x:1048:1048::/home/it47:/bin/bash
it48:x:1049:1049::/home/it48:/bin/bash
it49:x:1050:1050::/home/it49:/bin/bash
it50:x:1051:1051::/home/it50:/bin/bash
it51:x:1052:1052::/home/it51:/bin/bash
it52:x:1053:1053::/home/it52:/bin/bash
it53:x:1054:1054::/home/it53:/bin/bash
it54:x:1055:1055::/home/it54:/bin/bash
it55:x:1056:1056::/home/it55:/bin/bash
it56:x:1057:1057::/home/it56:/bin/bash
it57:x:1058:1058::/home/it57:/bin/bash
it58:x:1059:1059::/home/it58:/bin/bash
it59:x:1060:1060::/home/it59:/bin/bash
it60:x:1061:1061::/home/it60:/bin/bash
it61:x:1062:1062::/home/it61:/bin/bash
it62:x:1063:1063::/home/it62:/bin/bash
it63:x:1064:1064::/home/it63:/bin/bash
it64:x:1065:1065::/home/it64:/bin/bash
it65:x:1066:1066::/home/it65:/bin/bash
it66:x:1067:1067::/home/it66:/bin/bash
it67:x:1068:1068::/home/it67:/bin/bash
it68:x:1069:1069::/home/it68:/bin/bash
it69:x:1070:1070::/home/it69:/bin/bash
it70:x:1071:1071::/home/it70:/bin/bash
it71:x:1072:1072::/home/it71:/bin/bash
it72:x:1073:1073::/home/it72:/bin/bash
it73:x:1074:1074::/home/it73:/bin/bash
it74:x:1075:1075::/home/it74:/bin/bash
it75:x:1076:1076::/home/it75:/bin/bash
it76:x:1077:1077::/home/it76:/bin/bash
it77:x:1078:1078::/home/it77:/bin/bash
it78:x:1079:1079::/home/it78:/bin/bash
it79:x:1080:1080::/home/it79:/bin/bash
it80:x:1081:1081::/home/it80:/bin/bash
it81:x:1082:1082::/home/it81:/bin/bash
it82:x:1083:1083::/home/it82:/bin/bash
it83:x:1084:1084::/home/it83:/bin/bash
it84:x:1085:1085::/home/it84:/bin/bash
it85:x:1086:1086::/home/it85:/bin/bash
it86:x:1087:1087::/home/it86:/bin/bash
it87:x:1088:1088::/home/it87:/bin/bash
it88:x:1089:1089::/home/it88:/bin/bash
it89:x:1090:1090::/home/it89:/bin/bash
it90:x:1091:1091::/home/it90:/bin/bash
it91:x:1092:1092::/home/it91:/bin/bash
it92:x:1093:1093::/home/it92:/bin/bash
it93:x:1094:1094::/home/it93:/bin/bash
it94:x:1095:1095::/home/it94:/bin/bash
it95:x:1096:1096::/home/it95:/bin/bash
it96:x:1097:1097::/home/it96:/bin/bash
it97:x:1098:1098::/home/it97:/bin/bash
it98:x:1099:1099::/home/it98:/bin/bash
it99:x:1100:1100::/home/it99:/bin/bash
it100:x:1101:1101::/home/it100:/bin/bash
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
oldboy01:x:1102:1103::/home/oldboy01:/bin/bash
oldboy02:x:1103:1104::/home/oldboy02:/bin/bash
oldboy03:x:1104:1105::/home/oldboy03:/bin/bash
oldboy04:x:1105:1106::/home/oldboy04:/bin/bash
oldboy05:x:1106:1107::/home/oldboy05:/bin/bash
oldboy06:x:1107:1108::/home/oldboy06:/bin/bash
oldboy07:x:1108:1109::/home/oldboy07:/bin/bash
oldboy08:x:1109:1110::/home/oldboy08:/bin/bash
oldboy09:x:1110:1111::/home/oldboy09:/bin/bash
oldboy10:x:1111:1112::/home/oldboy10:/bin/bash
mailuser:x:1112:1113::/home/mailuser:/bin/bash
oldboy:x:1113:1114::/home/oldboy:/bin/bash
dhcpd:x:177:177:DHCP server:/:/sbin/nologin
geoclue:x:998:996:User for geoclue:/var/lib/geoclue:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
chrony:x:997:995::/var/lib/chrony:/sbin/nologin

7 檢視已使用總記憶體

free -m
df -h
free -h



[root@master ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            979         106         524           6         348         675
Swap:          4095           0        4095
[root@master ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           979M        106M        524M        6.7M        348M        675M
Swap:          4.0G          0B        4.0G
[root@master ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        94G  2.1G   92G   3% /
devtmpfs        481M     0  481M   0% /dev
tmpfs           490M     0  490M   0% /dev/shm
tmpfs           490M  6.8M  484M   2% /run
tmpfs           490M     0  490M   0% /sys/fs/cgroup
/dev/sda3        47G   69M   47G   1% /data
/dev/sda1      1014M  122M  893M  12% /boot
tmpfs            98M     0   98M   0% /run/user/0

8 echo 3 >/proc/sys/vm/drop_caches 是什麼意思

清理核心快取的命令,數字3代表清理所有快取型別。執行此命令後,系統會立即釋放快取資料,可能導致瞬間效能下降,但在某些情況下可回收大量空閒記憶體

9 MySQL的預設埠號是啥

3306

10 在/linux目錄下查詢許可權為644的檔案,並移動到/tmp目錄下

find . -type f -perm 644 -exec mv {} /tmp \;




[root@master tmp]# ll
total 16656
-rw-r--r-- 1 root root        0 Mar 11 03:04 10.log
-rw-r--r-- 1 root root        0 Mar 11 03:17 10.txt
-rw-r--r-- 1 root root        0 Mar 11 03:17 {1.10}.txt
-rw-r--r-- 1 root root        0 Mar 11 03:04 11.log
-rw-r--r-- 1 root root        0 Mar 11 03:04 12.log
-rw-r--r-- 1 root root        0 Mar 11 03:04 13.log
-rw-r--r-- 1 root root        0 Mar 11 03:04 14.log
-rw-r--r-- 1 root root        0 Mar 11 03:04 15.log
-rw-r--r-- 1 root root        0 Mar 11 03:04 16.log
-rw-r--r-- 1 root root        0 Mar 11 03:04 17.log
-rw-r--r-- 1 root root        0 Mar 11 03:04 18.log
-rw-r--r-- 1 root root        0 Mar 11 03:04 19.log
-rw-r--r-- 1 root root        0 Mar 11 03:04 1.log
-rw-r--r-- 1 root root        0 Mar 11 03:17 1.txt
-rw-r--r-- 1 root root        0 Mar 11 05:07 2
-rw-r--r-- 1 root root        0 Mar 11 03:04 20.log
-rw-r--r-- 1 root root      293 Mar 11 05:07 2.log
-rw-r--r-- 1 root root        0 Mar 11 03:17 2.txt
-rw-r--r-- 1 root root        0 Mar 11 03:04 3.log
-rw-r--r-- 1 root root        0 Mar 11 03:17 3.txt
-rw-r--r-- 1 root root        0 Mar 11 03:04 4.log
-rw-r--r-- 1 root root        0 Mar 11 03:17 4.txt
-rw-r--r-- 1 root root        0 Mar 11 03:04 5.log
-rw-r--r-- 1 root root        0 Mar 11 03:17 5.txt
-rw-r--r-- 1 root root        0 Mar 11 03:04 6.log
-rw-r--r-- 1 root root        0 Mar 11 03:17 6.txt
-rw-r--r-- 1 root root        0 Mar 11 03:04 7.log
-rw-r--r-- 1 root root        0 Mar 11 03:17 7.txt
-rw-r--r-- 1 root root        0 Mar 11 03:04 8.log
-rw-r--r-- 1 root root        0 Mar 11 03:17 8.txt
-rw-r--r-- 1 root root        0 Mar 11 03:04 9.log
-rw-r--r-- 1 root root        0 Mar 11 03:17 9.txt
-rw-r--r-- 1 root root        0 Mar 13 21:01 a10.txt
-rw-r--r-- 1 root root        0 Mar 13 21:01 a1.txt
-rw-r--r-- 1 root root        0 Mar 13 21:01 a2.txt
-rw-r--r-- 1 root root        0 Mar 13 21:01 a3.txt
-rw-r--r-- 1 root root        0 Mar 13 21:01 a4.txt
-rw-r--r-- 1 root root        0 Mar 13 21:01 a5.txt
-rw-r--r-- 1 root root        0 Mar 13 21:01 a6.txt
-rw-r--r-- 1 root root        0 Mar 13 21:01 a7.txt
-rw-r--r-- 1 root root        0 Mar 13 21:01 a8.txt
-rw-r--r-- 1 root root        0 Mar 13 21:01 a9.txt
-rw-r--r-- 1 root root  2881142 Mar 12 06:17 access.log
-rw-r--r-- 1 root root        0 Mar 11 02:54 acclog.log
-rw-r--r-- 1 root root       32 Mar 13 21:02 a.txt
-rw-r--r-- 1 root root      592 Mar 14  2024 awk
-rw-r--r-- 1 root root     2006 Dec  1  2016 CentOS6-Base-163.repo
-rw-r--r-- 1 root root      205 Mar 11 02:13 data-20240208.tar.gz
-rw-r--r-- 1 root root      205 Mar 11 02:16 data-20240209.tar.gz
-rw-r--r-- 1 root root      165 Mar 13 00:11 file
-rw-r--r-- 1 root root        0 Mar  8 05:11 hosts
-rw-r--r-- 1 root root      998 Mar 12 06:17 ip2.sh
-rw-r--r-- 1 root root      313 Mar 11 03:05 log.tar.gz
-rw-r--r-- 1 root root      128 Mar  9 20:48 motd
-rw-r--r-- 1 root root     2537 Mar  1 04:25 nwq1.6.sh
-rw-r--r-- 1 root root       32 Mar 14  2024 nwq.txt
-rw-r--r-- 1 root root     5612 Mar 14  2024 passwd
-rw-r--r-- 1 root root     3902 Mar 14  2024 person.txt
-rw-r--r-- 1 root root        0 Mar  9 20:51 profile
-rw-r--r-- 1 root root      224 Mar 12 04:50 redis
-rw-r--r-- 1 root root 11394981 Mar 11 02:20 services
-rw-r--r-- 1 root root  2312172 Mar 11 02:21 services.tar.gz
drwx------ 3 root root       16 Mar 13 00:19 systemd-private-f91239fad7be48c9adf50c012c17b403-chronyd.service-664wKY
-rw-r--r-- 1 root root        0 Mar 14  2024 test10.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test11.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test12.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test13.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test14.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test15.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test16.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test17.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test18.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test19.txt
-rw-r--r-- 1 root root      432 Mar 14  2024 test1.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test20.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test21.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test22.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test23.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test24.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test25.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test26.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test27.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test28.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test29.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test2.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test30.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test3.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test4.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test5.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test6.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test7.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test8.txt
-rw-r--r-- 1 root root        0 Mar 14  2024 test9.txt
-rw-r--r-- 1 root root      339 Mar 11 02:37 test.tar.gz
-rw------- 1 root root   385285 Mar  9 20:43 yum_save_tx.2024-03-09.20-43.MjeG_P.yumtx



r 4
w 2
x 1


11 用sed修改test.txt的第十行的Linux為test

sed -i '10 s/Linux/test/g' test.txt



[root@master ~]# cat test.txt
Line 1
Line with test word
Line after the first test
Some other lines...
Another line with test
More content here...



Linux


fgasg
fgasdgdf



dfgdfg



dfgasdg



fga

a
g
asg

gagadgadg

agas




[root@master ~]# sed -i '10s/Linux/test/g' test.txt
[root@master ~]# cat test.txt
Line 1
Line with test word
Line after the first test
Some other lines...
Another line with test
More content here...



test


fgasg
fgasdgdf



dfgdfg



dfgasdg



fga

a
g
asg

gagadgadg

agas



12 給一個檔案a.sh 加一個執行許可權

chmod +x a.sh


13 redis 文字
work 16067 /data/svr/redis/bin/redis-server:6403
work 16067 /data/svr/redis/bin/redis-server
:6403
work 16067 /data/svr/redis/bin/redis-server:6403
work 16067 /data/svr/redis/bin/redis-server
:6403

如何列印 只要 程序號,請給出一個命令:


cat redis |awk '{print $2}'




[root@master ~]# cat redis |awk '{print $2}'
16067
16067
16067
16067

如何列印第二列pid 和最後一列埠列印出來 ,請給出一個命令實現:


 awk '{split($NF, a, ":"); port=a[length(a)]; gsub(/[^0-9]/, "",port); print $2,port}' redis.txt



[root@master ~]# cat redis.txt
work   16067     /data/svr/redis/bin/redis-server*:6403
work   16067     /data/svr/redis/bin/redis-server*:6403
work   16067     /data/svr/redis/bin/redis-server*:6403
work   16067     /data/svr/redis/bin/redis-server*:6403

[root@master ~]# awk '{split($NF, a, ":"); port=a[length(a)]; gsub(/[^0-9]/, "",port); print $2,port}' redis.txt
16067 6403
16067 6403
16067 6403
16067 6403

14 linux系統中如何獲取 pid 9257的程序號監聽的埠是什麼 給出命令

ss -tulnp |grep 9257
netstat -tulnp |grep 9257
lsof -i -P -n -p 9257




lsof -p 9257 -iTCP -sTCP:LISTEN




[root@master ~]# lsof -i -P -n -p 9257
COMMAND    PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sshd       976   root    3u  IPv4  16652      0t0  TCP *:22 (LISTEN)
sshd       976   root    4u  IPv6  16654      0t0  TCP *:22 (LISTEN)
master    1196   root   13u  IPv4  17308      0t0  TCP 127.0.0.1:25 (LISTEN)
master    1196   root   14u  IPv6  17309      0t0  TCP [::1]:25 (LISTEN)
sshd      2093   root    3u  IPv4  18103      0t0  TCP 10.0.0.164:22->10.0.0.1:1888 (ESTABLISHED)
chronyd  14157 chrony    5u  IPv4  66584      0t0  UDP 127.0.0.1:323 
chronyd  14157 chrony    6u  IPv6  66585      0t0  UDP [::1]:323 
dhclient 14259   root    6u  IPv4  66981      0t0  UDP *:68 
[root@master ~]# netstat -tulpn |grep 9257
[root@master ~]# ss -tulpn |grep 9257

15 如何查詢 /data/log 修改時間為3天之前檔案 移動到 /home

find /data/log -type f -mtime +3 -exec mv {} /home/ \;



 查詢 `/data` 目錄下以 `.log` 結尾、修改時間在3天以前、的檔案,並移動到 `/temp` 目錄(這裡假設您是想寫 `/tmp` 目錄):
   ```bash
  find /data/log -type f -mtime +3 -exec mv {} /home/ \;

注:請確保路徑 /tmp 的正確性以及 mv 命令後有反斜槓 \; 來結束 -exec 引數。

相關文章