< Linux > A Safe Way to Use Deletion Command In Linux.

What is saferm?

A safe deletion script to prevent you from wrongly deleting important files in your Linux system.

How it works?

Everytime when you delete a file, it actually move the file to a hidden folder named .saferm_xxx_yyy in the same location where xxx means the timestamp when you delete, yyy is a random number.

This hidden folder will keep for some time(which is depended on your appointment) before it is truly deleted. So you can restore your deleted files within the keeping time of the file.

How to use it?

After you clone this project, there are two ways to use it:

First way(If you are a root user)

To put this two scripts in your /usr/bin/ folder, then to alias rm=’saferm’ to use it.

Second way

To put the two scripts in wherever you want, then to add the path to your PATH system environment in your .bashrc file. Finally to alias rm=’saferm’ to use it.

The useful command

To delete a file.

1
rm xxx

The file xxx will keep for a relatively long time(which is depended on your appointment) .

To delete a file right now.

1
rm -now yyy

The file yyy will keep in a relatively short time(Which depends on your appointment).

For safety concerns, to use * to delete is restricted. If you want to use ‘rm * ‘ to delete everything in your folder, you can use the following command.

1
rm -all *

Personal Customization

You can decide how long you want to the deleted file to be kept. You can edit the ‘saferm’ file, then modify the ‘KEEP_TIME_LONG’ variable to the time(by second) you want to set.
If you want to delete the file right now, you can set the variable ‘KEEP_TIME_INSTANT’ in the script ‘saferm’ to determine the short time you want to keep.

Check the deletion history

A ‘.my_deletion.txt’ text will be established once you firstly use saferm. And the location of the text is in your home directory, so you can locate this text by ‘ls ~/.my_deletion.txt’.

Everytime when you delete a file, a recored would be written in this text. And once that file is finally being deleted, the corresponded history will be removed also.

Source Code

Github

< Linux > A Safe Way to Use Deletion Command In Linux.

https://zhengtq.github.io/2019/10/19/saferm/

Author

Billy

Posted on

2019-10-19

Updated on

2021-03-12

Licensed under

Comments