Basic usage of the find search tool in Linux

Source: Internet
Author: User
Article Title: basic usage of the search tool find in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

We often need to find files in our daily work. The most powerful file search tool in linux is not "find. Find can filter files by file name, read modification time, size, type, and so on, and can complete almost all of the daily search requirements.

Let's look at a simple example:

Find/tmp/-name'Galeki *'

It means to find the file starting with "galeki" in the/tmp directory.-name indicates that the file name is filtered, isn't it easy and clear? In addition to file names, find has more powerful filtering conditions:

1. Time:

Parameters Meaning
-Atime n Files last accessed less than n * 24 hours ago
-Ctime n Last file whose status changes less than n * 24 hours ago
-Mtime n Last File Modified less than n * 24 hours ago
-Newer file A new file is required than the file.

2. Size:

Parameters Meaning
-Size n [bkMG] The file size is n (B is bit, k is KB, M is MB, G is GB)

3. Owner:

Parameters Meaning
-User name File whose owner username is name
-Group name File with the name of the owner user group Group

Example:

Find/tmp/-name'Sess *'-Mtime1 # Find all files starting with 'sess' in the/tmp directory and modified within one hour
Find./-name'*. Zip'-Size 546 k # Find all the 546KB zip files in the current directory
Find/tmp/-user'Galeki' # Find all files whose owner is galeki in the/tmp directory

In addition, you can use "+" and "-" to further modify the time and size conditions:

Find src/-mtime+ 2# Find the last file modified in the src directory two days ago.
Find download/-size + 50 M # find Files larger than 50 M in the download directory

It is not enough to find the file. We need to process the file to make sense. Generally, we can pass the find search result to other commands for further processing. Find also provides many options for processing actions.

Common handling actions:

Parameters Meaning
-Print
Print out the complete address for finding the file, one line of the file
-Delete
Delete the specified file
-Exec command {}\;

Execute the command for each file found,

Replace "{}" with a file, and "\;" is a fixed Terminator.

 

Example:

Find/tmp/-ctime+ 7-Delete # delete the files created one week ago in the/tmp directory
Find./-name'*. Unk'-ExecFile{}# Find the file with the suffix unk in the current folder and use the file command to display the file type of each file

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.