zoukankan      html  css  js  c++  java
  • find命令

    which whereis  locate  //平时搜索文件的命令,但是搜的不全。
    [root@master ~]# which ls
    alias ls='ls --color=auto'
            /usr/bin/ls
    [root@master ~]# whereis ls
    ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
    [root@master ~]#  yum install -y mlocate    #使用之前要安装,系统默认没安装。
    [root@master ~]# locate ls    #用这个命令 前提是要生成一些库文件。
    locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
    [root@master ~]# updatedb   
    [root@master ~]# locate aa/
    /root/aa/1.txt
    /usr/share/locale/aa/LC_MESSAGES
    /usr/share/locale/gaa/LC_MESSAGES
    /usr/share/locale/kaa/LC_MESSAGES
    /usr/share/locale/paa/LC_MESSAGES
    快捷键技巧:
    Ctrl + u可以把该行输入的所有命令清空
    Ctrl + a把光标移动到最前面
    Ctrl + e把光标移动到最后面
    Ctrl + d 相当于执行了exit退出
    find
    [root@master ~]# find /etc/ -name "sshd_config" (在/etc/目录下寻找名字叫sshd_config的文件或者目录)
    /etc/ssh/sshd_config
    [root@master ~]# find /etc/ -name "sshd*"  (在/etc/目录下寻找名字前缀是sshd的文件或者目录,其实就是模糊搜索。也就是代表搜索sshd开头的文件或目录)
    /etc/ssh/sshd_config
    /etc/systemd/system/multi-user.target.wants/sshd.service
    /etc/sysconfig/sshd
    /etc/pam.d/sshd
    [root@master ~]#  find /etc/ -type d -name "sshd*"  (-d参数只搜索目录)
    [root@master ~]#  find /etc/ -type f -name "sshd*"   (-f参数只搜索文件;l为软链接文件;c为字符串设备;b为block文件一般在/dev/下)
    /etc/ssh/sshd_config
    /etc/sysconfig/sshd
    /etc/pam.d/sshd
     
    通过stat命令是用来查看文件具体的信息的,比如文件的名字、大小、inode号、所用的块、权限、块设备、软连接,硬链接。
    详解三个time;
    [root@master ~]# stat 1.txt     
      File: ‘1.txt’
      Size: 0               Blocks: 0          IO Block: 4096   regular empty file
    Device: 802h/2050d      Inode: 100663364   Links: 2
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Context: unconfined_u:object_r:admin_home_t:s0
    Access: 2018-06-08 02:24:05.133623419 +0800    (访问的时间)
    Modify: 2018-06-08 02:24:05.133623419 +0800  (更改文件内容的时间)
    Change: 2018-06-08 02:24:42.092626272 +0800   (改动inode号的时间)
    Birth: -
     
      find的 -mtime是文件最近改动的时间,即是文件内容改动
    -atime是最近访问时间
    -ctime是最近改动时间,是改动如权限一类文件信息,而不是文件内容
    查看一天内发生更改的文件:
    [root@master ~]# find /etc/ -type f -mtime -1
    /etc/resolv.conf
    /etc/group
    /etc/gshadow
    /etc/tuned/active_profile
    [root@master ~]#  find /etc/ -type f  -mtime -1 -o -name "*.conf"  (-o表示或者)
     
    通过inode 号查找硬链接文件:
    [root@master ~]# ls -i 1.txt  (通过-i 参数查看到inode号)
    100663364 1.txt
    [root@master ~]# find / -inum 100663364  (通过-inum参数,去查找有多少个文件共同使用一个inode号。)
    /root/1.txt
    /root/aa/1.txt
     
    查找一小时以内的更改过的文件:
    [root@master ~]# find /root/ -type f -mmin -60  (通过-mmin参数,也就是按分钟去查找)
    查看并用ls -l的方式展现:
    [root@master ~]# find /root/ -type f -mmin -120 -exec ls -l {} ;
    更改找到文件或文件夹名称:
    [root@master ~]# find /root/ -type f -mmin -120 -exec mv {} {}.bak ;
    [root@master ~]#  find /root/ -type f -mmin -120
    查找小于10k的文件:
    [root@master ~]#  find /root/ -type f -size -10k -exec ls -lh {} ;
    -rw-r--r--. 1 root root 18 Dec 29  2013 /root/.bash_logout
    .-rw-r--r--. 1 root root 176 Dec 29  2013 /root/.bash_profile
    -rw-r--r--. 1 root root 176 Dec 29  2013 /root/.bashrc
    -rw-r--r--. 1 root root 100 Dec 29  2013 /root/.cshrc
    -rw-r--r--. 1 root root 129 Dec 29  2013 /root/.tcshrc
    -rw-------. 1 root root 3.3K Jun  8 02:32 /root/.bash_history
    -rw-------. 1 root root 1.4K Jun  7 03:31 /root/.viminfo
    -rw-r--r--. 2 root root 0 Jun  8 02:24 /root/1.txt
    -rw-r--r--. 2 root root 0 Jun  8 02:24 /root/aa/1.txt
    -rw-------. 1 root root 1.5K May 15 23:29 /root/anaconda-ks.cfg
     
  • 相关阅读:
    JVM内存分配及GC流程
    打印手机当前界面(位于栈顶)的activity
    AIDL通信过程中设置死亡代理
    最短路径&次短路径算法
    DEX、ODEX、OAT文件&Dalvik和ART虚拟机
    主线程中有多个handler的情况
    GB GBRT XgBoost
    logistic回归为什么要使用sigmoid函数
    十道海量数据处理面试题与十个方法大总结
    常见数据结构和算法题
  • 原文地址:https://www.cnblogs.com/xiaoliangxianshen/p/9154979.html
Copyright © 2011-2022 走看看