touch - change file timestamps
man touch
參 數:
-a或--time=atime或--time=access或--time=use 只更改存取時間。
-c或--no-create 不建立任何文件。
-d<時間日期> 使用指定的日期時間,而非現在的時間。
-f 此參數將忽略不予處理,僅負責解決BSD版本touch指令的兼容性問題。
-m或--time=mtime或--time=modify 只更改變動時間。
-r<參考文件或目錄> 把指定文件或目錄的日期時間,統統設成和參考文件或目錄的日期時間相同。
-t<日期時間> 使用指定的日期時間,而非現在的時間。
--help 在線幫助。
--version 顯示版本信息。
創建文件 touch test.txt
root@guofeng ~
# man touch
root@guofeng ~
# touch test.txt
root@guofeng ~
# ll
total 68
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Jun 6 18:47 b-ba-c.txt
-rw-r--r-- 1 root root 868 Jun 9 21:06 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
drwxrwxrwx 2 root root 4096 Jun 7 18:22 test
-rw-r--r-- 1 root root 0 Jun 11 20:01 test.txt
修改文件的創建時間爲當前的時間,touch -m test.txt
root@guofeng ~
# ll
total 68
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Jun 6 18:47 b-ba-c.txt
-rw-r--r-- 1 root root 868 Jun 9 21:06 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
drwxrwxrwx 2 root root 4096 Jun 7 18:22 test
-rw-r--r-- 1 root root 0 Jun 11 20:01 test.txt
root@guofeng ~
# touch -m test.txt
root@guofeng ~
# ll
total 68
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Jun 6 18:47 b-ba-c.txt
-rw-r--r-- 1 root root 868 Jun 9 21:06 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
drwxrwxrwx 2 root root 4096 Jun 7 18:22 test
-rw-r--r-- 1 root root 0 Jun 11 20:04 test.txt
touch -c a.txt 必須存在纔會創建文件
root@guofeng ~
# touch -c a.txt
root@guofeng ~
# ll
total 68
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Jun 6 18:47 b-ba-c.txt
-rw-r--r-- 1 root root 868 Jun 9 21:06 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
drwxrwxrwx 2 root root 4096 Jun 7 18:22 test
-rw-r--r-- 1 root root 0 Jun 11 20:04 test.txt
root@guofeng ~
# touch -c test.txt
root@guofeng ~
# ll
total 68
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Jun 6 18:47 b-ba-c.txt
-rw-r--r-- 1 root root 868 Jun 9 21:06 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
drwxrwxrwx 2 root root 4096 Jun 7 18:22 test
-rw-r--r-- 1 root root 0 Jun 11 20:06 test.txt
其餘的命令參數基本不用