Linux Learning Note 4 find

Source: Internet
Author: User


Find

-type

File type: Common f common file, D directory file,

-name

The most commonly used option is either to use this option alone or to use it with other options. You can use a file name pattern to match files, remembering to enclose the filename pattern in quotation marks. No matter what the current path is, if you want to find the file name in your root $home that matches *.log, use ~ as the ' pathname ' parameter, and the tilde ~ represents your $home directory.

Find ~-name "*.log"-print

[Email protected] ~]$ Find ~-name *.log

/home/srd/.imsettings.log

/home/srd/.local/share/gvfs-metadata/computer:-a70bf00a.log

/home/srd/.local/share/gvfs-metadata/label-centos_6.4_final-10158b6b.log

/home/srd/.local/share/gvfs-metadata/home-b5544f17.log

/home/srd/cc/python-3.5.0/build/temp.linux-x86_64-3.5/libffi/config.log

/home/srd/cc/python-3.5.0/config.log

/home/srd/cc/redis-3.0.5/deps/jemalloc/config.log

To find all the ' *.log ' files in the current directory and subdirectories, you can use: Find. -name "*.log"-print

[[email protected] ~]$ find. -name *.log

./.imsettings.log

./.local/share/gvfs-metadata/computer:-a70bf00a.log

./.local/share/gvfs-metadata/label-centos_6.4_final-10158b6b.log

./.local/share/gvfs-metadata/home-b5544f17.log

./cc/python-3.5.0/build/temp.linux-x86_64-3.5/libffi/config.log

./cc/python-3.5.0/config.log

./cc/redis-3.0.5/deps/jemalloc/config.log


Perm According to the file permission mode with the-perm option, according to file permission mode to find files. It is best to use the octal permission notation.

For example, in the current directory to find file permission bit 777 file, that is, the file owner can read, write, execute, other users can read, write, execute files, can be used:

[[email protected] ~]$ find. -perm 777

./.pulse/eae9e860c9ec8073634e4ecc0000003f-runtime

./cc/python-3.5.0/build/temp.linux-x86_64-3.5/libffi/include/ffitarget.h

./cc/python-3.5.0/build/temp.linux-x86_64-3.5/libffi/include/ffi_common.h

[Email protected] ~]$


user and Nouser options: Find files by file owner using the same group and nogroup option usage

Example 1: Find files in the root directory where the file belongs to 123

[[email protected]/]# Find/-user 123

/usr/123

/usr/123/.gnome2

/usr/123/.bashrc

/usr/123/.mozilla

/usr/123/.mozilla/extensions

/usr/123/.mozilla/plugins

/usr/123/.bash_profile

/usr/123/.bash_logout

Example 3: To find files that are already deleted by the master account, you can use the-nouser option. Find all of these files in the/home directory

[[email protected]/]# Find/-nouser  

This will enable you to find files that are not valid accounts in the/etc/passwd file. When using the-nouser option, you do not have to give the user name; the Find command can do the work for you.


-mtime Find files by change time or access time: You can use the Mtime,atime or CTime option if you want to find files by changing the time.  If the system suddenly does not have free space, it is possible that the length of a file grows rapidly during this period, you can use the Mtime option to find such a file. Use a minus sign-to limit the time to change the file within the current n days, and use the Plus + to limit the change time before the current n days of the file. To find files that change within 5th of the system root directory, you can use:

[[email protected]/]# Find/-mtime +9 9 days ago File



[[email protected]/]# Find/-mtime-5 files within 5 days


[[email protected]/]# Find/-name passwd-print Locate the passwd file with the directory and print it on the terminal (print can be omitted)

/etc/pam.d/passwd

/etc/passwd

/usr/bin/passwd

/selinux/class/passwd

/selinux/class/passwd/perms/passwd



[[email protected]/]# find/var/log-type f-mtime +5 Find/var/log The last modified date is 5 days ago

/var/log/maillog-20160124

/var/log/messages-20160103

/var/log/dracut.log-20160101

/var/log/maillog-20160110

/var/log/yum.log

/var/log/maillog-20160103

/var/log/mysqld.log

/var/log/anaconda.program.log

/var/log/spooler-20160124

/var/log/secure-20160110

/var/log/secure-20160103

/var/log/cron-20160117

/var/log/pm-powersave.log

/var/log/xorg.9.log

/var/log/anaconda.log

/var/log/wpa_supplicant.log



[Email protected]/]# find/var/log-type f-mtime +5-exec chown-r srd:srd {} \;

Find/var/log the last modified date is 5 days old, and the file owner is changed to SRD:SRD

[Email protected]/]# CD Var/log

[email protected] log]# LL

Total 1704

-RW-------. 1 SRD srd 2368 Dec 14:04 anaconda.ifcfg.log

-RW-------. 1 SRD srd 20626 Dec 14:04 anaconda.log

-RW-------. 1 SRD srd 44877 Dec 14:04 anaconda.program.log

-RW-------. 1 SRD srd 115558 Dec 14:04 anaconda.storage.log

-RW-------. 1 SRD srd 50364 Dec 14:04 anaconda.syslog

-RW-------. 1 SRD srd 60867 Dec 14:04 anaconda.xlog

-RW-------. 1 SRD srd 115227 Dec 14:04 anaconda.yum.log

Drwxr-x---. 2 root root 4096 June audit

-rw-r--r--. 1 SRD srd 2546 Dec 14:10 boot.log


[Email protected]/]# Find/etc/services-type F-print | Xargs grep "passwd"

Look for the passwd file below/etc/services and show

Pass the Find command output information to Xargs,xargs batch processing

KPASSWD 464/tcp kpwd # Kerberos "passwd"

KPASSWD 464/udp kpwd # Kerberos "passwd"

Passwd_server 752/udp QRH # Kerberos passwd Server

RPASSWD 774/tcp #

[Email protected]/]#

It's the same thing without print.

[Email protected]/]# Find/etc/services-type F | Xargs grep "passwd"

KPASSWD 464/tcp kpwd # Kerberos "passwd"

KPASSWD 464/udp kpwd # Kerberos "passwd"

Passwd_server 752/udp QRH # Kerberos passwd Server

RPASSWD 774/tcp




Linux Learning Note 4 find

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.