linux操作命令comm,Linux常用基本命令:touch命令

touch命令作用:创建空文件,或者改变文件的时间戳属性

适用场景:

如果创建一个新文件有很多种方法,比如:

vi file

cat > file

echo "hello,world" > file

touch  file

touch命令不仅可以创建新文件,而且可以修改文件的时间属性;

c6e4e307ef7f9d0f431b2640fff01645.png

格式: touch [option] [file]

备注:

1) -t选项的时间格式[[CC]YY]MMDDhhmm[.ss]说明:

0ecd7a52cc743e33c19537b1293bf673.png

2) touch命令的几点说明:

4e6fa4cf37b52c25b41dde56ffe4d763.png

1,同时创建一个或者多个空文件

linuxidc@linuxidc:~/linux/mkdir$ ls

linuxidc@linuxidc:~/linux/mkdir$ touch a.txt

linuxidc@linuxidc:~/linux/mkdir$ ls

a.txt

linuxidc@linuxidc:~/linux/mkdir$ touch b.txt c.txt

linuxidc@linuxidc:~/linux/mkdir$ ls

a.txt  b.txt  c.txt

linuxidc@linuxidc:~/linux/mkdir$ touch {1..5}.txt

linuxidc@linuxidc:~/linux/mkdir$ ls

1.txt  2.txt  3.txt  4.txt  5.txt  a.txt  b.txt  c.txt

2,创建文件,并用stat查看文件的属性状态信息

linuxidc@linuxidc:~/linux/mkdir$ touch linuxidc.txt

linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc.txt

File: 'linuxidc.txt'

Size: 0            Blocks: 0          IO Block: 4096  regular empty file

linuxidcice: 807h/2055d    Inode: 9569451    Links: 1

Access: (0664/-rw-rw-r--)  Uid: ( 1000/ linuxidc)  Gid: ( 1000/ linuxidc)

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个时间

Access time: 最后访问时间,查看文件的内容时,这个时间会改变,使用cat命令查看文件时,可以看出Access time已经变了

linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc.txt

File: 'linuxidc.txt'

Size: 0            Blocks: 0          IO Block: 4096  regular empty file

linuxidcice: 807h/2055d    Inode: 9569451    Links: 1

Access: (0664/-rw-rw-r--)  Uid: ( 1000/ linuxidc)  Gid: ( 1000/ linuxidc)

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: -

linuxidc@linuxidc:~/linux/mkdir$ cat linuxidc.txt

linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc.txt

File: 'linuxidc.txt'

Size: 0            Blocks: 0          IO Block: 4096  regular empty file

linuxidcice: 807h/2055d    Inode: 9569451    Links: 1

Access: (0664/-rw-rw-r--)  Uid: ( 1000/ linuxidc)  Gid: ( 1000/ linuxidc)

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:最后修改时间,修改文件内容,文件的修改时间会改变。访问时间和状态改变时间 也发生变化

linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc.txt

File: 'linuxidc.txt'

Size: 0            Blocks: 0          IO Block: 4096  regular empty file

linuxidcice: 807h/2055d    Inode: 9569451    Links: 1

Access: (0664/-rw-rw-r--)  Uid: ( 1000/ linuxidc)  Gid: ( 1000/ linuxidc)

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: -

linuxidc@linuxidc:~/linux/mkdir$ vim linuxidc.txt

linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc.txt

File: 'linuxidc.txt'

Size: 5            Blocks: 8          IO Block: 4096  regular file

linuxidcice: 807h/2055d    Inode: 9569550    Links: 1

Access: (0664/-rw-rw-r--)  Uid: ( 1000/ linuxidc)  Gid: ( 1000/ linuxidc)

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会发生改变.

1,移动文件( 重命名 ), change time 发生改变:

linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc.txt

File: 'linuxidc.txt'

Size: 5            Blocks: 8          IO Block: 4096  regular file

linuxidcice: 807h/2055d    Inode: 9569550    Links: 1

Access: (0664/-rw-rw-r--)  Uid: ( 1000/ linuxidc)  Gid: ( 1000/ linuxidc)

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: -

linuxidc@linuxidc:~/linux/mkdir$ mv linuxidc.txt linuxidc2.txt

linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc2.txt

File: 'linuxidc2.txt'

Size: 5            Blocks: 8          IO Block: 4096  regular file

linuxidcice: 807h/2055d    Inode: 9569550    Links: 1

Access: (0664/-rw-rw-r--)  Uid: ( 1000/ linuxidc)  Gid: ( 1000/ linuxidc)

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发生了改变

linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc2.txt

File: 'linuxidc2.txt'

Size: 5            Blocks: 8          IO Block: 4096  regular file

linuxidcice: 807h/2055d    Inode: 9569550    Links: 1

Access: (0664/-rw-rw-r--)  Uid: ( 1000/ linuxidc)  Gid: ( 1000/ linuxidc)

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: -

linuxidc@linuxidc:~/linux/mkdir$ chmod 777 linuxidc2.txt

linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc2.txt

File: 'linuxidc2.txt'

Size: 5            Blocks: 8          IO Block: 4096  regular file

linuxidcice: 807h/2055d    Inode: 9569550    Links: 1

Access: (0777/-rwxrwxrwx)  Uid: ( 1000/ linuxidc)  Gid: ( 1000/ linuxidc)

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时间

linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc2.txt

File: 'linuxidc2.txt'

Size: 5            Blocks: 8          IO Block: 4096  regular file

linuxidcice: 807h/2055d    Inode: 9569550    Links: 1

Access: (0777/-rwxrwxrwx)  Uid: ( 1000/ linuxidc)  Gid: ( 1000/ linuxidc)

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: -

linuxidc@linuxidc:~/linux/mkdir$ touch -m linuxidc2.txt

linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc2.txt

File: 'linuxidc2.txt'

Size: 5            Blocks: 8          IO Block: 4096  regular file

linuxidcice: 807h/2055d    Inode: 9569550    Links: 1

Access: (0777/-rwxrwxrwx)  Uid: ( 1000/ linuxidc)  Gid: ( 1000/ linuxidc)

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修改创建后的文件的修改时间

linuxidc@linuxidc:~/linux/mkdir$ ls -lh linuxidc2.txt

-rwxrwxrwx 1 linuxidc linuxidc 5 5月  1 17:34 linuxidc2.txt

linuxidc@linuxidc:~/linux/mkdir$ touch -d 20190218 linuxidc2.txt

linuxidc@linuxidc:~/linux/mkdir$ ls -lh linuxidc2.txt

-rwxrwxrwx 1 linuxidc linuxidc 5 2月  18  2019 linuxidc2.txt

linuxidc@linuxidc:~/linux/mkdir$ stat linuxidc2.txt

File: 'linuxidc2.txt'

Size: 5            Blocks: 8          IO Block: 4096  regular file

linuxidcice: 807h/2055d    Inode: 9569550    Links: 1

Access: (0777/-rwxrwxrwx)  Uid: ( 1000/ linuxidc)  Gid: ( 1000/ linuxidc)

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: -

0b1331709591d260c1c78e86d0c51c18.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值