• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

Linux Deletion Command Usage Guide

July 14, 2025

Streamlined Guide to File Deletion in Linux

File deletion is a critical task in Linux system management, particularly for Hong Kong Server and Hong Kong VPS environments. Effective deletion methods optimize storage and ensure compliance with data protection laws like CCPA and HIPAA. This guide provides concise, practical instructions for technicians.

1. Core Deletion Commands

rm Command

  • Delete a file: rm filename.txt

  • Delete multiple files: rm file1.jpg file2.png

  • Force delete (no prompt): rm -f report.log
    Caution: Verify file paths to avoid accidental data loss on production servers.

unlink Command

  • Delete a single file: unlink data.csv
    Note: Primarily used in scripts; rm is more common.

2. Directory Deletion

  • Delete empty directory: rmdir empty_folder

  • Delete non-empty directory: rm -r project_files

  • Force delete directory: rm -rf node_modules
    Warning: Use rm -rf cautiously, as it can cause irreversible data loss.

3. Safe Deletion Options

  • Interactive deletion: rm -i *.tmp (prompts for confirmation)

  • Verbose mode: rm -v old_*.log (shows deletion details)

4. Wildcard Batch Deletion

  • Delete all .log files: rm *.log

  • Delete files with prefix: rm backup_2023*

  • Delete specific extension: rm -i *.jpg
    Tip: Verify wildcard patterns to prevent unintended deletions.

5. Find and Delete

  • Delete logs older than 30 days: find /var/log -name “*.log” -mtime +30 -exec rm {} \;

  • Delete empty files: find . -type f -empty -delete

  • Delete files >100MB: find /tmp -size +100M -exec rm {} \;
    Benefit: Ideal for managing storage on resource-constrained servers.

6. Secure Deletion Tools

shred

  • Securely delete with overwrite: shred -n 3 -z -u secret.doc
    Use case: Ensures compliance with data protection regulations.

wipe

  • Install: sudo apt install wipe

  • Erase file: wipe confidential.pdf
    Use case: Suitable for sensitive data erasure.

7. Recycle Bin Mechanism

trash-cli

  • Install: sudo apt install trash-cli

  • Move to recycle bin: trash-put document.odt

  • List contents: trash-list

  • Restore: trash-restore
    Advantage: Provides a safety net for accidental deletions.

8. Handling Permissions and Special Files

  • Delete read-only files: rm -f read-only.file

  • Delete hidden files: rm .hiddenfile

  • Delete hidden directories: rm -r .config_backup

  • Delete system files: sudo rm /var/cache/apt/archives/*.deb
    Caution: Avoid deleting critical system files to prevent service disruptions.

9. Common Deletion Errors

Error

Cause

Solution

Permission denied

Insufficient permissions

Use sudo or chmod

Device or resource busy

File in use

Use lsof to identify and terminate processes

Argument list too long

Too many files

Use find for batch deletion

10. Data Recovery

  • Install recovery tool: sudo apt install extundelete

  • Recover files: extundelete /dev/sda1 –restore-directory /home/user/docs
    Recommendation: Regular backups are essential to minimize data loss risks.

11. Best Practices

  • Backup before deletion: cp file.txt file.txt.bak

  • Use interactive alias: alias rm=’rm -i’

  • Move files before deletion: mv sensitive_data /tmp && rm -rf /tmp/sensitive_data

  • Test patterns: ls | grep “*.tmp”

  • Prefer trash-cli for critical data.

12. Dangerous Commands to Avoid

  • rm -rf / (destroys system)

  • rm -rf ./* (deletes all in current directory)
    Warning: Never execute these on any server.

Recent Posts

  • Hong Kong VPS PostgreSQL Setup: High-Performance Database Configuration for Asia-Pacific (2026)
  • Hong Kong VPS for Live Streaming: RTMP Server Setup and Low-Latency Delivery to China (2026)
  • How to Set Up a Mail Server on Hong Kong VPS: Postfix, Dovecot, and Email Deliverability (2026)
  • How to Run a SaaS Product on Hong Kong VPS: Architecture and Deployment Guide 2026
  • Hong Kong VPS Uptime and SLA: What 99.9% Uptime Really Means for Your Business (2026)

Recent Comments

  1. Hong Kong VPS Uptime and SLA: What 99.9% Uptime Really Means for Your Business (2026) - Server.HK on How to Monitor Your Hong Kong VPS: Uptime, Performance, and Alert Setup Guide (2026)
  2. Best Hong Kong VPS Providers in 2026: Compared by Speed, Routing, and Value - Server.HK on How to Migrate Your Website to a Hong Kong VPS: Zero-Downtime Transfer Guide (2026)
  3. vibramycin injection on How to Choose the Right Hong Kong VPS Plan: A Buyer’s Guide for 2026
  4. allopurinol for gout on CN2 GIA vs BGP vs CN2 GT: What’s the Real Difference for China Connectivity?
  5. antibiotics online purchase on How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot