linux 修改檔案的時間屬性

2022-09-16 04:06:11 字數 2109 閱讀 3981

二、修改檔案時間

-a : 僅修改access time。

-c : 僅修改時間,而不建立檔案。

-d : 後面可以接日期,也可以使用 --date="日期或時間"

-m : 僅修改mtime。

-t : 後面可以接時間,格式為 [yymmddhhmm]

注:如果touch後面接乙個已經存在的檔案,則該檔案的3個時間(atime/ctime/mtime)都會更新為當前時間。若該檔案不存在,則會主動建立乙個新的空檔案。

[root@web10 ~]# touch install.log

[root@web10 ~]# stat install.log

file: 「install.log」

size: 33386 blocks: 80 io block: 4096 一般檔案

device: fd00h/64768d inode: 7692962 links: 1

access: (0644/-rw-r--r--) uid: ( 0/ root) gid: ( 0/ root)

access: 2012-07-13 16:21:50.000000000 +0800

modify: 2012-07-13 16:21:50.000000000 +0800

change: 2012-07-13 16:21:50.000000000 +0800

同樣,使用ls ,檢視到的結果也一樣。

[root@web10 ~]# ls -l --time=ctime install.log

-rw-r--r-- 1 root root 33386 07-13 16:21 install.log

[root@web10 ~]# ls -l --time=atime install.log

-rw-r--r-- 1 root root 33386 07-13 16:21 install.log

[root@web10 ~]# ls -l install.log

-rw-r--r-- 1 root root 33386 07-13 16:21 install.log

[root@web10 ~]# cp /etc/profile .;ll --time=atime profile ;ll --time=ctime profile

cp:是否覆蓋「./profile」? y

-rw-r--r-- 1 root root 1344 07-13 16:24 profile

-rw-r--r-- 1 root root 1344 07-13 16:25 profile

因為我之前執行過這個命令一次,所以會出現覆蓋,不過這個覆蓋出的好,剛才讓我們看到了atime和ctime的時間的差別。

1. 同時修改檔案的修改時間和訪問時間

touch -d "2010-05-31 08:10:30" install.log

2. 只修改檔案的修改時間

touch -m -d "2010-05-31 08:10:30" install.log

3. 只修改檔案的訪問時間

touch -a -d "2010-05-31 08:10:30" install.log

下面再給乙個rootkit木馬常用的伎倆。就是把後乙個檔案的時間修改成和前乙個相同。

touch -acmr /bin/ls /etc/sh.conf
[root@web10 ~]# touch -d "2 days ago" install.log ; ll install.log

-rw-r--r-- 1 root root 33386 07-11 16:35 install.log

最後總結下常用的檔案操作與時間的關係:

1、訪問時間,讀一次這個檔案的內容,這個時間就會更新。比如對這個檔案使用more命令。ls、stat命令都不會修改檔案的訪問時間。

2、修改時間,對檔案內容修改一次,這個時間就會更新。比如:vim後儲存檔案。ls -l列出的時間就是這個時間。

3、狀態改變時間。通過chmod命令更改一次檔案屬性,這個時間就會更新。檢視檔案的詳細的狀態、準確的修改時間等,可以通過stat命令 檔名

Linux 修改檔案使用者屬性

chgrp命令 功能 改變檔案或目錄所屬的組。語法 chgrp 選項 group filename?該命令改變指定指定檔案所屬的使用者組。其中group可以是使用者組id,也可以是 etc group檔案中使用者組的組名。檔名是以空格分開的要改變屬組的檔案列表,支援萬用字元。如果使用者不是該檔案的屬...

Linux 修改檔案使用者屬性

chgrp命令 功能 改變檔案或目錄所屬的組。語法 chgrp 選項 group filename?該命令改變指定指定檔案所屬的使用者組。其中group可以是使用者組id,也可以是 etc group檔案中使用者組的組名。檔名是以空格分開的要改變屬組的檔案列表,支援萬用字元。如果使用者不是該檔案的屬...

Linux 修改檔案屬性

1.chgrp chanage group 更改檔案屬組chgrp r 屬組名 檔名2.chown chanage owner 更改檔案屬主,也可以同時更改檔案屬組chown r 屬主名 檔名 chown r 屬主名 屬組名 檔名3.chmod chanage owner 更改檔案9個屬性 必須掌握...