linux touch命令 linux mv命令

linux touch命令详解

touch命令是linux下的一个文件管理命令,通常是用于创建文件,touch命令主要有两个功能,具体介绍如下:

1、创建新的空文件;

2、改变已有文件的时间属。

说明:touch命令可以依据当前的系统时间更新指定文件的访问时间以及修改时间。如果文件不存在的话,就会创建新的空文件,除非是指定了”-c”或”-h”选项。

touch命令的具体语法格式为touch [参数] [文件]。

参数:

-a改变档案的读取时间记录

-m改变档案的修改时间记录

-r使用参考档的时间记录,与--file的效果一样

-c不创建新文件

-d设定时间与日期,可以使用各种不同的格式

-t设定档案的时间记录,格式与 date命令相同

--no-create不创建新文件

--help显示帮助信息

--version列出版本讯息

Linux下touch命令有什么作用如何使用

在Linux命令中,我们会经常使用到cd、ls等命令,但像touch这样的命令就比较少用了,那么touch命令有什么作用呢?下面随小编一起来了解下Linux下touch命令的用法吧。

linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件。

1.命令格式:

touch[选项]。。。文件。。。

2.命令参数:

-a或--time=atime或--time=access或--time=use只更改存取时间。

-c或--no-create不建立任何文档。

-d使用指定的日期时间,而非现在的时间。

-f此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题。

-m或--time=mtime或--time=modify只更改变动时间。

-r把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同。

-t使用指定的日期时间,而非现在的时间。

3.命令功能:

touch命令参数可更改文档或目录的日期时间,包括存取时间和更改时间。

4.使用范例:

实例一:创建不存在的文件

命令:

touch log2012.log log2013.log

输出:

[root@localhost test]# touch log2012.log log2013.log

[root@localhost test]# ll

-rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

如果log2014.log不存在,则不创建文件

[root@localhost test]# touch-c log2014.log

[root@localhost test]# ll

-rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

实例二:更新log.log的时间和log2012.log时间戳相同

命令:

touch-r log.log log2012.log

输出:

[root@localhost test]# ll

-rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root 0 10-28 14:48 log.log

[root@localhost test]# touch-r log.log log2012.log

[root@localhost test]# ll

-rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root 0 10-28 14:48 log.log

实例三:设定文件的时间戳

命令:

touch-t 201211142234.50 log.log

输出:

[root@localhost test]# ll

-rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root 0 10-28 14:48 log.log

[root@localhost test]# touch-t 201211142234.50 log.log

[root@localhost test]# ll

-rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root 0 2012-11-14 log.log

说明:

-t time使用指定的时间值 time作为指定文件相应时间戳记的新值.此处的 time规定为如下形式的十进制数:

[[CC]YY]MMDDhhmm[.SS]

这里,CC为年数中的前两位,即”世纪数”;YY为年数的后两位,即某世纪中的年数.如果不给出CC的值,则touch将把年数CCYY限定在1969--2068之内.MM为月数,DD为天将把年数CCYY限定在1969--2068之内.MM为月数,DD为天数,hh为小时数(几点),mm为分钟数,SS为秒数.此处秒的设定范围是0--61,这样可以处理闰秒.这些数字组成的时间是环境变量TZ指定的时区中的一个时间.由于系统的限制,早于1970年1月1日的时间是错误的。

上面就是Linux下touch命令的用法介绍了,使用touch命令可以修改文件时间戳,其修改的是指定日期时间而不是现在时间,你学会了吗?

Linux系统下touch命令的使用方法

1.命令格式:

touch [选项]...文件...

2.命令参数:

-a  或--time=atime或--time=access或--time=use只更改存取时间。

  -c  或--no-create不建立任何文档。

  -d使用指定的日期时间,而非现在的时间。

  -f此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题。

  -m  或--time=mtime或--time=modify只更改变动时间。

  -r把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同。

  -t使用指定的日期时间,而非现在的时间。

3.命令功能:

touch命令参数可更改文档或目录的日期时间,包括存取时间和更改时间。

4.使用范例:

实例一:创建不存在的文件

命令:

touch log2012.log log2013.log

输出:

复制代码

  

代码如下:

[root@localhost test]# touch log2012.log log2013.log

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

如果log2014.log不存在,则不创建文件

复制代码

  

代码如下:

[root@localhost test]# touch-c log2014.log

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

实例二:更新log.log的时间和log2012.log时间戳相同

命令:

