文件操作1创建文件

1.[root@rusky ]# vi list     #如果testfile不存在,则vi会自动创建一个名为testfile的文件,并在Vi打开该文件等待用户输入内容。

2.[root@rusky ]# ls -l >listfile #利用重定向,将ls -l 的执行结果输出到新文件listfile中,也可使用cat,more,less或其它命令结合重向运算符>来生成新文件

3.[root@rusky ]# cp file  file2   #复制并创建新文件,相当于把file文件复制后,重新命名为file2

4.[root@rusky usr]# ls -l  
total 2
drwxr-xr-x 2 root root 36864 Apr 27 20:42 bin
5.drwxr-xr-x 2 root root 4096 Oct 10 2006 etc
[root@rusky usr]# ls -il    #与上一命令相比,显示出文件的inode值。
total 2
95914 drwxr-xr-x 2 root root 36864 Apr 27 20:42 bin
95915 drwxr-xr-x 2 root root 4096 Oct 10 2006 etc
6.touch 命令

[root@rusky /]# date
Fri May  2 07:36:34 PDT 2014
[root@rusky /]# stat test
  File: `test'
  Size: 16              Blocks: 16         IO Block: 4096   regular file
Device: 802h/2050d      Inode: 48          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-04-16 22:58:32.000000000 -0700
Modify: 2014-04-07 05:34:27.000000000 -0700
Change: 2014-04-07 05:34:27.000000000 -0700
[root@rusky /]# touch -a -t 19890106101010 test   #设置秒时,前面要加.  否则会提示无效时间格式
touch: invalid date format `19890106101010'
[root@rusky /]# touch -a -t 198901061010.10 test   #-a 表示修改修改访问时间,-m表示修改属性modify时间 -t 指定时间 
[root@rusky /]# stat test
  File: `test'
  Size: 16              Blocks: 16         IO Block: 4096   regular file
Device: 802h/2050d      Inode: 48          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 1989-01-06 10:10:10.000000000 -0800
Modify: 2014-04-07 05:34:27.000000000 -0700
Change: 2014-05-02 07:38:04.000000000 -0700
[root@rusky /]# stat var
  File: `var'
  Size: 4096            Blocks: 16         IO Block: 4096   directory
Device: 802h/2050d      Inode: 191809      Links: 20
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-04-28 02:35:05.000000000 -0700
Modify: 2014-04-03 16:14:09.000000000 -0700
Change: 2014-04-03 16:14:09.000000000 -0700
[root@rusky /]# touch -r var test  #-r 指定参考文件,将test文件的时间设置为跟var的时间属性一致
[root@rusky /]# stat test
  File: `test'
  Size: 16              Blocks: 16         IO Block: 4096   regular file
Device: 802h/2050d      Inode: 48          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-04-28 02:35:05.000000000 -0700
Modify: 2014-04-03 16:14:09.000000000 -0700
Change: 2014-05-02 07:42:22.000000000 -0700
[root@rusky /]# touch var  #如果不指定任何参数,var文件存在,则touch命令会将文件var的时间属性设置为当前系统时间,并且,如果var文件不存在,则会创建一个新的文件var,并且时间为当前系统时间;
[root@rusky /]# stat var
  File: `var'
  Size: 4096            Blocks: 16         IO Block: 4096   directory
Device: 802h/2050d      Inode: 191809      Links: 20
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-05-02 07:43:09.000000000 -0700
Modify: 2014-05-02 07:43:09.000000000 -0700
Change: 2014-05-02 07:43:09.000000000 -0700
[root@rusky /]# touch -d 05:59:59am10/01/2012 test  #-d 与-t类似,用于指定时间,时间格式不固定。
[root@rusky /]# stat test
  File: `test'
  Size: 16              Blocks: 16         IO Block: 4096   regular file
Device: 802h/2050d      Inode: 48          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-10-01 05:59:59.000000000 -0700
Modify: 2012-10-01 05:59:59.000000000 -0700
Change: 2014-05-02 07:58:16.000000000 -0700
[root@rusky /]# touch -d 2022/01/01 test
[root@rusky /]# stat test
  File: `test'
  Size: 16              Blocks: 16         IO Block: 4096   regular file
Device: 802h/2050d      Inode: 48          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-01-01 00:00:00.000000000 -0800
Modify: 2022-01-01 00:00:00.000000000 -0800
Change: 2014-05-02 07:58:52.000000000 -0700

posted on 2014-05-02 23:06  遠離塵世の方舟  阅读(356)  评论(0编辑  收藏  举报

导航