Linux学习
一、find命令
二、文件后缀名
一、find命令
1、搜索文件的命令:which、whereis、locate、find
a、which只能用来查找在PATH环境变量中的出现可执行的文件。
[root@01 ~]# which vi
/usr/bin/vi
[root@01 ~]#
b、whereis类似于模糊查找。预先生成的一个文件列表库查找与给出的文件名相关的文件。
[root@01 ~]# whereis -m vi
vi: /usr/share/man/man1/vi.1.gz
[root@01 ~]# whereis -b vi
vi: /usr/bin/vi
[root@01 ~]# whereis -s vi
vi:[root@01 ~]# whereis vi
vi: /usr/bin/vi /usr/share/man/man1/vi.1.gz
[root@01 ~]#
c、locate命令需要安装,命令为:yum install -y mlocate。安装完成后需要执行updatedb命令才能更新库,如果服务器运行重要的文件情况下,尽量不要使用updatedb命令。locate和whereis都是模糊搜索。
[root@01 ~]# locate
locate: no pattern to search for specified
[root@01 ~]# updatedb
[root@01 ~]# locate 123
/home/admin/123
/root/12345
/root/12345/123.log
/root/66/123.txt
/root/admin/123
/root/admin/123.txt
/usr/lib/modules/3.10.0-693.el7.x86_64/kernel/drivers/media/dvb-frontends/cx24123.ko.xz
/usr/lib64/gconv/IBM1123.so
/usr/share/man/man1/perl5123delta.1.gz
/usr/share/perl5/pod/perl5123delta.pod
[root@01 ~]#
2、find命令,find / -name
[root@01 ~]# find /etc/ -name sshd*
/etc/ssh/sshd_config
/etc/systemd/system/multi-user.target.wants/sshd.service
/etc/sysconfig/sshd
/etc/pam.d/sshd
[root@01 ~]#
[root@01 ~]# find / -name seli*
/sys/kernel/slab/selinux_inode_security
/etc/sysconfig/selinux
/etc/selinux
/etc/selinux/targeted/active/modules/100/selinuxutil
/usr/sbin/selinux_restorecon
/usr/sbin/selinuxconlist
/usr/sbin/selinuxdefcon
/usr/sbin/selinuxenabled
/usr/sbin/selinuxexeccon
/usr/lib/systemd/system/basic.target.wants/selinux-policy-migrate-local-changes@targeted.service
/usr/lib/systemd/system/selinux-policy-migrate-local-changes@.service
/usr/lib/dracut/modules.d/98selinux/selinux-loadpolicy.sh
/usr/lib/tmpfiles.d/selinux-policy.conf
/usr/lib64/python2.7/site-packages/selinux
/usr/share/man/man5/selinux_config.5.gz
/usr/share/man/man8/selinux.8.gz
/usr/share/man/man8/selinuxconlist.8.gz
/usr/share/man/man8/selinuxdefcon.8.gz
/usr/share/man/man8/selinuxenabled.8.gz
/usr/share/man/man8/selinuxexeccon.8.gz
/usr/share/selinux
/usr/libexec/selinux
/usr/libexec/selinux/selinux-policy-migrate-local-changes.sh
a、find命令,find / -type 查找etc下面"l"类型的软连接文件;
[root@01 ~]# find /etc/ -type l
/etc/rc.d/rc2.d/K50netconsole
/etc/rc.d/rc3.d/S10network
/etc/rc.d/rc3.d/K50netconsole
/etc/rc.d/rc4.d/S10network
/etc/rc.d/rc4.d/K50netconsole
/etc/rc.d/rc5.d/S10network
/etc/rc.d/rc5.d/K50netconsole
/etc/rc.d/rc6.d/K90network
/etc/rc.d/rc6.d/K50netconsole
find 目录 -需求(name、type等) 搜索的类型
b、三个time:mtime、ctime、atime。mtime创建时间;atime最近访问时间;ctime最近改动时间。内容更改ctime一定会变;查看文件内容atime会变。
[root@01 ~]# touch 222.txt
[root@01 ~]# stat 222.txt
File: ‘222.txt’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 33580935 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-09-18 09:21:46.898053755 -0400 //Atime
Modify: 2018-09-18 09:21:46.898053755 -0400 //Mtime
Change: 2018-09-18 09:21:46.898053755 -0400 //Ctime
Birth: -
[root@01 ~]#
[root@01 ~]# echo "123123123123123123123" >> 222.txt
[root@01 ~]# stat 222.txt
File: ‘222.txt’
Size: 22 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 33580935 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-09-18 09:21:46.898053755 -0400
Modify: 2018-09-18 09:27:06.903462462 -0400
Change: 2018-09-18 09:27:06.903462462 -0400
Birth: -
[root@01 ~]#
c、find /etc/ -type f -mtime -1 :查找/目录下,一天以内变动的文件
[root@01 ~]# find /etc/ -type f -mtime -1
/etc/resolv.conf
/etc/group
/etc/gshadow
/etc/tuned/active_profile
[root@01 ~]#
d、find / -inum inode号;查找硬链接文件,-inum(inode number)
[root@01 ~]# find / -inum 33659253
/root/12.log
[root@01 ~]#
e、find /root/ -type f -mmin -120 -exec ls -l {} ; -exec选项,查找到文件后
[root@01 ~]# find /root/ -type f -mmin -120 -exec ls -l {} \;
-rw-r--r-- 1 root root 22 Sep 18 09:27 /root/222.txt
[root@01 ~]#
f、find /root/ -type f -size -10k -exec ls -lh {} ; 显示小于10K的文件
[root@01 ~]# find /root/ -type f -size -10k -exec ls -lh {} \;
-rw-r--r--. 1 root root 18 Dec 28 2013 /root/.bash_logout
-rw-r--r--. 1 root root 176 Dec 28 2013 /root/.bash_profile
-rw-r--r--. 1 root root 176 Dec 28 2013 /root/.bashrc
-rw-r--r--. 1 root root 100 Dec 28 2013 /root/.cshrc
-rw-r--r--. 1 root root 129 Dec 28 2013 /root/.tcshrc
-rw-------. 1 root root 1.3K Sep 11 16:53 /root/anaconda-ks.cfg
-rw-------. 1 root root 6.0K Sep 17 09:45 /root/.bash_history
-rw-------. 1 root root 1.7K Sep 11 09:30 /root/.ssh/id_rsa
-rw-r--r--. 1 root root 408 Sep 11 09:30 /root/.ssh/id_rsa.pub
-rw-r--r--. 1 root root 176 Sep 11 09:31 /root/.ssh/known_hosts
-rw-------. 1 root root 389 Sep 11 09:36 /root/.ssh/authorized_keys
-rwxrwxrwx 1 user1 user1 0 Sep 16 01:40 /root/2/1.txt
-rw-r--r--. 1 root root 846 Sep 13 08:45 /root/passwd
-rw-------. 1 root root 921 Sep 16 01:33 /root/.viminfo
-rwxrwxrwx 1 root root 0 Sep 16 01:50 /root/2.txt
-rw-r--r-- 1 root root 0 Sep 16 02:07 /root/11.txt
-rw-r--r-- 1 root root 887 Sep 16 02:39 /root/66/123.txt
-rw-r--r-- 1 root root 0 Sep 16 02:35 /root/66/345.txt
-rw-r--r-- 1 root root 0 Sep 17 08:47 /root/admin/123.txt
-rw-r--r-- 1 root admin 0 Sep 17 08:54 /root/666/12.txt
-rw-r--r-- 1 root root 0 Sep 17 08:55 /root/666/888.txt
-rw-r--r-- 1 root root 5.5K Sep 17 09:34 /root/23.txt
-rw-r--r-- 1 root root 22 Sep 18 09:27 /root/222.txt
二、文件名后缀
1、区分大小写
[root@01 ~]# LS
-bash: LS: command not found
[root@01 ~]# ls
11.txt 12345 12.log 1.txt 2 222.txt 23.txt 2.txt 3 4 66 666 admin anaconda-ks.cfg passwd
[root@01 ~]#
2、Linux下可以自定义文件的后缀名,但并不能代表文件的类型;相同类型的文件定义相同的后缀名,方便区分。比如配置文件.conf
[root@01 ~]# ls /etc/
adjtime crypttab GeoIP.conf.default kernel my.cnf profile.d selinux terminfo
aliases csh.cshrc gnupg krb5.conf my.cnf.d protocols services tmpfiles.d
aliases.db csh.login GREP_COLORS krb5.conf.d NetworkManager python sestatus.conf tuned
alternatives dbus-1 groff ld.so.cache networks rc0.d shadow udev
anacrontab default group ld.so.conf nsswitch.conf rc1.d shadow- updatedb.conf
asound.conf depmod.d group- ld.so.conf.d nsswitch.conf.bak rc2.d shells vconsole.conf
audisp dhcp grub2.cfg libaudit.conf openldap rc3.d skel vimrc
audit DIR_COLORS grub.d libnl opt rc4.d ssh virc
bash_completion.d DIR_COLORS.256color gshadow libuser.conf os-release rc5.d ssl vmware-tools
bashrc DIR_COLORS.lightbgcolor gshadow- locale.conf pam.d rc6.d statetab wpa_supplicant
binfmt.d dracut.conf gss localtime passwd rc.d statetab.d X11
centos-release dracut.conf.d host.conf login.defs passwd- rc.local subgid xdg
centos-release-upstream e2fsck.conf hostname logrotate.conf pkcs11 redhat-release subuid xinetd.d
chkconfig.d environment hosts logrotate.d pki resolv.conf sudo.conf yum
chrony.conf ethertypes hosts.allow machine-id plymouth rpc sudoers yum.conf
chrony.keys exports hosts.deny magic pm rpm sudoers.d yum.repos.d
cron.d favicon.png init.d makedumpfile.conf.sample polkit-1 rsyslog.conf sudo-ldap.conf
cron.daily filesystems inittab man_db.conf popt.d rsyslog.d sysconfig
cron.deny firewalld inputrc mke2fs.conf postfix rwtab sysctl.conf
cron.hourly fstab iproute2 modprobe.d ppp rwtab.d sysctl.d
cron.monthly fuse.conf issue modules-load.d prelink.conf.d sasl2 systemd
crontab gcrypt issue.net motd printcap securetty system-release
cron.weekly GeoIP.conf kdump.conf mtab profile security system-release-cpe
[root@01 ~]#