The Folder Search
When organizing an Ubuntu Linux server, the find command is the most powerful tool available. By default, if you simply type find /var/www/ -name "backup", the search engine will return everything it finds: it will list text files named “backup.txt”, bash scripts named “backup.sh”, and the actual folders named “backup.” If you are strictly looking for a directory and want to completely filter out the thousands of individual files cluttering the output, you must explicitly declare the “type” of data you are looking for.
Using the find Command with -type d
The Linux find command utilizes the -type d (Directory) flag to force the engine to completely ignore standard files, symlinks, and sockets.
- Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
- To search the entire
/var/www/directory for a specific folder named exactly “images”, type the following command: sudo find /var/www/ -type d -name "images"- Press Enter and provide your administrator password.
The Power of Exclusion
This flag is incredibly powerful when combined with other parameters. For example, if you want to find all empty folders on your system so you can delete them, you don’t want the command to return empty text files. By combining the directory flag with the empty flag (sudo find /home/user/ -type d -empty), the terminal will instantly output a highly filtered, accurate list of only the abandoned folders, completely ignoring the thousands of zero-byte log files scattered across the system.