
-
Website Maintenance: If your website files are stored in /usr/share, and you need to list all image files (e.g., with a .jpg extension), you can run:
-
Disk Space Management: When hosting virtual machines, you might encounter low disk space situations. Since most VM files are usually under 20 GB, filtering out unusually large files is critical. For example, to find files larger than 10 megabytes, execute:
-
Monitoring File Changes: After deploying an application, you may want to verify which files have been modified recently. To list files modified within the last minute, use the mmin parameter:
Find Command Syntax
The basic syntax for the find command is:If no directory is specified, remember that find will perform a recursive search starting in the current directory.
Common Search Parameters
Name and Wildcards
The -name option allows you to search for files by their name. Note that this search is case sensitive:Time-Based Searches
The -mmin option lets you find files based on their modification time in minutes. For example, to list files modified exactly 5 minutes ago:- -mtime 0 returns files modified within the past 24 hours.
- -mtime 1 returns files modified between 24 and 48 hours ago.
-
To find files modified between 48 and 72 hours ago, you would use:
Size-Based Searches
The -size parameter allows searching for files based on file size. For example, to find files that are exactly 512 kilobytes in size:| Size Suffix | Unit |
|---|---|
| C | Bytes |
| K | Kilobytes |
| M | Megabytes |
| G | Gigabytes |
Combining Search Parameters
Multiple search conditions can be combined to refine your results. For example, to search for files that start with the letter “f” and are exactly 512K in size:Permission-Based Searches
The -perm option finds files based on their permission settings. Here are several examples:-
Exact permissions: To search for files with precisely 664 permissions (read and write permissions for the user and group; read permission for others):
-
At least these permissions: To find files having at least these permissions, prefix the mode with a hyphen:
-
Any of the specified permissions: To search for files where any one of the specified permissions is present, use a slash:
-
To find files that only the owner can read and write:
-
To find files that the owner can execute (regardless of additional permissions):
-
To ensure that others do not have read permission, combine conditions with the NOT operator: