Undo the Linux trash command
There is no general "undo" for every operation in terminal. If you wish to recover a file after using rm
you will need to look into recovery software.
An option to prevent you from future mistakes is to make alias
es for alternative commands to remove files. Add them to your ~/.bashrc
and get into the habit of using them instead of rm
.
alias rmi='rm -i'
If you use
rmi
, you will be prompted for confirmation of future deletes. Try to avoid developing the habit of pressingy
immediately after you issue anrmi
command, as that will defeat the purpose.You could also move files deleted by the
trsh
command in terminal to your recycle bin (on KDE and Gnome):alias trsh='mv --target-directory="$HOME/.Trash"'
If you use
trsh
, you will have a limited "undelete" capability. Beware thattrsh dir1/file1 dir2/file1
may still cause unrecoverable data loss.
There is no recycle bin for the command line.
You could try some of the various undelete utilities, but there's no guarantee that they would work.
You could use trash-cli if you use KDE when you run a gui. This is command line utility to delete/restore using the KDE trash facilities.