搜索fing


1.which   用于搜索一个命令在什么地方,不能搜索文件
  eg:[root@ns1 ~]# which passwd
      /usr/bin/passwd
2.有些命令 比如 pwd ls cp  mv cat 可以直接使用  是因为他们在环境变量 echo $PATH下都可以找到
3.locate   用来查询数据库中文件
    如果locate命令不能使用,先进行安装
 [root@ns1 tmp]# touch /root/erzi.com
 [root@ns1 tmp]# locate erzi.com
 [root@ns1 tmp]# updatedb                       //数据库的更新每天在凌晨4点会执行一次
 [root@ns1 tmp]# locate erzi.com
 显示结果:/root/erzi.com
4.查询文件或目录的命令   find  这个命令比较强大
  eg:[root@ns1 tmp]# find . -name father          //查询本目录下名字叫father的文件
      显示结果:./father
      [root@ns1 tmp]# find . -name son          
      显示结果:./zuzong/son                   
      [root@ns1 tmp]# find . -type f -name son     //只要文档    
      显示结果:./zuzong/son
   [root@ns1 tmp]# find . -mtime +10            //查询10天以前创建的
  ./yum.log
  ./auto2Ij53g
   [root@ns1 tmp]# find . -mtime -10            //查询10天以内创建的
  . 
  ./mother
  ./father
  ./zuzong
  ./zuzong/son
  ./.ICE-unix
   [root@ns1 tmp]# find . -mmin +10            //10分钟
  .
  ./mother
  ./yum.log
  ./father
  ./zuzong
  ./zuzong/son
  ./auto2Ij53g
  ./.ICE-unix
  [root@ns1 tmp]# find . -mmin -10
      [root@ns1 tmp]#
      [root@ns1 tmp]# stat zuzong              //查看这个目录
  File: "zuzong"
  Size: 4096       Blocks: 8          IO Block: 4096   目录
  Device: 803h/2051d Inode: 659359      Links: 2
  Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
  Access: 2018-03-30 00:22:38.033079400 +0800               //访问时间
  Modify: 2018-03-30 00:22:16.049079037 +0800               //创建时间
  Change: 2018-03-30 00:22:16.049079037 +0800               //更改属性权限的时间
  
    删除日志:find /date/log/ -mtime +30 -type f |xargs rm -f    或者   find /date/log/ -mtime +30 -type f -exec rm {} \; // \转意符
 修改文件的名称:find ./ -type f |xargs -i mv {} {} .bak          //  -i的意思是一个一个处理
 删除文件:find ./ -type f |xargs rm
            [root@ns1 tmp]# ls -la
    总用量 20
    drwxrwxrwt.  5 root root 4096 3月  30 17:14 .
    dr-xr-xr-x. 25 root root 4096 3月  30 17:14 ..
    drwx------   2 root root 4096 3月   6 17:33 auto2Ij53g
    -rw-r--r--   1 root root    0 3月  30 00:14 father
    drwxrwxrwt   2 root root 4096 3月  30 17:14 .ICE-unix
    -rw-r--r--   1 root root    0 3月  30 00:14 mother
    -rw-------.  1 root root    0 3月   5 23:59 yum.log
    drwxr-xr-x   2 root root 4096 3月  30 00:22 zuzong
            [root@ns1 tmp]# find ./ -type f |xargs rm
               [root@ns1 tmp]# ls -la
    总用量 20
    drwxrwxrwt.  5 root root 4096 3月  30 18:08 .
    dr-xr-xr-x. 25 root root 4096 3月  30 17:14 ..
    drwx------   2 root root 4096 3月   6 17:33 auto2Ij53g
    drwxrwxrwt   2 root root 4096 3月  30 17:14 .ICE-unix
    drwxr-xr-x   2 root root 4096 3月  30 18:08 zuzong
