Back to Snippets

Disk & File Management

Essential commands for managing disk space, finding large files, and cleaning up old data.

Caution:Commands like -delete or rm are irreversible. Always verify the file list first by running the command without the delete flag.

Top 10 Largest Files

Identifies and sorts the top 10 largest files or directories consuming disk space. Great for quick cleanup analysis.

du -ah /path/to/dir | sort -hr | head -n 10

Cleanup Old Logs

Automatically finds and deletes log files older than 30 days. Replace '/path/to/logs' and '+30' as needed.

find /path/to/logs -name "*.log" -type f -mtime +30 -delete

Find Hidden Dotfiles

Searches for hidden configuration files (like .env, .htaccess) across a directory. Useful for auditing security or finding lost configs.

find /path/to/search -type f -name ".*" -ls