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
  • 26,947
  • Your function will fail when ~/.Trash is missing. Add mkdir -p ~ /.Trash and use "$@" instead of unqoted $*. – pLumo May 28 '19 at 14:54
  • You should probably use https://askubuntu.com/questions/213533/command-to-move-a-file-to-trash-via-terminal to use the "real" Trash mechanism instead of maintaining your own temporary folders. – Byte Commander May 28 '19 at 15:07

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,247
0

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