Linux command-find: Search for files

Source: Internet
Author: User

The Find command can search for files in a given directory (and its subdirectories) based on the various attributes of the file.

Command format

Find [-h] [-l] [-p] [-D debugopts] [-olevel] [path ...] [Expression]

Command parameter test item

-cmin N
Matches a file or directory that changed state (content or attributes) N minutes ago. If it is less than n minutes, use-N, if more than n minutes, use +n.

-cnewer file
Files or directories that match content or properties that are modified more than file files later.

-ctime N
A file or directory that matches the file status changes (content, attributes, access rights, and so on) in the system n*24 hours ago.

-empty
Match empty files and empty directories.

-group Name
Matches the file or directory that belongs to the name group, and name can be described as either a group name or a reorganized ID.

-iname pattern
Similar to the-name option feature is just case insensitive.

-inum N
A file that matches the index node is n. The test option helps you find all the hard links on a particular index node.

-mmin N
Matches the file or directory to which the content was modified N minutes ago.

-mtime N
Matches only files or directories where the content was changed before n*24 hours.

-name pattern
Matches a file or directory with a specific wildcard pattern

-newer file
Files or directories that match content are modified more closely than file files. This is useful when writing shell scripts for file backups. Each time you create a backup, update a file (such as a log) and use the Find + this parameter option to determine which files changed after the last update.

-nouser
Matches files or directories that do not belong to a valid user. The test option can be used to find files that are part of a deleted account or to detect an attacker's activity.

-nogroup
Match files or directories that do not belong to a valid group

-perm mode
Look for files or directories with access rights that match the established pattern. The established pattern can be expressed in eight or in the form of conformity.

-samefile Name
Similar to the-inum option. Match files with the same index number as the file files.

-size N
Matches a file of size n. +n indicates that the greater than n,-n represents less than N. Find supports metering units with B (representing 512-byte blocks, default units), C (bytes), W (two-byte words), K (KB), M (MB), and G (GB).

-type C
Matches a file of the specified type. The file types supported by Find are B (block device file), C (character device file), D (directory), f (normal file), and L (symbolic link).

-user Name
Matches the file or directory that belongs to the name user. Name can be described as the user name or the user's ID.

Action Item

-delete
Delete the matching file.

-ls
Performs an LS operation on a matching file, outputting its file name and other requested information in a standard format.

-print
The full path of the matching file is output in standard form. When no specific action is specified, the action is the default action.

-quit
Exit once the match is successful.

-exec command {};
A custom action that indicates the name of the action command to be executed,{} curly braces represent the current path, and a semicolon as a required delimiter indicates the end of the command.

Option Item

-depth
The Find program processes the directory before it processes the directory. This parameter option is called automatically when the-delete operation is specified.

-maxdepth levels
When you perform the test condition behavior, set the maximum number of levels that the find program falls into the number of directories.

-mindepth levels
When you apply test conditions and behaviors, set the minimum number of levels that the find program falls into the number of directories.

-mount
Boot find does not traverse directories mounted on other file systems.

-noleaf
Instruct the Find program not to optimize its search based on the assumption that the Unix-like file system is being searched. This option is used when scanning the Dos/windows file system and the CD.

Instance

A) list List of all files in the directory ~/redis/redis-3.0.4/utils/.

Find ~/redis/redis-3.0.4/utils//home/huey/redis/redis-3.0.4/utils//home/huey/redis/redis-3.0.4/utils/ cluster_fail_time.tcl/home/huey/redis/redis-3.0.4/utils/redis_init_script/home/huey/redis/redis-3.0.4/utils/ Mkrelease.sh ...

b) Find all directories of directory ~/redis/redis-3.0.4/utils/.

Find ~/redis/redis-3.0.4/utils/-type d/home/huey/redis/redis-3.0.4/utils//home/huey/redis/redis-3.0.4/ Utils/hyperloglog/home/huey/redis/redis-3.0.4/utils/create-cluster/home/huey/redis/redis-3.0.4/utils/lru

c) Find all common Files under directory ~/redis/redis-3.0.4/utils/that are suffixed with. Sh and are larger than 1KB.

Find ~/redis/redis-3.0.4/utils/-type f-name "*.sh"-size +1k/home/huey/redis/redis-3.0.4/utils/install_ server.sh

D) Look for a file with a pattern of 0775 or 0755 under directory ~/redis/redis-3.0.4/src/(note the space on the command line).

find ~/redis/redis-3.0.4/src/\ (-type f-perm 0775 \)-or \ (-type f-perm 0755 \)/home/huey/redis/redis-3.0.4/s rc/redis-benchmark/home/huey/redis/redis-3.0.4/src/mkreleasehdr.sh/home/huey/redis/redis-3.0.4/src/ redis-check-dump/home/huey/redis/redis-3.0.4/src/redis-check-aof/home/huey/redis/redis-3.0.4/src/redis-server/ home/huey/redis/redis-3.0.4/src/redis-sentinel/home/huey/redis/redis-3.0.4/src/redis-trib.rb/home/huey/redis/ Redis-3.0.4/src/redis-cli

e) Perform the LS operation on the matching file.

Find ~/redis/redis-3.0.4/src/-type f-perm 0755-ls919417 6316-rwxr-xr-x   1 Huey      Huey       6466357 SEP 2 6 13:20/home/huey/redis/redis-3.0.4/src/redis-sentinel

f) Delete the matching file.

Find ~/redis/redis-3.0.4/src/-type f-perm 0755-delete

g) Copy the matching files to the specified directory by customizing the file.

[[email protected] ~]$ mkdir ~/tmpdir[[email protected] ~]$ find ~/redis/redis-3.0.4/src/-type f-perm 0755-exec cp ' {} ' ~/tmpdir '; ' [[email protected] ~]$ ll ~/tmpdir/total 6316-rwxr-xr-x 1 Huey Huey 6466357 OCT-10:04 Redis-sentinel

Linux command-find: Search for files

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.