touch-r log.log log2012.log

输出:

复制代码

  

代码如下:

[root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 10-28 14:48 log.log

  [root@localhost test]# touch-r log.log log2012.log

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 10-28 14:48 log.log

实例三:设定文件的时间戳

命令:

touch-t 201211142234.50 log.log

输出:

复制代码

  

代码如下:

[root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 10-28 14:48 log.log

  [root@localhost test]# touch-t 201211142234.50 log.log

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 2012-11-14 log.log

说明:

-t time使用指定的时间值 time作为指定文件相应时间戳记的新值.此处的 time规定为如下形式的十进制数:

[[CC]YY]MMDDhhmm[.SS]

这里,CC为年数中的前两位,即”世纪数”;YY为年数的后两位,即某世纪中的年数.如果不给出CC的值,则touch  将把年数CCYY限定在1969--2068之内.MM为月数,DD为天将把年数CCYY限定在1969--2068之内.MM为月数,DD为天数,hh为小时数(几点),mm为分钟数,SS为秒数.此处秒的设定范围是0--61,这样可以处理闰秒.这些数字组成的时间是环境变量TZ指定的时区中的一个时间.由于系统的限制,早于1970年1月1日的时间是错误的。

指令名?:

  touch(1)-更新?n案的?r???

  ?明:

  藉由???指令,我??可以同?r或?为??更?n案的?煞N?r???,?取?r?(access time)以及修改?r?(modification time)。

  ??:

  -a

  更改文件的?取?r?(access time)

  -c,--no-create

  不建立任何新?n案

  -m

  更改文件的修改?r?(modification time)

  -t STAMP

  ?定"特定?r?"?泶??quot;目前?r?",格式 [[CC]YY]MMDDhhmm[.ss]

  --help

  ?示程式用法??

  --version

  ?示程式本身的版本??

  ??例?明:

  空?n案

复制代码

  

代码如下:

# touch file-touch1

  # ls-l

  total 0

  -rw-r--r-- 1 root root 0 7月 9 13:53 file-touch1

  #

一般??r下使用 touch指令?更?n案?r?,如果?n案不存在,touch???咏?⒅付ǖ?n案(空?n案)。如果不想因使用 touch而建立任何新?n案,必?加上??-c

复制代码

  

代码如下:

# touch-c file-touch2

  touch: setting times of `file-touch2':?]有此一?n案或目?

  #

指令的?绦薪Y果是出?一段???息,因?橹付ǖ?n案不存在。?正是加上??-c的目的。更新?n案?r? touch指令一般是以下指令??r的???r??碜?楦??n案的?r?。但也提供特殊的??-t??br/指定"特定的?r?"作?楦??r?。?榱伺e例的方便,我原封不定地,拷?一?已建?n?久的系?程式-- tcsh

复制代码

  

代码如下:

# cp-a/bin/tcsh.

  # ls--full-time

  total 288

  -rwxr-xr-x 1 root root 288604?一 6月 25 03:45:26 2001 tcsh

  #

??程式的最後修改?r?是-- 2001年 6月 25日 3? 45分 26秒。?在,我因?控上的需要,打算??n案?r??更? 2002年 7月 1日 8? 00分 01秒。最??斡行У淖鞣ㄈ缦

复制代码

  

代码如下:

# touch-t 200207010800.01 tcsh

  # ls--full-time

  total 288

  -rwxr-xr-x 1 root root 288604?一 7月 01 08:00:01 2002 tcsh

??的?法很?渭?,就是直接?入西元的年月日?r分?底旨纯桑?溟g不需任何分隔。如果要加上秒?担?龇ū容^特?e,需使用小?"."?砼c前段?^隔。?然,在有需要?r,touch指令也支援"?取?r?"或"修改?r?"的?为??更。

复制代码

  

代码如下:

# touch-at 200207022300 tcsh

  # ls-lu

  total 288

  -rwxr-xr-x 1 root root 288604 7月 2 23:00 tcsh

  #

上例是?为??更"?取?r?",下例?t是?更"修改?r?"

复制代码

  

代码如下:

# touch-mt 200206302300 tcsh

  # ls-l

  total 288

  -rwxr-xr-x 1 root root 288604 6月 30 23:00 tcsh

  # ls-lu

  total 288

  -rwxr-xr-x 1 root root 288604 7月 2 23:00 tcsh

  #

以上?些例子,即是大?上 touch的

阅读剩余
THE END