A friendly alternative to finding tools in Linux

  • 2020-12-07 04:38:43
  • OfStack

The find command is used to find files in the specified directory. Any string that precedes the parameter is treated as the name of the directory you are looking for. If you use this command without setting any parameters, the find command looks for subdirectories and files in the current directory. And will find the subdirectories and files are all displayed.

grammar

find(选项)(参数)

options

-amin < minutes > : Search in minutes for files or directories that have been accessed at a specified time; -anewer < Refer to a file or directory > : Finds that its access time is closer to the current file or directory than the specified file or directory; -atime < 24 hours > : Search for files or directories that have been accessed at a specified time in 24 hours; -cmin < minutes > : Find files or directories that have been changed at the specified time; -cnewer < Refer to a file or directory > Finds that its change time is closer to the current file or directory than the change time of the specified file or directory; -ctime < 24 hours > : Search for files or directories that have been changed at a specified time in 24 hours; -ES29en: The time shall be calculated from this day; -ES30en: Start lookup from the deepest subdirectory under the specified directory; -ES31en: Look for files with file size 0 Byte, or empty directories without any subdirectories or files; -exec < An instruction to > : Suppose the return value of the find instruction is True, then the instruction is executed; -ES38en: Set the return value of the find instruction to False; -fls < A list of files > : The effect of this parameter is similar to that of the specified "-ls" parameter, but the result is saved as a specified list file; -ES45en: Exclude symbolic links; -fprint < A list of files > : The effect of this parameter is similar to that of the specified "-print" parameter, but the result is saved as a specified list file; -fprint0 < A list of files > : The effect of this parameter is similar to that of the specified "-print0" parameter, but the result is saved as a specified list file; -fprintf < A list of files > < The output format > : The effect of this parameter is similar to that of the specified "-printf" parameter, but the result is saved as a specified list file; -fstype < File system type > : Only look for files or directories under the file system type; -gid < Group identification code > : Finds a file or directory that matches the specified group identifier; -group < The name of the group > : Finds a file or directory that matches the specified group name; -ES69en or -ES70en: Online help; -ilname < Sample style > : The effect of this parameter is similar to that of specifying the "-ES74en" parameter, but the difference in character case is ignored; -iname < Sample style > : The effect of this parameter is similar to that of specifying the "-name" parameter, but the difference in character case is ignored; -inum < inode number > : Find a file or directory that matches the specified inode number; -ipath < Sample style > : The effect of this parameter is similar to that of specifying the "-path" parameter, but the character case difference is ignored; -iregex < Sample style > : The effect of this parameter is similar to that of specifying the "-ES91en" parameter, but the difference in character case is ignored; -links < Connection number > : Finds files or directories that match the specified number of hard connections; -iname < Sample style > : Specifies a string as a template style to look for symbolic connections; -ES98en: The file or directory name is listed to standard output, assuming that the return value of the find directive is Ture; -maxdepth < Directory hierarchy > : Set the maximum directory level; -mindepth < Directory hierarchy > : Set the minimum directory level; -mmin < minutes > : Find files or directories that have been changed at a specified time in minutes; -ES110en: This parameter has the same effect as specifying "-ES111en"; -mtime < 24 hours > : Search for files or directories that have been changed at a specified time in 24 hours; -name < Sample style > : Specifies a string as a template style to find a file or directory; -newer < Refer to a file or directory > : Find that the change time of the specified file or directory is closer to the current file or directory; -ES121en: Find files or directories that do not belong to the localhost group identification code; -ES122en: Regardless of the fact that the directory must have at least two hard connections; -ES123en: Find a file or directory that does not belong to the localhost user id; -ok < An instruction to > : The effect of this parameter is similar to that of specifying "-ES127en", but the user is asked before the instruction is executed. If the user answers "y" or "Y", the execution command is abandoned; -path < Sample style > : Specifies a string as a template style to find a directory; -perm < Permissions numerical > : Finds a file or directory that matches the specified permission value; -ES136en: The file or directory name is listed to standard output, assuming the return value of the find directive is Ture. The format is 1 name for each column, preceded by a./. String; -print0: The file or directory name is listed to standard output, assuming the return value of the find directive is Ture. All names in format are on the same line; -printf < The output format > : The file or directory name is listed to standard output, assuming the return value of the find directive is Ture. The format can be specified by itself; -ES147en: Does not look for strings as template styles for looking for files or directories; -regex < Sample style > : Specifies a string as a template style to find a file or directory; -size < The file size > : Finds files that match the specified file size; -true: Set the return value of find instruction to True; -typ < The file type > : Only look for files that match the specified file type; -uid < User identification code > : Finds a file or directory that matches the specified user id; -used < days > : Find the file or directory that has been accessed at a specified time since the file or directory was changed, on a daily basis; -user < Owner name > : File or directory with the finder and specified owner name; -ES169en or -- version: Display version information; -ES171en: Limit the scope to the file system in the previous row; -xtype < The file type > : This parameter has the same effect as specifying the "-ES175en" parameter, except that it checks for symbolic connections.

parameter

Start directory: Find the start directory of the file.

FD

fd is a super fast, Unix/Linux find command based on Rust. It doesn't offer all the power of find. However, it does provide enough functionality to cover 80 percent of the situations you might encounter. Features such as good planning and easy syntax, color output, smart capitalization, regular expressions, and parallel command execution make fd a very capable successor.

The installation

Go to the fd GitHub page to see the installation section. It covers how to install programs on macOS, Debian/Ubuntu Red Hat and Arch Linux. Once the installation is complete, you can run help for a complete overview of all available command line options, get succinct help from ES207en-ES208en, or get more detailed help from fd --help.

Simple search

fd is designed to help you easily find files and folders in your file system. You can perform the simplest search using fd with an argument that is whatever you are searching for. For example, suppose you want to find an Markdown document that contains the word services as part 1 of the file name:


$ fd services
downloads/services.md

If called with only 1 argument, fd recursively searches the current directory to find any files and/or directories that match the parameters of the mo. An equivalent search using the built-in find command would look like this:


$ find . -name 'services'
downloads/services.md

As you can see, fd is much simpler and requires less input. It is always right to do more with less input in my mind.

Files and folders

You can use the -t parameter to limit the search to files or directories, followed by letters that represent what you are searching for. For example, to find all files in the current directory that contain services in the file name, you can use:


$ fd -tf services
downloads/services.md

Also, find all directories with services in the file name of the current directory:


$ fd -td services
applications/services
library/services

How do I list all documents with the.md extension in the current folder?


$ fd .md
administration/administration.md
development/elixir/elixir_install.md
readme.md
sidebar.md
linux.md

As you can see from the output, fd can not only find and list the files in the current folder, but also find the files in the subfolders. Very simple.

You can even use the -H parameter to search for hidden files:


fd -H sessions .
.bash_sessions

The specified directory

If you want to search for a specific directory, the name of the directory can be passed to fd as a second parameter:


$ fd passwd /etc
/etc/default/passwd
/etc/pam.d/passwd
/etc/passwd

In this example, we tell fd that we want to search the etc directory for all instances of the word passwd.

Global search

What if you know part 1 of a file name but don't know the folder? Suppose you have downloaded a book on Linux network management, but you don't know where it is saved. No problem:


fd Administration /
/Users/pmullins/Documents/Books/Linux/Mastering Linux Network Administration.epub

fd is an excellent alternative to the find command, and I'm sure you'll find it as useful as I do. To learn more about this command, just browse the man page.

conclusion


Related articles: