簡明Linux命令列筆記:touch

來源:互聯網
上載者:User
文章目錄
  • 參數
  • 選項
  • 樣本
  • Tips

建立檔案或修改檔案時間

touch [options] file-list

 

參數

file-listtouch將要建立或更新的檔案路徑名

 

選項

-a                    只更新訪問時間,不改變修改時間

-c                    不建立不存在的檔案

-m                   只更新修改時間,不改變訪問時間

-r file               使用檔案file的時間更新檔案的時間

-t                     將時間修改為參數指定的日期,如:07081556代表7月8號15點56分

 

樣本touch 更新已有檔案時間
$ ls -l Firefox_wallpaper.png -rw-r--r-- 1 siu siu 309597 12月 20 15:03 Firefox_wallpaper.png$ touch Firefox_wallpaper.png $ ls -l Firefox_wallpaper.png -rw-r--r-- 1 siu siu 309597  1月  8 15:18 Firefox_wallpaper.png

touch 無選項,會同時更新檔案的修改時間和訪問時間

 

touch 建立檔案
$ touch demo.c$ ls -l總用量 372-rw-r--r-- 1 siu siu      0  1月  8 15:21 demo.c

 

touch -at 使用參數更新訪問時間

首先看看原來的修改時間和訪問時間,ls -lu用來查看訪問時間

$ ls -l總用量 68-rw-r--r-- 1 siu siu 66350 12月 23 16:51 hs_err_pid2874.log$ ls -lu總用量 68-rw-r--r-- 1 siu siu 66350  1月  8 15:17 hs_err_pid2874.log

接著是更新過後的修改時間和訪問時間

$ touch -at 01081010 hs_err_pid2874.log $ ls -l總用量 68-rw-r--r-- 1 siu siu 66350 12月 23 16:51 hs_err_pid2874.log$ ls -lu總用量 68-rw-r--r-- 1 siu siu 66350  1月  8 10:10 hs_err_pid2874.log

可以看到,修改時間沒有變動,但是訪問時間改變了

 

touch -m 只更新修改時間
$ ls -l總用量 68-rw-r--r-- 1 siu siu 66350 12月 23 16:51 hs_err_pid2874.log$ touch -m hs_err_pid2874.log $ ls -l總用量 68-rw-r--r-- 1 siu siu 66350  1月  8 15:31 hs_err_pid2874.log$ ls -lu總用量 68-rw-r--r-- 1 siu siu 66350  1月  8 10:10 hs_err_pid2874.log

由上面的樣本可知,此處訪問時間沒有改變,而修改時間發生了變動

 

Tips

1.可以用預設的目前時間來更新檔案的訪問時間和修改時間,也可以指定參數來更新

2.通常情況下,touch用的最多的地方還是在於建立新檔案

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.