touch 修改檔案時間與建置新檔
[root@dywHome2 ~]# ll /etc/man.config %*<==預設為 mtime*) -rw-r--r-- 1 root root 4831 Feb 3 2008 /etc/man.config [root@dywHome2 ~]# ll --time=atime /etc/man.config -rw-r--r-- 1 root root 4831 Sep 5 09:30 /etc/man.config [root@dywHome2 ~]# ll --time=ctime /etc/man.config -rw-r--r-- 1 root root 4831 Feb 3 2008 /etc/man.config [root@dywHome2 ~]# ll --time=mtime /etc/man.config
[root@linux ~]# touch [-acdmt] 檔案 參數: -a :僅修訂 access time; -c :僅修改時間,而不建立檔案; -d :後面可以接日期,也可以使用 --date="日期或時間" -m :僅修改 mtime ; -t :後面可以接時間,格式為[YYMMDDhhmm] #範例: #範例一:新建一個空的檔案 [root@linux ~]# cd /tmp [root@linux tmp]# touch testtouch [root@linux tmp]# ls -l testtouch -rw-r--r-- 1 root root 0 Jul 19 20:49 testtouch #範例二:將 ~/.bashrc 複製成為 bashrc,假設複製完全的屬性,檢查其日期 [root@linux tmp]# cp ~/.bashrc bashrc [root@linux tmp]# ll bashrc; ll --time=atime bashrc; ll --time=ctime bashrc -rwxr-xr-x 1 root root 395 Jul 4 11:45 bashrc %*<==這是 mtime*) -rwxr-xr-x 1 root root 395 Jul 19 20:44 bashrc %*<==這是 atime*) -rwxr-xr-x 1 root root 395 Jul 19 20:53 bashrc %*<==這是 ctime*) #範例三:修改案例二的 bashrc 檔案,將日期調整為兩天前 [root@linux tmp]# touch -d "2 days ago" bashrc [root@linux tmp]# ll bashrc; ll --time=atime bashrc; ll --time=ctime bashrc -rwxr-xr-x 1 root root 395 Jul 17 21:02 bashrc -rwxr-xr-x 1 root root 395 Jul 17 21:02 bashrc -rwxr-xr-x 1 root root 395 Jul 19 21:02 bashrc # 日期在 atime 與 mtime 都改變了,但是 ctime 則是記錄目前的時間! #範例四:將上個範例的 bashrc 日期改為 2005/07/15 2:02 [root@linux tmp]# touch -t 0507150202 bashrc [root@linux tmp]# ll bashrc; ll --time=atime bashrc; ll --time=ctime bashrc -rwxr-xr-x 1 root root 395 Jul 15 02:02 bashrc -rwxr-xr-x 1 root root 395 Jul 15 02:02 bashrc -rwxr-xr-x 1 root root 395 Jul 19 21:05 bashrc
練習題