Linux經常使用基本命令( touch )

touch命令:node

做用:建立空文件,或者改變文件的時間戳屬性linux

格式: touch [option] [file]vim

1,同時建立一個或者多個空文件spa

ghostwu@dev:~/linux/mkdir$ ls
ghostwu@dev:~/linux/mkdir$ touch a.txt
ghostwu@dev:~/linux/mkdir$ ls
a.txt
ghostwu@dev:~/linux/mkdir$ touch b.txt c.txt
ghostwu@dev:~/linux/mkdir$ ls
a.txt  b.txt  c.txt
ghostwu@dev:~/linux/mkdir$ touch {1..5}.txt
ghostwu@dev:~/linux/mkdir$ ls
1.txt  2.txt  3.txt  4.txt  5.txt  a.txt  b.txt  c.txt

2,建立文件,並用stat查看文件的屬性狀態信息code

ghostwu@dev:~/linux/mkdir$ touch ghostwu.txt
ghostwu@dev:~/linux/mkdir$ stat ghostwu.txt 
  File: 'ghostwu.txt'
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 807h/2055d    Inode: 9569451     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/ ghostwu)   Gid: ( 1000/ ghostwu)
Access: 2018-05-01 17:25:16.439856937 +0800
Modify: 2018-05-01 17:25:16.439856937 +0800
Change: 2018-05-01 17:25:16.439856937 +0800
 Birth: -

最後有3個時間blog

Access time: 最後訪問時間,查看文件的內容時,這個時間會改變,使用cat命令查看文件時,能夠看出Access time已經變了io

ghostwu@dev:~/linux/mkdir$ stat ghostwu.txt 
  File: 'ghostwu.txt'
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 807h/2055d    Inode: 9569451     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/ ghostwu)   Gid: ( 1000/ ghostwu)
Access: 2018-05-01 17:25:16.439856937 +0800
Modify: 2018-05-01 17:25:16.439856937 +0800
Change: 2018-05-01 17:25:16.439856937 +0800
 Birth: -
ghostwu@dev:~/linux/mkdir$ cat ghostwu.txt 
ghostwu@dev:~/linux/mkdir$ stat ghostwu.txt 
  File: 'ghostwu.txt'
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 807h/2055d    Inode: 9569451     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/ ghostwu)   Gid: ( 1000/ ghostwu)
Access: 2018-05-01 17:27:51.887215139 +0800
Modify: 2018-05-01 17:25:16.439856937 +0800
Change: 2018-05-01 17:25:16.439856937 +0800
 Birth: -

 

Modify time:最後修改時間,修改文件內容,文件的修改時間會改變。訪問時間和狀態改變時間 也發生變化class

ghostwu@dev:~/linux/mkdir$ stat ghostwu.txt 
  File: 'ghostwu.txt'
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 807h/2055d    Inode: 9569451     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/ ghostwu)   Gid: ( 1000/ ghostwu)
Access: 2018-05-01 17:27:51.887215139 +0800
Modify: 2018-05-01 17:25:16.439856937 +0800
Change: 2018-05-01 17:25:16.439856937 +0800
 Birth: -
ghostwu@dev:~/linux/mkdir$ vim ghostwu.txt 
ghostwu@dev:~/linux/mkdir$ stat ghostwu.txt 
  File: 'ghostwu.txt'
  Size: 5             Blocks: 8          IO Block: 4096   regular file
Device: 807h/2055d    Inode: 9569550     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/ ghostwu)   Gid: ( 1000/ ghostwu)
Access: 2018-05-01 17:29:34.982228802 +0800
Modify: 2018-05-01 17:29:34.982228802 +0800
Change: 2018-05-01 17:29:35.018231392 +0800
 Birth: -

 

Change time:狀態改變時間,修改文件內容,移動文件,或者改變文件屬性等,文件的change time會發生改變.file

1,移動文件( 重命名 ), change time 發生改變:權限

ghostwu@dev:~/linux/mkdir$ stat ghostwu.txt 
  File: 'ghostwu.txt'
  Size: 5             Blocks: 8          IO Block: 4096   regular file
Device: 807h/2055d    Inode: 9569550     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/ ghostwu)   Gid: ( 1000/ ghostwu)
Access: 2018-05-01 17:29:34.982228802 +0800
Modify: 2018-05-01 17:29:34.982228802 +0800
Change: 2018-05-01 17:29:35.018231392 +0800
 Birth: -
