首页 > 系统相关 >Linux文件操作命令touch

Linux文件操作命令touch

时间:2022-10-09 14:34:49浏览次数:58  
标签:rhel7 rw 操作命令 23 Linux booboo tom touch 2016

touch

touch [filename]

创建文件,参数可以跟多个

如果要创建 50 个有规律的文件,例如 text1-text50

利用参数扩展

touch test{1..50}
touch test{a..e}
touch test{a..e}_{1..3}---> 会创建 a_1 a_2 a_3...

上帝之手,本来是用来修改文件时间戳的。文件的三个时间 ctime\mtime\atime

拓展内容:可以通过“stat”命令查看文件的三个时间

touch " " 可以放一些特殊字符

touch实验

[tom@rhel7 ~]$ touch test{a..c}_{1..4}
[tom@rhel7 ~]$ ls
testa_1 testa_4 testb_3 testc_2
testa_2 testb_1 testb_4 testc_3
testa_3 testb_2 testc_1 testc_4

--full-time可以查看mtime的完整时间

[tom@rhel7 ~]$ ls -l --full-time
total 0
-rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testa_1
-rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testa_2
-rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testa_3
-rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testa_4
-rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testb_1
-rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testb_2
-rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testb_3
-rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.853039590 +0800 testb_4
-rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.854039544 +0800 testc_1
-rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.854039544 +0800 testc_2
-rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.854039544 +0800 testc_3
-rw-rw-r--. 1 tom tom 0 2016-03-21 01:31:22.854039544 +0800 testc_4

[tom@rhel7 ~]$ touch "ab cd"

[tom@rhel7 ~]$ ls -b
ab\ \ \ cd testa_3 testb_2 testc_1 testc_4
testa_1 testa_4 testb_3 testc_2
testa_2 testb_1 testb_4 testc_3

touch拓展实验

[booboo@rhel7 ~]$ touch booboo
[booboo@rhel7 ~]$ ll
total 0
-rw-rw-r--. 1 booboo booboo 0 Jun 15 23:28 booboo
[booboo@rhel7 ~]$ stat booboo
  File: ‘booboo’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fd01h/64769d	Inode: 143         Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1001/  booboo)   Gid: ( 1001/  booboo)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2016-06-15 23:28:55.041578819 -0400     #atime 文件最近一次被访问的时间
Modify: 2016-06-15 23:28:55.041578819 -0400    #mtime 文件内容最近一次修改的时间
Change: 2016-06-15 23:28:55.041578819 -0400    #ctime 文件属性最近一次修改的时间
 Birth: -

使用cat去访问booboo文件,可以发现atime被修改了

[booboo@rhel7 ~]$ cat booboo
[booboo@rhel7 ~]$ stat booboo
  File: ‘booboo’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fd01h/64769d	Inode: 143         Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1001/  booboo)   Gid: ( 1001/  booboo)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2016-06-15 23:32:35.898724748 -0400
Modify: 2016-06-15 23:28:55.041578819 -0400
Change: 2016-06-15 23:28:55.041578819 -0400
 Birth: -

通过chmod修改文件权限后,会看到ctime时间改变,通过ll命令看到的时间为mtime

[booboo@rhel7 ~]$ chmod 777 booboo
[booboo@rhel7 ~]$ ll
total 0
-rwxrwxrwx. 1 booboo booboo 0 Jun 15 23:28 booboo  
[booboo@rhel7 ~]$ stat booboo
  File: ‘booboo’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fd01h/64769d	Inode: 143         Links: 1
Access: (0777/-rwxrwxrwx)  Uid: ( 1001/  booboo)   Gid: ( 1001/  booboo)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2016-06-15 23:32:35.898724748 -0400
Modify: 2016-06-15 23:28:55.041578819 -0400
Change: 2016-06-15 23:33:49.195445761 -0400
 Birth: -

通过echo命令向booboo文件追加一些内容,会看到mtime时间变了,并且ctime也变了,思考为什么?

[booboo@rhel7 ~]$ echo hi >> booboo
[booboo@rhel7 ~]$ ll
total 4
-rwxrwxrwx. 1 booboo booboo 3 Jun 15 23:34 booboo
[booboo@rhel7 ~]$ stat booboo
  File: ‘booboo’
  Size: 3         	Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 143         Links: 1
Access: (0777/-rwxrwxrwx)  Uid: ( 1001/  booboo)   Gid: ( 1001/  booboo)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2016-06-15 23:32:35.898724748 -0400
Modify: 2016-06-15 23:34:53.251332183 -0400
Change: 2016-06-15 23:34:53.251332183 -0400
 Birth: -

标签:rhel7,rw,操作命令,23,Linux,booboo,tom,touch,2016
From: https://blog.51cto.com/u_14068620/5739657

相关文章

  • node_exporter到prometheus到grafana,监控linux机器,监控搭建
    搭建架构:Linux被监控机:node_exporterLinux监控机:prometheus&grafanamacos图形化展示监控结果:远程访问 prometheus&grafana 一、Linux被监控机的配置下载node_e......
  • linux磁盘已满,查看哪个文件占用多
    1.使用df-h查看磁盘空间占用情况2.使用sudodu-s-h/*|sort-nr命令查看那个目录占用空间大3.然后那个目录占用多再通过sudodu-s-h/var/*|sort-nr一层层......
  • LINUX系统同步网络时间
    安装了一个ntp缩减版的工具,然后同步时间的master是一个所有人都可以用的master安装工具yum -yinstallntpntpdate同步网络时间ntpdatecn.pool.ntp.org......
  • Linux中安装使用rsync
    获取 rsync-3.1.0 我的网盘里放了一个。地址:​​http://pan.baidu.com/s/1dDs4lSt​​安装rsync-3.1.0.tar.gz #tarzxvfrsync-3.1.0.tar.gz#cdrsync-3.1.0#./config......
  • 记录Linux下启动docker中Mysql,并进入mysql。
    1.启动dockersystemctlstartdocker  2.查看docker容器启动信息,并找到mysql容器  3.使用进程名启动mysql:dockerstartmysql-test;也可以使用进程id启动:docker......
  • linux 定时任务 加锁
    ​​*/3****flock-xn/home/work/fupeng/oem_apk_new.lock-c'sh/home/work/fupeng/oem_apk_new.sh>/dev/null2>&1'>/dev/null2>&1......
  • Linux系统睡眠
    参考Linuxkernel文档Documentation\admin-guide\pm\sleep-states.rstSystemSleepStates—TheLinuxKerneldocumentation系统睡眠状态名称ACPIState说明唤......
  • linux下解压zip 命令
    ## 基础命令是 unzip 解压在当前目录下,我以解压一个 logstash 的压缩包为例  unziplogstash-7.5.1.zip  ## 解压到指定目录下   这个是常用的,可以看到下......
  • Linux进程冻结
    主要参考:Documentation\power\freezing-of-tasks.rstFreezingoftasks—TheLinuxKerneldocumentation【原创】LinuxSuspend流程分析-LoyenWang-博客园(cnb......
  • linux安装redis扩展
    1、下载github中的稳定版本库。php7gitclonehttps://github.com/phpredis/phpredistar-zxvfphpredis进入解压后目录cdphpredis2、使用安装php时生成的phpize来生......