每天回顾linux命令(touch)
2017-10-27 09:52
471 查看
笔者对touch命令印象比较深刻,记得有一次客户说我们处理的结果(以文件的形式)有些小问题,让我人工处理一下。我把花不到3个小时处理完了,结果对接的人说让我答复客户说过两天后才可以处理完,不然一些无关紧要的小问题,可能不是我们造成的也会占用我们的工作量。满满的套路啊…….两天后,用touch命令修改文件更新时间为当前时间。ok,客户那边各种感谢信,搞的自己都有点不好意思。这是笔者第一次在实际应用中使用到touch修改文件的更新时间。
touch命令
touch命令有两个功能:
1)用于把已经存在的文件的时间标签更新(默认更新为当前系统时间),文件内容不改变。
2)用来创建新的空文件
语法
touch (选项) (参数)
最好使用为 touch (参数) (选项)
选项
不加任何参数:创建新的空文件,如果文件已经存在,将其更新时间修改为当前时间。
-a或–time=atime或–time=access或–time=use,只更改存取时间(默认情况下,带-a)
-c或–no-create:不建立任何文件
-d:<时间日期>使用指定日期时间,而非现在的时间。修改accesstime和modifytime
-m或者–time=mtime或–time=modify 只更改变动时间。
-r:<参考文件或目录> 使用指定文件或目录的日期时间,统统设成或参考文件或目录的日期时间相同。
-t:<日期时间>使用指定的日期时间,而非现在的时间 和-d相同
参数
文件:指定要设置时间属性的文件列表
touch命令
touch命令有两个功能:
1)用于把已经存在的文件的时间标签更新(默认更新为当前系统时间),文件内容不改变。
2)用来创建新的空文件
语法
touch (选项) (参数)
最好使用为 touch (参数) (选项)
选项
不加任何参数:创建新的空文件,如果文件已经存在,将其更新时间修改为当前时间。
root@62bf1a913608:/home/wzm/testjoin# ll total 8 drwxr-xr-x 2 root root 4096 Oct 27 01:19 ./ drwxr-xr-x 5 root root 4096 Oct 27 00:58 ../ -rw-r--r-- 1 root root 0 Oct 27 00:58 a.txt -rw-r--r-- 1 root root 0 Oct 27 00:58 b.txt -rw-r--r-- 1 root root 0 Oct 27 01:19 testtouch.txt root@62bf1a913608:/home/wzm/testjoin# date Fri Oct 27 01:19:41 UTC 2017
-a或–time=atime或–time=access或–time=use,只更改存取时间(默认情况下,带-a)
root@62bf1a913608:/home/wzm/testjoin# stat testtouch.txt File: 'testtouch.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 70h/112d Inode: 114 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2017-10-27 01:26:53.046806235 +0000 Modify: 2017-10-27 01:23:43.254185694 +0000 Change: 2017-10-27 01:26:53.046806235 +0000 Birth: - root@62bf1a913608:/home/wzm/testjoin# date Fri Oct 27 01:28:02 UTC 2017 root@62bf1a913608:/home/wzm/testjoin# touch testtouch.txt -a root@62bf1a913608:/home/wzm/testjoin# stat testtouch.txt File: 'testtouch.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 70h/112d Inode: 114 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2017-10-27 01:28:12.513025472 +0000 Modify: 2017-10-27 01:23:43.254185694 +0000 Change: 2017-10-27 01:28:12.513025472 +0000 Birth: - root@62bf1a913608:/home/wzm/testjoin#
-c或–no-create:不建立任何文件
root@62bf1a913608:/home/wzm/testjoin# ls 201610270921 201810270921 a.txt b.txt testtouch.txt root@62bf1a913608:/home/wzm/testjoin# touch -c abc.txt root@62bf1a913608:/home/wzm/testjoin# ls 201610270921 201810270921 a.txt b.txt testtouch.txt
-d:<时间日期>使用指定日期时间,而非现在的时间。修改accesstime和modifytime
root@62bf1a913608:/home/wzm/testjoin# stat testtouch.txt File: 'testtouch.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 70h/112d Inode: 114 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2017-10-27 01:28:12.513025472 +0000 Modify: 2017-10-27 01:23:43.254185694 +0000 Change: 2017-10-27 01:28:12.513025472 +0000 Birth: - root@62bf1a913608:/home/wzm/testjoin# touch testtouch.txt -d 201610271030 root@62bf1a913608:/home/wzm/testjoin# stat testtouch.txt File: 'testtouch.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 70h/112d Inode: 114 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 20161027-10-30 00:00:00.000000000 +0000 Modify: 20161027-10-30 00:00:00.000000000 +0000 Change: 2017-10-27 01:36:34.618294433 +0000 Birth: -
-m或者–time=mtime或–time=modify 只更改变动时间。
root@62bf1a913608:/home/wzm/testjoin# stat testtouch.txt File: 'testtouch.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 70h/112d Inode: 114 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2017-10-27 12:00:00.000000000 +0000 Modify: 2017-10-27 12:00:00.000000000 +0000 Change: 2017-10-27 01:37:17.722516325 +0000 Birth: - root@62bf1a913608:/home/wzm/testjoin# touch testtouch.txt -m root@62bf1a913608:/home/wzm/testjoin# stat testtouch.txt File: 'testtouch.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 70h/112d Inode: 114 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2017-10-27 12:00:00.000000000 +0000 Modify: 2017-10-27 01:47:06.275801443 +0000 Change: 2017-10-27 01:47:06.275801443 +0000 Birth: -
-r:<参考文件或目录> 使用指定文件或目录的日期时间,统统设成或参考文件或目录的日期时间相同。
root@62bf1a913608:/home/wzm/testjoin# stat testtouch.txt File: 'testtouch.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 70h/112d Inode: 114 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2017-10-27 12:00:00.000000000 +0000 Modify: 2017-10-27 01:47:06.275801443 +0000 Change: 2017-10-27 01:47:06.275801443 +0000 Birth: - root@62bf1a913608:/home/wzm/testjoin# stat a.txt File: 'a.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 70h/112d Inode: 107 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2017-10-27 00:58:45.220080420 +0000 Modify: 2017-10-27 00:58:45.220080420 +0000 Change: 2017-10-27 00:58:45.220080420 +0000 Birth: - root@62bf1a913608:/home/wzm/testjoin# touch testtouch.txt -m -r a.txt root@62bf1a913608:/home/wzm/testjoin# stat testtouch.txt File: 'testtouch.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 70h/112d Inode: 114 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2017-10-27 12:00:00.000000000 +0000 Modify: 2017-10-27 00:58:45.220080420 +0000 Change: 2017-10-27 01:49:42.747427988 +0000 Birth: -
-t:<日期时间>使用指定的日期时间,而非现在的时间 和-d相同
参数
文件:指定要设置时间属性的文件列表
相关文章推荐
- 每天回顾linux命令(mv)
- 每天一个linux命令(9):touch 命令
- 每天回顾linux命令(whereis)
- linux每天一小步---touch命令详解
- 每天一个linux命令(9):touch 命令
- 每天一个linux命令(9):touch 命令
- 每天回顾linux命令(wc)
- 每天一个linux命令(9):touch 命令
- 每天一个linux命令——touch
- 每天回顾linux命令(cd)
- 每天回顾linux命令(split)
- 每天一个linux命令(9):touch 命令
- 每天回顾linux命令(whoami)
- 每天一个linux命令(9):touch 命令
- 每天一个linux命令(9):touch 命令
- linux每天一小步---touch命令详解
- 每天回顾linux命令(dirname)
- 每天一个Linux命令(9):touch 命令
- 每天回顾linux命令(ldd)
- 每天回顾linux命令(pushd、pwd、popd)