Home > php教程 > PHP开发 > body text

How to use the find command skillfully in Linux

高洛峰
Release: 2016-12-14 17:20:53
Original
1310 people have browsed it

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

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template