Locating files and directories efficiently in Linux prevents wasted time navigating complex directory trees and reduces the risk of missing important configuration files, logs, or documents. Consistent search techniques also help when troubleshooting or cleaning up disk space across large or unfamiliar systems.
The find command walks a directory tree in real time, matching paths based on criteria such as name, type, size, and modification time. Because it inspects the live filesystem, it sees newly created or deleted files immediately and can restrict searches to a specific subtree, which improves performance and reduces noise.
The locate command searches an indexed database of paths generated by updatedb, returning results much faster than a full filesystem scan. This index can lag behind the actual filesystem, so some very new or removed files may not appear or may still show up in results. Running broad searches from the filesystem root can be resource intensive, so targeting specific top-level directories and refreshing the locate database when needed keeps searches fast and reliable.
Steps to find files and folders in Linux:
- Open a terminal with an account that has access to the directories that need to be searched.
$ whoami alex - Search for a regular file by exact name inside a directory tree using find.
$ find /home -type f -name "report.pdf" /home/alex/Documents/report.pdf
The -type f filter restricts matches to regular files and avoids listing directories or special files.
- Search for directories (folders) by name using find with a directory type filter.
$ find /srv -type d -name "logs" /srv/app/logs /srv/legacy/logs
The -type d filter restricts matches to directories, which is useful when looking for application or backup folders.
- Search for files by filename pattern, such as a specific extension, using shell globbing.
$ find /var/log -type f -name "*.log" /var/log/auth.log /var/log/syslog /var/log/nginx/access.log
Quoting the pattern ("*.log") prevents the shell from expanding the wildcard before find runs.
- Find large files that may be consuming disk space by filtering on size.
$ find /var -type f -size +100M /var/lib/libvirt/images/vm1.qcow2 /var/backups/system-2024-10-01.tar.gz
The +100M threshold matches files larger than 100 megabytes; use -100M to match smaller files instead.
- Find recently modified files to identify recent changes or troubleshoot issues.
$ find /etc -type f -mtime -2 /etc/ssh/sshd_config /etc/nginx/nginx.conf
The -mtime -2 filter matches files modified in the last two days; use +N to find files older than N days.
- Suppress permission error messages when scanning large directory trees that include restricted paths.
$ find / -type f -name "config.yaml" 2>/dev/null /home/alex/projects/api/config.yaml /etc/myapp/config.yaml
Redirecting errors hides Permission denied messages but may also hide other important warnings; review search scope before scanning from the filesystem root.
- Refresh the locate database to speed up subsequent searches using the prebuilt index.
$ sudo updatedb
Rebuilding the index can generate noticeable disk I/O on large systems; schedule updates during low-traffic periods on production servers.
- Search for files by name using locate for a fast indexed lookup.
$ locate report.pdf /home/alex/Documents/report.pdf /home/alex/Archive/2023/report.pdf
locate returns all matching paths from its database and may list files that have been moved or deleted if the index has not been refreshed recently.
- Use case-insensitive matching with locate when the exact capitalization of the filename is unknown.
$ locate -i "report" /home/alex/Documents/report.pdf /home/alex/Documents/Report-2023.xlsx /home/alex/Docs/REPORT-notes.txt
The -i option ignores case in the search term, which is useful on filesystems where names differ only by capitalization.
- Verify a located path by listing it with ls to confirm that the file still exists and is accessible.
$ ls -l /home/alex/Documents/report.pdf -rw-r--r-- 1 alex alex 24576 Oct 2 10:42 /home/alex/Documents/report.pdf
Checking file metadata (owner, size, and date) confirms that the result matches the intended file before further actions such as editing or deletion.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
