How to undo an operation done in terminal?

90,334

Solution 1

If deleted the file in a terminal with rm then it will not go to the trash, do it in filemanager and it will.

You 'might' be able to restore the file, but all the time you're using the system the area the file was in could be overwritten.

https://help.ubuntu.com/community/DataRecovery

You should be able to revert permissions on files.

https://help.ubuntu.com/community/FilePermissions

Solution 2

There's an rm wrapper script that makes rm a bit more fool-proof.

Suppose you did...

rm very_important_file

Getting that file back using the terminal is tedious and not always possible.

If you used the script mentioned above, you don't have to worry about this because

rm very_important_file

Is actually doing

mv very_important_file ~/.Trash/

behind the scenes in that rm wrapper script mentioned above.

The script handles more cases and doesn't alter your system rm application, just shadows it if you put the wrapper somewhere before the official rm in your $PATH.

This is a bit better than just aliasing, because it can do more (like maintaining that ~/.Trash/ directory).

Share:
90,334

Related videos on Youtube

Ranjit Shinde
Author by

Ranjit Shinde

Updated on September 18, 2022

Comments

  • Ranjit Shinde
    Ranjit Shinde over 1 year

    I had deleted an important file once and later i had changed the permissions of a file which i am not able to revert now. Is there any way through which i can undo delete or revert permissions on files while working with terminal?


    And one more question about Ubuntu ... Why do we never get a dialog box asking 'are you sure you want to delete' as compared to windows.I see it as a flaw in Ubuntu GUI. Once you press delete,there it is in the trash but never prompts to ask if we really want it to be deleted and ofcourse, I know ppl would be like -- why you want reassurance before deleting...it is a part of HCI and should be implemented(I am sorry,just a beginner).

    • 23  93  26  35  19  57   3  89
      23 93 26 35 19 57 3 89 about 12 years
      As far as I know nautilus will prompt for confirmation when you empty the trash/rubbish bin but not when you 'delete' a file. If you use a terminal then rm -i will ask for confirmation. askubuntu.com/questions/8590/…
    • Ranjit Shinde
      Ranjit Shinde about 12 years
      @forestpiskie Ya i know abt the terminal thingy btw i am using 10.10 Lucid not nautilus.
    • RobotHumans
      RobotHumans about 12 years
      If you want delete prompts in the command line add this alias to your .bashrc askubuntu.com/questions/17536/…
  • Ranjit Shinde
    Ranjit Shinde about 12 years
    @bebojoor ofcourse the first thing i did was to look for it in the trash but its not found and about downloading and making the file... thats what i will obviously be doing in the end if i am not getting any solution. :(
  • Ranjit Shinde
    Ranjit Shinde about 12 years
    I donot know what were the earlier permissions set. I want to rollback not change again. and Data recovery... is it that tedious to retrieve a deleted file ? Can you suggest some alternatives?
  • 23  93  26  35  19  57   3  89
    23 93 26 35 19 57 3 89 about 12 years
    It would I think be rather tedious, if it's that important though it would be worth it. You don't need to know what the permissions were - you do need to know what you want them to be now.