Simple Linux Command Line notes: Find

Source: Internet
Author: User
ArticleDirectory
    • Parameters
    • Condition
    • Example 1 (search by attribute)
    • Example 2 (search by Time)
    • Example 3 (search by file type)
    • Example 4 (connector)
    • Tips

Search for files based on conditions

Find [Directory-list] [Expression]

 

Parameters

Directory-listUsed to specifyFindDirectory hierarchy or range to be searched

If noDirectory-list,FindThe hierarchy of the current working directory will be searched

 

Condition

There are many conditions that can be used in expression. I have written them into categories.

Some of the conditions include +-N, which means:

+ N is greater than N

-N is smaller than N.

N is EXACTLY n

 

Search by file attributes

-User name: searches for files whose owner is name.

-Group Name: Find the file whose group is name.

-Name filename: Find the file named filename.

-Nogroup: Search for files not in any group

-Nouser: Search for files not belonging to any user

-Perm mode: searches for files based on file permissions.

-Inum N: Find the object whose node is N.

-Links +-N: number of file links found +-N files

-Size +-N [c | K | M | G]: searches for files based on the file size. The default size is +-N times the size of 512 bytes, or the unit is kb, MB, or GB.

 

Search by time unit

The unit of time is followed by +-N, indicating the number of (days, minutes) within/outside. The following are 6 time units.

Day: ctime atime mtime

Min.: Cmin Amin mmin

So what does the above c a m mean?

C change indicates that the file property has been modified, including the owner, group, and permission (that is, What ls-l can see)

A access

M modify: indicates the file content has been modified.

 

Search by file type

-Type filetype: if the file type is filetype, the file meets the search criteria. The file types include:

B. Special Block Files

C Special Character files

D directory file

F Common File

L Symbolic Link

 

Connector

-A and logic and

-O or logic or

-Exec command {}\; The format is fixed, indicating that some operations are performed after the file is found.

{} Indicates the search result in find.

\ Represents the Escape Character. Use the command itself (ignore aliases)

; Indicates the end of the entire statement.

-OK: Check whether the operation is performed. The usage is the same as that of exec.

 

Example 1 (search by attribute) Find-user
$Find/Etc-User Siu/Etc/Firefox-3.0/Etc/Firefox-3.0/Pref/Etc/Firefox-3.0/Pref/apturl. js

Search for files by owner

 

Find-perm
$Find/Etc-perm600/Etc/PPP/chap-Secrets/Etc/PPP/PAP-Secrets/Etc/Passwd-/Etc/group-/etc/gshadow-/etc /.PWD. Lock/Etc/shadow-/etc/APT/Trustdb. GPG/Etc/default/Cacerts/Etc/security/Opasswd/Etc/MySQL/Debian. CNF/Etc/mtab. fuselock

Find Files Based on File Permissions

 

Find-name
$ Find /Etc- Name init /Etc/ Init /Etc/apparmor/ Init $  Find /Etc-name init */etc/ Init /Etc/apparmor/ Init /Etc/initramfs- Tools /Etc/initramfs-tools/scripts/init- Premount /Etc/initramfs-tools/scripts/init- Bottom /Etc/initramfs-tools/scripts/init- Top /Etc/initramfs-tools/ Initramfs. conf /Etc/bash_completion.d/initramfs- Tools /Etc/ Init. d /Etc/kernel/postinst. d/initramfs- Tools /Etc/kernel/postrm. d/initramfs- Tools /Etc/Wireshark/init. Lua

Search by the full name of the file name. If it is not the full name, you can use the wildcard * or?

 

Find-nogroup-nouser
 
$Find/Etc-nogroup-Nouser $

Search for files with no groups and no users.

Find-size
 
$Find/Etc/-size +1 m/Etc/brltty/ZH-Tw. CTB/Etc/skel/. Mozilla/Firefox/mwad0hks. Default/Places. SQLite/Etc/skel/. config/chromium/Safe browsing bloom

Searches for files in the specified unit size. The default unit is 512 bytes of data block, which is inconvenient.

In MB, search for files larger than 1 MB.

 

Example 2 (search by Time) Find-mmin
 
$Find/Etc-mmin-120/Etc/Cups/Etc/cups/Subscriptions. conf. o/Etc/cups/subscriptions. conf

Search for files with modified content within two hours

 

Find-mtime
 
$Find/Etc-mtime-2/Etc/Etc/Mtab/Etc/update-motd.d/10-Help-Text/Etc/gnome/Defaults. List/Etc/cups

Search for files with modified content within two days

 

Example 3 (search by file type) Find-type
 
$Find/Etc-Type D/Etc/Etc/-Spi2/Etc/Purple/Etc/Ndiswrapper/Etc/Init/Etc/ImageMagick/Etc/gnome-app-Install

Find the files under the/etc directory whose file type is directory

TIPS:Everything in Linux is a file, including a directory

 

Example 4 (connector) -A logic and
$Find/Etc-name init *--Type F/Etc/initramfs-tools/Initramfs. conf/Etc/bash_completion.d/initramfs-Tools/Etc/kernel/postinst. d/initramfs-Tools/Etc/kernel/postrm. d/initramfs-Tools/Etc/Wireshark/init. Lua

Search for files whose names start with init and whose types are common in the/etc directory

 

-P logic or
 
$Find/Etc-name system-o-Name init/Etc/Init/Etc/apparmor/Init/Etc/systemd/System

View the file named system or init in the/etc directory.

 

Find-Exec
$Find/Etc-name system-ExecLs-L {}\; total usage4Drwxr-XR-x2Root4096December9 21:49Multi-user.target.wants

Search for a file named system and use LS-L to display its details.

 

Find-OK
$Ls-I672684AA $Find./-Inum672684-OKRm{}\;<Rm.../AA>?Y $Ls-I $

Find the file of the specified node in the local directory and ask whether to delete it.

TIPS: The difference between-OK and-exec is that one request is executed, and the other is executed directly.

If the alias Rm = 'rm-I 'is set in some Linux distributions, the \ escape character can be used to restore the RM command, which is a fixed usage and a hidden rule.

 

 

Tips

1. The find command is exceptionally powerful. You can set many search conditions. For details, see the man page.

2. Use the find command to specify the search range first. The smaller the range, the better. Meanwhile, the more accurate the conditions, the higher the efficiency.

 

 

Related Article

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.