Linux Basic Command (a) Find command overview

Source: Internet
Author: User

The Linux Find command searches for files in the directory structure and performs the specified actions. Linux under Find command provides a considerable number of search conditions, the function is very powerful. Because find has a powerful feature, it has a lot of options, and most of the options are worth taking time to understand. Even if the system contains a network file system (NFS), the Find command is equally valid in the file system, only you have the appropriate permissions. When running a very resource-consuming find command, many people tend to put it in the background because it can take a long time to traverse a large file system (this refers to a file system above 30G bytes).

1. Command format:

Find Pathname-options [-print-exec-ok ...]

2. Command function:

Used to look up files in a file tree and make the appropriate processing

3. Command parameters:

The directory path that the Pathname:find command looks for. For example, to represent the current directory, with/to represent the system root directory.

The-print:find command outputs matching files to the standard output.

The-exec:find command executes the shell command given by the parameter to the matching file. The corresponding command is in the form of ' command ' {} \;, notice the space between {} and \;

-ok: The same as the-exec, but in a more secure mode to execute the shell command given by this parameter, before executing each command, will be prompted to let the user determine whether to execute.

4. Command options:

-name finds files by file name.

-perm to find files by file permissions.

-prune Use this option to make the Find command not look up in the currently specified directory, and if you use the-depth option,-prune will be ignored by the Find command.

-user to find files according to the owner of the file.

-group finds files by the group to which the file belongs.

-mtime-n +n to find files according to the file change time-n indicates that the file change time is now within n days, + n indicates that the file change time is now N days ago. The Find command also has the-atime and-ctime options, but they all and the-m time option.

-nogroup finds a file that does not have a valid owning group, that is, the group that the file belongs to does not exist in/etc/groups.

-nouser finds a file that has no valid owner, that is, the owner of the file does not exist in/etc/passwd.

-newer file1! File2 find change times than file File1 new but older files than file file2.

-type find a type of file, such as:

B-block device files.

D-Directory.

C-Character device files.

P-pipe file.

L-Symbolic link file.

F-Normal files.

-size N:[c] finds files with a file length of n blocks, with C indicating the length of the file in bytes. -depth: When looking for a file, first look for the files in the current directory and then look in their subdirectories.

-fstype: Find files in a type of file system that can usually be found in the configuration file/etc/fstab, which contains information about the file system in this system.

-mount: Does not cross the file system mount point when locating files.

-follow: If the find command encounters a symbolic link file, it tracks to the file that the link points to.

-cpio: Use the cpio command for matching files to back up these files to a tape device.

In addition, the following three differences:

-amin N Find the last n minutes of files accessed in the system

-atime N Find the last n*24-hour access to files in the system

-cmin n finds files in the system with the last n minutes of changed file status

-ctime n finds files in the system where the last n*24 hours are changed file status

-mmin n finds files in the system with the last n minutes of changed file data

-mtime n finds files in the system for the last n*24 hours changed file data

5. Use instance:

Example 1: Find a file that has been modified within a specified time

Command

Find-atime-2

Output

[Root@peidachang ~]# Find-atime-2

.

./logs/monitor

./.BASHRC

./.bash_profile

./.bash_history

Description

Look for files that have been modified within 48 hours.

Example 2: Finding by keyword

Command:

Find. -name "*.log"

Output:

[Root@localhost test]# Find. -Name "*.log"

./log_link.log

./log2014.log

./tes T4/log3-2.log

./test4/log3-3.log

./test4/log3-1.log

./log2013.log

./log2012.log

./log.log

./Test5/log5-2.log

./test5/log5-3.log

./test5/log.log

./test5/log5-1.log

./test5/test3/log3-2.log

./test5/test3/log3-3.log

./test5/test3/log3-1.log

./test3/log3-2.log

./test3/log3-3.log

./test3/log3-1.log

Description

Finds files in the current directory that end with. Log. ". " Represents the current directory

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.