Connect with us

How To

How To Restore Deleted Files in Linux? – The Easiest Way

Published

on

How To Restore Deleted Files in Linux

Are you searching for ways to restore deleted files in Linux?

All of us periodically delete files from our computer to keep it decluttered and to save storage space.

However, it also happens that we accidentally delete important files and realize only after deleting them.

If you’re facing such an issue on your computer running the Linux operating system, today we are here with a detailed guide that takes you through the various ways to recover deleted files in Linux OS easily.

How To Recover Deleted Files In Linux Easily?

Below are the different easy methods to recover permanently deleted files in Linux.

Method 1: Recover Files In Linux Using Terminal

  • Launch the Terminal on your Linux computer.
  • Type the command “init 1” and press the Enter key.
  • Now, type the command “grep -i -a ‘MyFile’ /dev/[partition-name] > file.txt“.Replace the MyFile text with any word that appears in the name of the file that you wish to recover. Any files with matching words in their filename will be restored.Also, replace [partition-name] with the name of the partition where you’re desired file is present.

Understanding the Above Command:

  • Init 1: “Init” stands for Initialize and represents the first process that runs on a Linux environment after booting. The Initialize process is started with the command init 1.
  • i: This parameter instructs the command line to ignore any case conditions. This means that the “-i” parameter will ignore both lower case and upper case conditions and will only return the matching letters/words.
  • -a: This parameter will process any matching binary files as they are text files.
  • Method 2: Use TestDisk To Recover Deleted Linux Files

    TestDisk is an opensource and free tool for data recovery that is already present in the official Linux repository. Below are the steps to recover deleted Linux files using TestDisk.

    • Open the terminal application on your Linux system.
    • Type in the command “sudo apt install TestDisk” and press Enter.
    • Now, type in the command “TestDisk” to run the TestDisk tool. You can now control the tool using the arrow keys.
    • You can now see an option that allows you to either create a new log file for the process, append to the existing log file, or not record any logs. Choose to create a new log and press Enter.
    • Now, after a couple of minutes, you will be able to see the drive on your computer. Select the sudo option from the bottom and enter the password. Now press the “Enter” key and press “Enter” again to create a separate log file.
    • All the drives on your computer will now be displayed.
    • From the list, select the drive from which you wish to recover deleted files and press Enter.
    • On the next screen, select “Advanced” and press “Enter”.
    • Now, select the “Undelete” option from the next screen.
    • The scan will now begin. Any deleted files that are recovered by TestDisk will be highlighted in red color within the search results.
    • Select the deleted file that you wish to recover from the search results, and press the “C” key on your keyboard.

    The recovered file will now be placed in the home folder of your computer.

    That’s it. You have now finished successfully recovering deleted file in Linux using TestDisk.

    Final Words

    We hope you found the above tutorial on how to recover deleted files in Linux easy to understand and helpful.

    In case of any questions about recovering files that are deleted accidentally in Linux, feel free to leave a comment below. We will definitely help you out.

    Continue Reading
    Click to comment

    You must be logged in to post a comment Login

    Leave a Reply