Home > System Tutorial > LINUX > body text

Usage of find commandLinux

WBOY
Release: 2024-02-20 08:27:35
Original
855 people have browsed it

The find command is a powerful file search tool commonly used in Linux systems. It can search for files in a specified directory based on specified conditions and return a list of files that meet the conditions.

The basic syntax of the find command is as follows:
find [path...] [expression]

Among them, path represents the directory path to be searched, and one or more directories can be specified. expression is an expression composed of various options and test conditions, used to specify search rules and conditions.

Below I will give some commonly used find command examples to help you better understand and use this command.

  1. Search for all files in the current directory whose file names end with ".txt":
    find . -name "*.txt"
  2. In the specified directory Search for files containing specific keywords:
    find /path/to/directory -type f -name "keyword"

    -type f option means to only search for ordinary files, not Includes directories and linked files.

  3. Search for files larger than 100MB in the /home directory:
    find /home -type f -size 100M

    -size 100M option means to search for files larger than 100MB File, the unit can be k (KB), M (MB) or G (GB).

  4. Search for files whose owner is root:
    find / -user root

    -user option means to search for files with the specified owner.

  5. Search for files modified in the last 7 days:
    find /path/to/directory -type f -mtime -7

    -mtime -7 option indicates Search for files modified within the last 7 days. -mtime n means to search for files modified in the last n days, n can also be n means to search for files modified n days ago.

  6. Search for files larger than 1G and ending with ".log" in the specified directory:
    find /path/to/directory -type f -size 1G -name "*.log"
  7. Perform a search and output the results to a file:
    find /path/to/directory -type f -name "*.txt" > result.txt

    Will search The results are output to the result.txt file rather than displayed in the terminal.

These are only some usage examples of the find command. By combining different options and test conditions, you can achieve more complex and precise file search and processing operations.

Although the find command is very powerful, it can be time-consuming when searching in a large-scale directory structure. Therefore, please choose search paths and conditions carefully when using them to improve search efficiency. At the same time, it is recommended to familiarize yourself with the use of relevant options and test conditions before using the find command to avoid incorrect search results or unexpected operations.

The above is the detailed content of Usage of find commandLinux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!