Support > About cloud server > Japanese cloud server security operation and maintenance: three practical methods to replace the Linux rm command
Japanese cloud server security operation and maintenance: three practical methods to replace the Linux rm command
Time : 2025-08-12 14:02:23
Edit : Jtti

Deleting files is a common operation in cloud server maintenance. The rm command is widely used in Linux to delete files and directories. However, improper use of the rm command can easily lead to the accidental deletion of important files and data loss. Below are some common, safer, and more reliable alternatives to the rm command to help improve security and avoid the risks of accidental deletion.

First, the most direct and simple method is to use the trash-cli tool. It works similarly to the "Recycle Bin" in desktop operating systems. When you delete a file, the file is not physically deleted immediately but moved to a Recycle Bin directory. This allows for easy recovery even if the file is accidentally deleted. Installing trash-cli is very convenient:

sudo apt-get install trash-cli

Usage is also simple: simply replace rm with trash:

trash filename

Compared to the traditional rm command, this method offers a chance to recover files after accidental deletion, making it particularly suitable for users who prioritize data security but prefer a more user-friendly approach. File recovery can be achieved with:

trash-restore

This tool lists deleted files and allows users to restore them.

Secondly, a common practice in operations and maintenance is to limit the destructive power of the rm command by setting an alias. The most common approach is to configure the rm command in interactive mode in your bash configuration file (such as ~/.bashrc):

alias rm='rm -i'

This way, whenever you perform a deletion, the system will prompt you to confirm the deletion, preventing inadvertent file deletion. This method requires no additional tools, is simple to use, and effectively reduces accidental deletions. After configuring, run:

source ~/.bashrc

for the changes to take effect. While this method doesn't completely prevent accidental deletions, it adds a second step of confirmation, making it a low-cost security improvement for daily operations and maintenance.

A third approach is to utilize time-based version control and snapshot mechanisms, such as rsnapshot or the snapshot functionality provided by cloud servers. While this isn't a direct replacement for the rm command, regular snapshots and backups allow for quick recovery from accidental file deletions, fundamentally addressing data loss. Take rsnapshot, for example. It uses hard links and incremental backups for efficient file backups:

Installation:

sudo apt-get install rsnapshot

The configuration file is typically located in /etc/rsnapshot.conf , where you can set the backup cycle and path as needed. To start a backup:

sudo rsnapshot daily

If you accidentally delete a file, you can simply restore it from the backup directory, making it virtually painless. Furthermore, most cloud servers, such as Jtti Cloud support snapshots, allowing data to be restored in minutes, greatly enhancing data security.

Each of these three methods has its advantages. trash-cli is suitable for operators who want to retain the ability to recover after deletion; setting up an rm -i alias adds a confirmation step to daily operations, reducing the risk of accidental deletions; and version control and snapshots provide the most comprehensive protection, making them suitable for enterprise environments with strict data protection requirements. Combined, they can create a more secure and reliable deletion process for cloud server operations.

Of course, in addition to tools and command substitution, good operational practices are equally important. For example, avoid using the root account to directly manipulate files in production environments; carefully confirm paths and file names before deleting; develop a habit of regular backups; and even write scripts to log deletion operations for easier tracking and auditing.

Although the Linux rm command is powerful, the risk of misuse should not be ignored. Multiple measures, such as the trash-cli recycling mechanism, the rm -i interactive mode, and snapshot backups, can significantly improve the security of deletion operations. Combined with standardized operational procedures and permission management, this can minimize business interruptions and data loss caused by accidental deletion.

Relevant contents

Southeast Asian e-commerce: Which is better, Singapore VPS or Malaysia VPS? How to optimize the high latency when accessing US VPS from mainland China Which is more suitable for mainland China access, Japan VPS server or Hong Kong VPS What are the reasons why Singapore cloud servers are prone to freezing? CentOS Japan Cloud Server Permanently Mount NTFS Partition Practical Tutorial Why do professional players recommend Hong Kong cloud servers? Minecraft server one-click deployment tutorial Hong Kong VPS Server Data Loss Emergency Guide Analysis of the characteristics and uses of large-capacity hard drive vps dynamic cloud server Is Japan's CN2 VPS suitable for running idle scripts? An in-depth analysis of bandwidth and stability Save 50% in three years! 5 bargaining tips for long-term cloud server storage leases
Go back

24/7/365 support.We work when you work

Support