The find command is used to search for files and directories on a Linux system through SSH. It allows you to locate items based on different criteria such as name, type, or size.
It is commonly used when managing website files on a server where manual navigation through directories would be inefficient.
Table of Contents
How the command works
The basic structure of the command is:
find [directory] [options]
The command searches through the specified directory and its subdirectories, returning results that match the defined conditions.
Searching by name
To find a file with a specific name:
find / -name "filename.txt"
This searches the entire system (/) for a file named filename.txt.
If you want to search within a specific directory, replace / with the relevant path.
Searching by type
You can limit results to files or directories only.
find / -type f # files only
find / -type d # directories only
Searching by size
The find command can also filter results based on file size:
find / -size +2M # files larger than 2 MB
find / -size -2M # files smaller than 2 MB
Executing actions on found files
You can run additional commands on each result returned by find.
For example, changing file permissions:
find / -name "file.txt" -exec chmod 0755 {} \;
In this case:
{}represents each file found\;marks the end of the command
Practical considerations
When using find, especially with the root directory (/), the search can take time because the system scans many folders.
To improve performance, it is recommended to narrow the search path whenever possible.
Be careful when using -exec, as it applies the action to every matching file.
Before you begin
You need SSH access enabled in your hosting account to use command-line tools.
If SSH access is not yet active, you can enable it from the mybox panel in the account settings.