文件/目录操作(4)——file、stat、du命令

来源:互联网 发布:迅捷pdf分割软件 编辑:程序博客网 时间:2024/04/28 08:02
 file命令

        file   file1   file2  

        file    -b             //查看文件类型

        file    -f              //读出文本文件中每一行的文件,并判别文件类型【脚本中查看文件类型】
[root@localhost shell]# file test.txt test.txt: ASCII text[root@localhost shell]# file -b test.txt ASCII text[root@vm_hosts ~]# cat file.txt /etc/passwdstring just a test txt[root@vm_hosts ~]# file -f file.txt /etc/passwd:            ASCII textstring just a test txt: cannot open `string just a test txt' (No such file or directory)

stat命令
         显示对象的详细信息(状态)        
[root@localhost lyj]# stat .  File: "."  Size: 4096      Blocks: 8          IO Block: 4096   目录Device: fd00h/64768dInode: 1572865     Links: 3Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)Access: 2015-10-13 03:14:08.797401158 +0800Modify: 2015-10-08 03:32:55.600587141 +0800Change: 2015-10-08 03:32:55.600587141 +0800
注意这三个“时间”的不同:   
         Access:上一次访问时间。
         Modify:上一次修改时间——指“内容的修改”。
         Change:上一次状态/属性修改时间——指“属性(如权限、大小等的修改)”。
         
        stat   -f  显示有关文件系统(而非文件)的信息
        stat   -t  以一行的格式显示信息【在shell脚本中有用!】
[root@localhost lyj]# stat -f .  File: "."    ID: ad73353be9b38fb8 Namelen: 255     Type: ext2/ext3Block size: 4096       Fundamental block size: 4096Blocks: Total: 12901535   Free: 7968969    Available: 7313609Inodes: Total: 3276800    Free: 3151282[root@localhost lyj]# stat -t  .. 4096 8 41ed 0 0 fd00 1572865 3 0 0 1444677248 1444246375 1444246375 4096

       
du命令  
      du  file1 file2   显示指定文件/目录的大小      
      -s                       显示当前目录的大小(而不包括显示子目录)
      -h                       以K、M、G这样易读的单位显示
      -c                       显示大小并最后计算count总和大小
      du  | sort  -nr    按文件大小排序
      du  -h  --max-depth=1   输出当前目录下各个子目录的大小 
[root@localhost ~]# du  -sh /etc/passwd4.0K/etc/passwd[root@localhost ~]# du -h --max-depth=1   /etc28K/etc/rpm52K/etc/udev20K/etc/audisp20K/etc/ConsoleKit4.0K/etc/thnuclnt72K/etc/init40K/etc/logrotate.d

        
0 0