Useful Linux find Command Examples
The find command in Ubuntu is a versatile tool for searching files and directories based on various criteria such as name, size, type, and modification time. It allows users to perform complex queries, execute actions on matched files, and integrate with other commands to streamline file management tasks.
find Command Examples
Finding All .log Files in the Home Directory
This command searches recursively in the home directory for files ending with .log.
find ~/ -name "*.log"
Finding All Empty Directories
This finds all empty directories under a given path.
find /path/to/search -type d -empty
Finding Files Modified in the Last 24 Hours
Use this to locate files modified in the last 24 hours.
find /path/to/search -mtime -1
Finding Files Larger Than 500 MB and Deleting Them
This finds files larger than 500 MB and removes them.
⚠️ Caution: Use this command carefully; it will permanently delete files.
find /path/to/search -size +500M -exec rm {} \;
Finding Files Owned by a Specific User and Changing Their Permissions
This locates files owned by a user and sets their permissions to 644.
find /path/to/search -user username -exec chmod 644 {} \;
Advanced find Command Examples
Finding Files Accessed in the Last 7 Days
find /path/to/search -atime -7
This lists files accessed in the last 7 days.
Finding Files with Specific Permissions (e.g., 777)
find /path/to/search -perm 0777
Finds all files or directories with 777 permissions.
Finding and Archiving Files Modified in the Last 3 Days
find /path/to/search -mtime -3 -type f -print | tar -czf recent-files.tar.gz -T -
This command archives all files modified in the last 3 days into a .tar.gz file.
Finding Symbolic Links in a Directory
find /path/to/search -type l
Lists all symbolic (soft) links.
Excluding a Directory from Search
find /path/to/search -path /path/to/search/exclude-dir -prune -o -name "*.txt" -print
This excludes a specific directory from the search results while finding .txt files.
Tips to Use find Effectively
- Combine with
grepto filter content inside found files. - Use
-execto apply commands likemv,chmod,chown,rm, or custom scripts. - Use
xargsfor better performance with many files. - Use
-inamefor case-insensitive search.
Recommended Reading
If you found this guide helpful, you may also want to check out these related Linux solutions:
- Find the Largest Files and Folders on Linux
Learn how to identify and analyze large files or directories taking up disk space on your system. - List and Delete Log Data Older Than 30 Days
A practical solution to automatically clean up old log files and manage disk usage effectively.












