How to choose

Before running cleanup commands, define what "large" actually means for your system. A 500 MB log file might be negligible on a 1 TB server but critical on a 20 GB partition. Start by identifying your disk pressure points using df -h to see which mount points are nearing capacity.

Next, establish a size threshold. For most general maintenance, targeting files larger than 100 MB is a safe starting point. This filters out temporary cache files and small logs while catching oversized backups, old kernels, or misplaced media files. You can adjust this threshold based on your available space.

Consider the file type as well. Not all large files are candidates for deletion. System libraries, database files, and active application data should be excluded from broad cleanup searches. Focus on temporary directories (/tmp, /var/tmp), user home directories, and old backup archives.

Once you have your criteria, use the find command with the -size flag. For example, to find files larger than 100 MB in your home directory:

Terminal showing disk usage analysis
1
Identify full partitions

Run df -h to locate partitions with high usage. Focus your search on these specific mount points to avoid wasting time on unused space.

Terminal output showing file size filtering
2
Set a size threshold

Define your cutoff. Use -size +100M to find files strictly larger than 100 megabytes. Adjust the number based on your specific storage constraints.

File type identification in Linux terminal
3
Filter by directory

Narrow the scope. Instead of scanning the entire root filesystem, target /home, /var/log, or specific application directories to reduce noise and risk.

Places to compare

When you need to reclaim disk space, the find command offers several entry points depending on whether you prioritize speed, precision, or file type. Choosing the right search criteria prevents you from scanning the entire filesystem unnecessarily. Below is a comparison of the most common approaches for locating large files.

MethodBest ForSpeedPrecision
find -sizeExact size thresholdsFastHigh
du -shDirectory size summaryModerateLow
find -mtimeRecently modified filesFastMedium
find -nameSpecific file extensionsFastHigh

The find -size option is the most direct way to target files above a specific threshold. For example, find / -type f -size +100M lists every file larger than 100 megabytes. This is ideal when you have a clear target size in mind. However, it scans every directory, which can be slow on large drives.

Using du (disk usage) provides a different perspective. While du doesn't find individual files as easily as find, it quickly shows which directories are consuming the most space. Running du -sh /* | sort -rh gives you a ranked list of top-level directories. This helps you identify the "heavy" areas before diving deeper with find.

If you are dealing with temporary files or logs that accumulate over time, combining size with modification time (-mtime) is effective. find /var/log -type f -size +50M -mtime +30 finds log files older than 30 days that are also larger than 50MB. This dual filter ensures you only remove files that are both large and stale.

Finally, targeting specific file types can save time. If you are cleaning up a development environment, you might only care about .o or .class files. find . -type f \( -name "*.o" -o -name "*.class" \) -size +10M isolates these artifacts. This approach is safer because it ignores unrelated large files like videos or backups.

More Command in Linux with Examples - Scaler Topics

Frequently Asked Questions

Check before you go

Before running any cleanup commands, verify that you have a recent backup of your system. Removing large files is irreversible, and a corrupted archive or accidental deletion of a critical system library can leave your Linux installation unbootable. A simple tar archive of essential directories or a snapshot via Btrfs/ZFS is a small price to pay for peace of mind.

Next, identify the exact files you intend to delete. Use ls -lh on the specific files to confirm their content and modification dates. Avoid using broad wildcards like *.log or *.tmp in your find command unless you are absolutely certain of their purpose. System logs and temporary files can sometimes be held open by running processes, leading to "file in use" errors or incomplete deletions.

Finally, check your disk usage with df -h and du -sh /path/to/target to establish a baseline. This helps you verify that the cleanup actually freed up space afterward. If you are targeting a specific partition, ensure you are not accidentally deleting files from a mounted external drive or network share that might be critical for other users or services.

Common questions

Can I delete files directly with find?

Yes, adding the -delete flag removes matches immediately. For example, find /tmp -type f -size +500M -delete clears old temporary files over 500MB. This is efficient but risky. Always test without -delete first to verify the list of files you intend to remove.

How do I find the largest files in a directory?

Use find with the -size option to filter by size, then sort the results. A common pattern is find /path -type f -printf '%s %p\n' | sort -nr | head -10. This outputs the file size and path, sorted from largest to smallest, helping you identify the biggest space hogs quickly.

Is find better than du for cleanup?

du shows directory usage, while find locates specific files. Use du to find which folder is consuming space, then use find inside that folder to locate and delete the large files. Combining both tools gives you a complete picture of where to clean up.

What if I want to delete old large files?

Combine size and time filters. For instance, find /var -type f -size +100M -mtime +30 -delete removes files larger than 100MB that haven't been modified in 30 days. This helps archive or remove stale data that is no longer needed but takes up significant space.

Map

linux find command examples