1. Locating Files with find
# Search every directory for a file called nginx.conf
find / -type f -name nginx.conf
# Limit the search to /etc for faster results
find /etc -type f -name nginx.conf
# Wildcards: list every .conf file under /etc
find /etc -type f -name "*.conf"
# Combine wildcard and prefix
find /etc -type f -name "nginx*"
2. Touching and Backdating Files
# Display full metadata
stat /opt/demo.cfg
# Create or update mtime to a specific date
touch -m -d "2021-08-02 09:00" /opt/report.txt
3. Filtering by Modification Age
# Files modified more than 3 days ago
find /opt -type f -name "*.log" -mtime +3
# Files modified within the last 24 hours
find /opt -type f -mtime -1
4. Deleting Old Logs Safely
# Dry-run first
find /var/log -type f -name "*.log" -mtime +10
# Execute deletion
find /var/log -type f -name "*.log" -mtime +10 -exec rm -f {} \;
5. Generating Dummy Files of Abritrary Size
# 1 MiB file
dd if=/dev/zero of=dummy_1M.img bs=1M count=1
# 100 MiB file
dd if=/dev/zero of=dummy_100M.img bs=1M count=100
# Verify
ls -lh dummy_*
6. Finding by Size
# Exact match
find . -type f -size 5M
# Greater than 5 MiB
find . -type f -size +5M
# Less than 1 MiB
find . -type f -size -1M
# System-wide hunt for giants
find / -xdev -type f -size +100M 2>/dev/null
7. Visualising Directory Trees with tree
# Install once
yum install -y tree
# Show /var/log hierarchy
tree /var/log
8. Cloning a Virtual Machine
- Power off the source VM.
- Right-click → Clone → Full clone.
- Boot the clone and assign a unique hostname/IP.
9. Remote Copy with scp
Download
# Copy single file
scp user@192.168.1.10:/opt/data.csv /opt/
# Recursive directory
scp -r user@192.168.1.10:/opt/project /opt/
Upload
# File
scp /opt/report.txt user@192.168.1.10:/opt/
# Directory
scp -r /opt/folder user@192.168.1.10:/opt/
Ensure sshd is active:
systemctl enable --now sshd
10. Automated Backups via cron
# Discover full path to tar
which tar # → /usr/bin/tar
# Edit crontab
crontab -e
# Every day at 03:15, create a timestamped archive
15 3 * * * /usr/bin/tar -czf /backup/etc-$(date '+\%Y\%m\%d\%H\%M\%S').tar.gz /etc
# List current jobs
crontab -l
11. Date Formating Quick Reference
date '+%F %T' # 2024-07-15 14:30:00
date '+%Y%m%d%H%M%S' # 20240715143000