ghostwu@dev:~/linux/mkdir$ mv ghostwu.txt ghostwu2.txt
ghostwu@dev:~/linux/mkdir$ stat ghostwu2.txt 
  File: 'ghostwu2.txt'
  Size: 5             Blocks: 8          IO Block: 4096   regular file
Device: 807h/2055d    Inode: 9569550     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/ ghostwu)   Gid: ( 1000/ ghostwu)
Access: 2018-05-01 17:29:34.982228802 +0800
Modify: 2018-05-01 17:29:34.982228802 +0800
Change: 2018-05-01 17:32:25.392863791 +0800

2,修改文件的權限,change time發生了改變

ghostwu@dev:~/linux/mkdir$ stat ghostwu2.txt 
  File: 'ghostwu2.txt'
  Size: 5             Blocks: 8          IO Block: 4096   regular file
Device: 807h/2055d    Inode: 9569550     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/ ghostwu)   Gid: ( 1000/ ghostwu)
Access: 2018-05-01 17:29:34.982228802 +0800
Modify: 2018-05-01 17:29:34.982228802 +0800
Change: 2018-05-01 17:32:25.392863791 +0800
 Birth: -
ghostwu@dev:~/linux/mkdir$ chmod 777 ghostwu2.txt 
ghostwu@dev:~/linux/mkdir$ stat ghostwu2.txt 
  File: 'ghostwu2.txt'
  Size: 5             Blocks: 8          IO Block: 4096   regular file
Device: 807h/2055d    Inode: 9569550     Links: 1
Access: (0777/-rwxrwxrwx)  Uid: ( 1000/ ghostwu)   Gid: ( 1000/ ghostwu)
Access: 2018-05-01 17:29:34.982228802 +0800
Modify: 2018-05-01 17:29:34.982228802 +0800
Change: 2018-05-01 17:33:31.602584110 +0800
 Birth: -

touch -m修改文件的modify和change時間

ghostwu@dev:~/linux/mkdir$ stat ghostwu2.txt 
  File: 'ghostwu2.txt'
  Size: 5             Blocks: 8          IO Block: 4096   regular file
Device: 807h/2055d    Inode: 9569550     Links: 1
Access: (0777/-rwxrwxrwx)  Uid: ( 1000/ ghostwu)   Gid: ( 1000/ ghostwu)
Access: 2018-05-01 17:29:34.982228802 +0800
Modify: 2018-05-01 17:29:34.982228802 +0800
Change: 2018-05-01 17:33:31.602584110 +0800
 Birth: -
ghostwu@dev:~/linux/mkdir$ touch -m ghostwu2.txt 
ghostwu@dev:~/linux/mkdir$ stat ghostwu2.txt 
  File: 'ghostwu2.txt'
  Size: 5             Blocks: 8          IO Block: 4096   regular file
Device: 807h/2055d    Inode: 9569550     Links: 1
Access: (0777/-rwxrwxrwx)  Uid: ( 1000/ ghostwu)   Gid: ( 1000/ ghostwu)
Access: 2018-05-01 17:29:34.982228802 +0800
Modify: 2018-05-01 17:34:31.678864985 +0800
Change: 2018-05-01 17:34:31.678864985 +0800

touch -d修改建立後的文件的修改時間

ghostwu@dev:~/linux/mkdir$ ls -lh ghostwu2.txt 
-rwxrwxrwx 1 ghostwu ghostwu 5 5月   1 17:34 ghostwu2.txt
ghostwu@dev:~/linux/mkdir$ touch -d 20190218 ghostwu2.txt 
ghostwu@dev:~/linux/mkdir$ ls -lh ghostwu2.txt 
-rwxrwxrwx 1 ghostwu ghostwu 5 2月  18  2019 ghostwu2.txt
ghostwu@dev:~/linux/mkdir$ stat ghostwu2.txt 
  File: 'ghostwu2.txt'
  Size: 5             Blocks: 8          IO Block: 4096   regular file
Device: 807h/2055d    Inode: 9569550     Links: 1
Access: (0777/-rwxrwxrwx)  Uid: ( 1000/ ghostwu)   Gid: ( 1000/ ghostwu)
Access: 2019-02-18 00:00:00.000000000 +0800
Modify: 2019-02-18 00:00:00.000000000 +0800
Change: 2018-05-01 17:37:13.031347481 +0800
 Birth: -
相關文章
相關標籤/搜索