SSH command – find

On this page
  1. How the command works
  2. Searching by name
  3. Searching by type
  4. Searching by size
  5. Executing actions on found files
  6. Practical considerations
  7. Before you begin

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.

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.

Didn't find an answer?

Our support team is here for you 24/7 – write to us and we will help you sort it out.