linux创建文件(touch)命令详解


Linux 创建文件命令主要用到的是 touch 命令,touch 命令可用来修改文件的访问时间,修改时间,如果没有指定时间,则默认为当前时间,如果指定的文件不存在,则 touch 命令将创建该文件。
命令格式:
touch
[-acfm]
[-r file(参照文件)]
[-t decimtime(时间值)]
[-d time(时间值)]
[--time={atime,access,use,mtime,modify}]
[--date=time]
[--reference=file]
[--no-create] 不建立任何文件,与 -c 作用想用
[--help] 在线帮助
[--version] 显示版本信息
[--]
file(文件)... 
-a 修改文件 file 的存取时间.     
-c 不创建文件 file.     
-m 修改文件 file
-r ref_file 将参照文件 ref_file 相应的时间戳记的数值作为指定文件 file 时间戳记的新值.     
-t time 使用指定的时间值 time 作为指定文件 file 相应时间戳记的新值,格式可以是 MMDDhhmm 或者 yyyyMMDDhhmm
例如:
touch -t 10112200 phpernote.com 将 phpernote.com 文件的时间更改为当年的10月11号22点整
touch -t 200910112200 phpernote.com 将 phpernote.com 文件的时间更改为2009年10月11日22点整
touch -r baidu.com phpernote.com 将 phpernote.com 文件的时间更改为和 baidu.com 文件的时间相同
touch phpernote.com 创建 phpernote.com 文件(文件时间默认为当前时间)
当然 Linux 创建文件的命令还有如:cp(拷贝文件) ,mv(移动文件) 也算是吧。
另外只要命令能够重定向输出到一个不存在的文件中去,那么该命令也能够创建文件,比如如下命令:
echo hello world > /home/phpernote.com 将字符串输出到 /home/phpernote.com 文件里面
cat baidu.com > /home/phpernote.com 将 baidu.com 文件里面的内容输出到 /home/phpernote.com 文件里面
less testless > /home/phpernote.com
tail -f -n 20 /home/phpernote.com > /home/phpernote.com
等等很多。

相关内容

    暂无相关文章