search
Homephp教程PHP开发How to use the find command skillfully in Linux

We all know that the command to find files under Linux is the find command. Using this command, you can quickly search for the files you want. So what are the tips for using the find command? The editor below will introduce to you the clever use of the find command in Linux.

The find command works by traversing down the file hierarchy, matching files that meet the criteria, and performing the appropriate operations.

 1. Search based on file name or regular expression matching

 The parameter of option -name specifies the string that the file name must match. We can use wildcards as parameters. "*.txt" matches all strings ending with .txt file name.

 The code is as follows:

 [root@localhost test]# touch {data, log, file, File, LOG}_{1, 2, 3, 4, 5, 6}_{.txt, .pdf, .log ,.conf}

 [root@localhost test]# find. -name “*.txt” –print

 If you want to match one of multiple conditions, you can use the -o parameter.

 The code is as follows:

 [root@localhost test]# find. (-name “*.txt” -o -name “*.log” )

 Option-iname ignores letter case

 Option-path parameter can use wildcards to match file paths or files.

 2. Negate parameters

  Find uses "!" to negate parameters and match all file names that do not end with .txt.

 The code is as follows:

 [root@localhost test]# find. ! -name “*.txt” –print

 3. Search based on directory depth

  When the find command is used, it will traverse all subdirectories. We can use -maxdepth and -mindepth to limit the depth of the find command traversal.

  -maxdepth: Specify the maximum depth;

  -mindepth: Specify the minimum depth.

 The code is as follows:

 [root@localhost ~]# find. -maxdepth 1 -type f

  List all ordinary files in the current directory. These two commands should follow the target path.

 4. Search based on file type

 The code is as follows:

 find. –type d –print

How to use the find command skillfully in Linux

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.