find command usage and parameters

 

findCommands are a powerful tool for finding files on Linux and Unix systems. It can recursively search for qualified files in the specified directory and subdirectories, and perform some operations.

Here are findsome common uses and parameters for the command:

basic usage

Find files with a given name:

find /path/to/directory -name "filename"

This command will /path/to/directoryrecursively look for filenamefiles named in the directory.

search by type

Find files of a specified type:

find /path/to/directory -type f

This command will /path/to/directoryrecursively find all types of files in the directory (excluding directories, symbolic links, etc.).

Find directories of a specified type:

find /path/to/directory -type d

This command will /path/to/directoryrecursively find all types of directories in the directory.

Find by timestamp

Find files modified in the last N days:

find /path/to/directory -type f -mtime -N

This command will /path/to/directoryrecursively find all types of files in the directory that have been modified in the last N days.

Find files modified more than N days ago:

find /path/to/directory -type f -mtime +N

This command will /path/to/directoryrecursively find all types of files in the directory that were modified N days ago.

find by size

Find files larger than a specified size:

find /path/to/directory -type f -size +Nc

This command will /path/to/directoryrecursively search for all types of files in the directory, and the file size is greater than N bytes (bytes can be represented by c).

Find files smaller than a specified size:

find /path/to/directory -type f -size -Nc

This command will /path/to/directoryrecursively find all types of files in the directory, and the file size is less than N bytes (bytes can be represented by c).

specified operation

-execThe action to be performed can be specified via the parameter. For example, the following command will copy all found .txtfiles to another directory:

find /path/to/directory -name "*.txt" -exec cp {} /path/to/destination \;

In this command, {}it will be replaced with the file name found, which \;is a required termination symbol.

There are many other parameters that can be used, you can man findview findthe full manual of the command via command.

Qianfeng Education Java Introduction Full Set of Video Tutorials (java core technology, suitable for java zero foundation, necessary for self-study of Java)

 

Guess you like

Origin blog.csdn.net/longz_org_cn/article/details/132188886