2016-11-22 68 views
0

我正在尋找一種方法來在不同的文件系統上創建一個具有舊ctime的文件。 在Linux EXT,這是通過使用在FreeBSD UFS/MacOS X下更改文件的ctime HFS

touch /path/to/file debugfs -w -R 'set_inode_field /path/to/file ctime 201001010101' /dev/sdX echo 3 > /proc/sys/vm/drop_caches

是否有關於FreeBSD的UFS任何等效實現? 甚至可能在MacOSX HFS +上?

回答

1

在FreeBSD,使用-f選項可用於這方面的工作,例如touch命令:在20點22分十三秒

touch -t 0510242022.13 file 

將設置日期至2005年11月24日的格式[[CC]YY]MMDDhhmm[.SS],從man touch

-t  Change the access and modification times to the specified time 
      instead of the current time of day. The argument is of the form 
      ``[[CC]YY]MMDDhhmm[.SS]'' where each pair of letters represents 
      the following: 

        CC  The first two digits of the year (the century). 
        YY  The second two digits of the year. If ``YY'' is 
          specified, but ``CC'' is not, a value for ``YY'' 
          between 69 and 99 results in a ``CC'' value of 19. 
          Otherwise, a ``CC'' value of 20 is used. 
        MM  The month of the year, from 01 to 12. 
        DD  the day of the month, from 01 to 31. 
        hh  The hour of the day, from 00 to 23. 
        mm  The minute of the hour, from 00 to 59. 
        SS  The second of the minute, from 00 to 61. 

要改變的ctime你可以使用fsdb,大概你需要啓動單模式有以只讀模式,例如磁盤:

> fsdb /dev/vtbd0p2 
** /dev/vtbd0p2 (NO WRITE) 
Editing file system `/dev/vtbd0p2' 
Last Mounted on/
current inode: directory 
I=2 MODE=40755 SIZE=1024 
     BTIME=Sep 29 01:45:50 2016 [0 nsec] 
     MTIME=Nov 26 09:47:37 2016 [339135000 nsec] 
     CTIME=Nov 26 09:47:37 2016 [339135000 nsec] 
     ATIME=Nov 26 09:28:38 2016 [679268000 nsec] 
OWNER=root GRP=wheel LINKCNT=20 FLAGS=0 BLKCNT=8 GEN=37b9b524 
fsdb (inum: 2)> 

從那裏我可以到該目錄,然後選擇它:

fsdb (inum: 2)> cd /usr/home/nbari 

而且

fsdb (inum: 644816)> lookup file 

您可以鍵入active雙重檢查是文件,例如:

fsdb (inum: 642101)> active 
current inode: regular file 
I=642101 MODE=100644 SIZE=29 
     BTIME=Oct 24 20:22:13 2005 [0 nsec] 
     MTIME=Jan 1 12:12:12 2012 [0 nsec] 
     CTIME=Jan 1 12:12:12 2012 [0 nsec] 
     ATIME=Jan 1 12:12:12 2012 [0 nsec] 
OWNER=nbari GRP=nbari LINKCNT=1 FLAGS=0 BLKCNT=8 GEN=384445f7 

後來只是改變的ctime到你需要的日期:

fsdb (inum: 642101)> ctime 20121212010101 

格式YYYYMMDDHHMMSS[.nsec]

然後只需鍵入qexit,仔細檢查運行stat,例如退出:

> stat -x test_file 
    File: "test_file" 
    Size: 29   FileType: Regular File 
    Mode: (0644/-rw-r--r--)   Uid: (1002/ nbari) Gid: (1002/ nbari) 
Device: 0,68 Inode: 642101 Links: 1 
Access: Sun Jan 1 12:12:12 2012 
Modify: Sun Jan 1 12:12:12 2012 
Change: Sun Jan 1 12:12:12 2012 
+0

對不起,但你的答案只適用於修改atime或mtime,而不是ctime。 – deajan