5.软链接
     eg:         
   [root@ns1 ~]# touch /root/zjz.com
   [root@ns1 ~]# ls -la
   总用量 80
   dr-xr-x---.  2 root root  4096 3月  30 18:25 .
   dr-xr-xr-x. 25 root root  4096 3月  30 18:24 ..
   -rw-------.  1 root root  1250 3月   6 00:11 anaconda-ks.cfg
      -rw-------.  1 root root   622 3月   6 18:13 .bash_history
   -rw-r--r--.  1 root root    18 5月  20 2009 .bash_logout
   -rw-r--r--.  1 root root   176 5月  20 2009 .bash_profile
   -rw-r--r--.  1 root root   176 9月  23 2004 .bashrc
   -rw-r--r--.  1 root root   100 9月  23 2004 .cshrc
   -rw-r--r--.  1 root root 28232 3月   6 00:11 install.log
   -rw-r--r--.  1 root root  7570 3月   6 00:07 install.log.syslog
   -rw-r--r--.  1 root root   129 12月  4 2004 .tcshrc
   -rw-------   1 root root   875 3月   6 17:32 .viminfo
   -rw-r--r--   1 root root     0 3月  30 18:25 zjz.com                 
   [root@ns1 ~]# 
   [root@ns1 ~]# ln -s /root/zjz.com linux     做软链接       做软链接时最好写成绝对路径
   [root@ns1 ~]# ls -l
   总用量 44
   -rw-------. 1 root root  1250 3月   6 00:11 anaconda-ks.cfg
   -rw-r--r--. 1 root root 28232 3月   6 00:11 install.log
   -rw-r--r--. 1 root root  7570 3月   6 00:07 install.log.syslog
   lrwxrwxrwx  1 root root    13 3月  30 18:27 linux -> /root/zjz.com //发生变化  此行开头的l表示这是一个软链接,名字叫Linux,其真正的文件在root下叫zjz.com
   -rw-r--r--  1 root root     0 3月  30 18:25 zjz.com
     
             一个软连接的例子
            [root@ns1 ~]# cat linux
   [root@ns1 ~]# echo "wo shi ni baba." > /root/zjz.com
   [root@ns1 ~]# cat linux
            wo shi ni baba.
            软链接的作用:可以很快很方便的查找文件
6.硬链接
      做硬链接有限制:不能在同一个分区下,不能给目录做硬链接
    例如:
    [root@ns1 tmp]# ln zjz zjz
  ln: "zjz": 不允许将硬链接指向目录   //提示不能给目录做硬链接
       做硬链接:
          [root@ns1 tmp]# touch father.txt
             [root@ns1 tmp]# ln father.txt son.txt
              [root@ns1 tmp]# ls -li
    总用量 8
    659355 drwx------  2 root root 4096 3月   6 17:33 auto2Ij53g
    659360 -rw-r--r--  2 root root    0 3月  30 18:50 father.txt     //最前面659360
    659361 -rw-r--r--  1 root root    0 3月  30 18:50 mother.txt
    659360 -rw-r--r--  2 root root    0 3月  30 18:50 son.txt        //659360    两者相同
    655362 -rw-------. 1 root root    0 3月   5 23:59 yum.log
    659359 drwxr-xr-x  2 root root 4096 3月  30 18:46 zjz
             把源(father.txt)删了也没关系 ,只要替身(son.txt)在 数据就在。
    [root@ns1 tmp]# rm -f father.txt
    [root@ns1 tmp]# ls -li
    总用量 8
    659355 drwx------  2 root root 4096 3月   6 17:33 auto2Ij53g
    659361 -rw-r--r--  1 root root    0 3月  30 18:50 mother.txt
    659360 -rw-r--r--  1 root root    0 3月  30 18:50 son.txt
    655362 -rw-------. 1 root root    0 3月   5 23:59 yum.log
    659359 drwxr-xr-x  2 root root 4096 3月  30 18:46 zjz
            硬链接的作用:更安全,做备份,不占用磁盘空间
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值