*Cube-Host– full cloud services!!
The find command is one of the most useful Linux tools for VPS administration: it helps you locate files by name, size, time, owner, permissions, and even content—then perform safe actions (move, chmod, archive, delete) on the results.
If you manage a website, mail server, or any application on a Linux VPS, mastering find will save you hours during incidents: “Where did the disk space go?”, “Which files changed last night?”, “Which folders have unsafe permissions?”
Many “search” tasks are solved faster with the right command:
| Tool | Best for | Key detail |
|---|---|---|
| find | Precise file search + actions (delete/move/chmod) | Walks directories in real time |
| locate | Instant filename search | Uses an index (may be outdated) |
| grep | Search inside files by content | Often paired with find (-exec grep) |
find <where-to-look> <tests-and-actions>
Where to look is a directory path. Use . for the current directory. Tests decide what matches (name, type, time, owner, permissions). Actions decide what to do with matches (print, exec, delete).
Important behavior: find evaluates from left to right. When you combine conditions with AND/OR, use parentheses (escaped in shell) to avoid surprises.
# Example: (A OR B) AND type file
find . \( -name "*.log" -o -name "*.txt" \) -type f
# Exact name
find /var/www -name "wp-config.php"
# Pattern (all .tmp files)
find / -name "*.tmp"
# Case-insensitive
find /home -iname "*.JPG"
Tip: always quote patterns like "*.tmp" so your shell doesn’t expand them too early.
# Files only
find . -type f
# Directories only
find . -type d
# Symlinks
find /etc -type l
# Files larger than 1 GB
find / -type f -size +1G
# Files smaller than 10 KB
find /var/www -type f -size -10k
On production servers, avoid scanning the entire filesystem unless needed. Start with likely hotspots: /var/log, /var/lib, /home, /tmp, and your project directory.
Time flags are extremely useful for incident response and cleanup:
# Files modified more than 60 days ago
find /var/log -type f -mtime +60
# Files modified in the last 30 minutes
find /var/www -type f -mmin -30
# Files modified between 10 and 20 minutes ago
find /var/www -type f -mmin +10 -mmin -20
Tip: -mtime is in days. -mmin is in minutes. For suspicious activity on a VPS, -mmin is often more practical.
# Files owned by a user
find /var/www -type f -user www-data
# Files owned by a group
find /var/www -type f -group www-data
These checks are common during Linux security reviews:
# World-writable files (potential risk)
find /var/www -type f -perm -0002
# Directories with 777 (almost always a mistake)
find /var/www -type d -perm 0777
# Files readable/writable by everyone
find / -type f -perm 0666
If you run business services (WordPress, mail server, dashboards) on a VPS, permission hygiene is part of basic security hardening.
To search inside files, combine find with grep. This is common when hunting secrets, config flags, or suspicious injections.
# Search for a string inside all .conf files
find /etc -type f -name "*.conf" -exec grep -Hn "listen" {} \;
# Case-insensitive search inside PHP files (project folder)
find /var/www/project -type f -name "*.php" -exec grep -Hin "base64_decode" {} \;
-maxdepth and -mindepth.-xdev.-prune (great for node_modules, cache, backups).# Exclude node_modules and vendor directories
find /var/www/project \
\( -path "*/node_modules/*" -o -path "*/vendor/*" \) -prune -o \
-type f -name "*.log" -print
The most powerful part of find is automation. But with great power comes “oops, I deleted production”. Use a safe workflow:
-print first and review output.-ok) or log results.-delete for safe, well-tested patterns.# SAFE: show what would be removed first
find /tmp -type f -mtime +14 -print
# Semi-safe: ask before executing
find /tmp -type f -mtime +14 -ok rm -f {} \;
# Fast but risky: delete immediately (use only when confident)
find /tmp -type f -mtime +14 -delete
Pro tip: prefer -exec ... {} + (plus) when possible—it’s more efficient than running a command once per file.
A classic VPS task: keep temporary folders from growing forever. Schedule a nightly cleanup:
crontab -e
# Remove files older than 14 days from /tmp daily at 00:00
0 0 * * * /usr/bin/find /tmp -type f -mtime +14 -delete
Use the full path to find (check with which find) and always start with a -print dry run on a test folder.
*.log: your shell expands it incorrectly. Fix: use "*.log".-print first.-mtime is days, not hours. Fix: use -mmin for short windows.\( ... \).On a Linux VPS, find is a daily driver: investigate disk usage, clean old files, locate configs, and perform security checks. Combined with monitoring tools (like Zabbix), it becomes an incident response toolkit you can trust.