How to Delete and Recover Files in Linux
Linux is a reasonably famous Operating System especially among programmers. The default file system in Linux is known to be intolerant when it comes to user mistakes, but using the method described in this post, you will be able to recover any data that you lost or accidentally deleted.
Deleting Files In Linux
Deleting a file in Linux is quite simple. You just have to right-click the file icon (which you want to delete) & then click the “Delete” option in the context menu. If you are working from the command console or terminal, the delete command is “rm” for remove. The “rm” command accepts a number of parameters which can be both unsafe and extraordinarily useful. The most famous parameter pair is “rm -rf”. This command deletes everything that’s present inside the specified folder, recursively (r). Moreover, this command does not ask you to confirm the deletion of each file. This means that you can accidentally delete the entire File system. This could be dangerous in some cases.
There is no recycle bin in Linux. So if you delete a file, It will no longer be available on your hard disk. Other operating systems however, usually have a recycle bin, which is just a folder where all the deleted files are preserved where they can be recovered or permanently deleted from there.
Recovering Files in Linux
Linux is famous for being customizable, there is a little tweak that can be made that will add the recycle bin functionality. You can simply add an alias to their.bashrc file, in a user’s home directory, that overrides the rm command. The alias is as follows:
alias rm=’mv –target-directory=$HOME/.Trash’
This alias would change the rm command into the mv, move command and send any files sent to be removed to the.Trash directory in the user’s home folder however this is not the best solution to save files from being lost as this may sometimes cause confusion with other aliases.
Another way of recovering files in linux is by using a process known as ‘File carving’. This application parses the hard disk for the leading and trailing bits of a file and then uses those bits to identify the file type and group together the deleted file on the disk. It is a reliable technique and is used by forensic data recovery.
You can use 3 main application for file carving: foremost, PhotoRec, and scalpel. From a console window, enter the application’s name, followed by the hard drive partition’s name found by using the “fdisk -l” command (ex. /dev/hda2).
Using the above two methods you should be able to recover or delete files in Linux in virtually any situation.
Luqmaan Ameen is the main writer behind Computer Realm, a blog which focuses on computer tips and several other aspects on computers and the internet in general. Cannot delete file? If so, you can find a free solution on http://www.computer-realm.net/cannot-delete-file/ on his site.