0

When it comes to removing files. Instead of

rm some_file.txt

or

rm -rf some_folder

we do

del some_file.txt

or

del some_folder

where you can define your bash alias for del in ~/.custom_aliases as

function del() {
    mv $* ~/.Trash
}

which just moves your files and folders to the trash such that you can recover them later.

What’s your choice?

pLumo
  • 27,991

2 Answers2

1

You're on a good path if you want to learn how to solve this problem yourself. However, this is a common problem, and there is already a tool available.

You can install trash via apt install trash-cli. Once installed, you can 'safely' delete files, list the contents of Trash, restore files and empty the Trash:

  1. trash /path/to/some/file
  2. trash-list
  3. trash-restore
  4. trash-empty.

You can read more about trash.


Notes:

  1. Some systems will have restore-trash instead of trash-restore.
  2. Many Debian distributions have gvfs-trash from gvfs-bin installed by default.
  3. gvfs-trash has been replaced by gio trash.
earthmeLon
  • 11,658
0

Wellcome! You can recover the data almost always (forensic methods). But moving to the trash bin is the fastest and clearest method.