Restoring deleted file with rm -rf


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Restoring deleted file with rm -rf
# 1  
Old 04-11-2016
Restoring deleted file with rm -rf

Is there a way I could recover a deleted text file with "rm -rf" command.

Running CentOS 6.5.

Thank you.
# 2  
Old 04-11-2016
The rm command deletes files; it does not recover lost or deleted files.

Once you have deleted a file, it is generally gone and unrecoverable. If you happen to be using a transactional filesystem, recovery might not be so difficult. Otherwise, if, immediately after removing a file you unmount the filesystem on which it was located without writing any new data to any other file on that filesystem, you might be able to search the free list for that filesystem for blocks that had been assigned to the file you deleted; but how you do that, if it is possible at all, varies considerably based on the filesystem type.
# 3  
Old 04-11-2016
Quote:
Originally Posted by Don Cragun
The rm command deletes files; it does not recover lost or deleted files.

Once you have deleted a file, it is generally gone and unrecoverable. If you happen to be using a transactional filesystem, recovery might not be so difficult. Otherwise, if, immediately after removing a file you unmount the filesystem on which it was located without writing any new data to any other file on that filesystem, you might be able to search the free list for that filesystem for blocks that had been assigned to the file you deleted; but how you do that, if it is possible at all, varies considerably based on the filesystem type.
I am running CentOS under a VPS.. i dont think it has backups Smilie So this means my file is lost, right?
# 4  
Old 04-12-2016
Im afraid... Always wise to archive before a rm -rf just in case as nothing is stopping you to remove the archive later once you have checked and see no issue...
# 5  
Old 04-12-2016
Hi.

In a system like:
Code:
OS, ker|rel, machine: Linux, 2.6.32-358.23.2.el6.centos.plus.x86_64, x86_64
Distribution        : CentOS 6.4 (Final)

There appears to be:
Code:
extundelete.x86_64 : An ext3 and ext4 file system undeletion utility
testdisk.x86_64 : Tool to check and undelete partition, PhotoRec recovers lost
                : files

I have no experience with either one.

This could also be considered a valuable (but difficult) learning experience:
1) Have a backup, even if minor (e.g. file.01, file.02, etc).
2) Balance extra resources with risk of losing one's time.
3) It's a rite of passage to destroy something valuable.

I consider my time to be very valuable. So I use a number of strategies to reduce risk. For example, I use virtual machines most of the time. This allows me to do a snapshot, which can restore an entire system in less than 5 minutes (and usually less). I usually do a snapshot just before a big update. After a reboot and few days of smooth running, I fold the snapshot into the running system. I have used VMWare and Virtualbox for that. Requires learning about virtual machines.

I have an external machine contact other machines periodically, say every 4 hours, then do an rsnapshot to capture changed files, rotating to daily, weekly, monthly backups. Rsnapshot knows about LVM volumes, and can create LVM snapshot volumes (not to be confused with virtual machine snapshots, but both use the idea of copy-on-write , https://en.wikipedia.org/wiki/Copy-on-write), so that the system can be captured without stopping the machine. Requires learning, setup, external machine, and a big disk (I use a big disk in a raw disk dock).

During development work, I use a version control system, like rcs, bzr, etc., to keep a local (to the directory) copy of files in development. Requires learning a bit about version control. More feature-full systems include subversion, git, etc.

Every week or so, I tar up the home directory on my main workstation and store it on a (slow, but large) external drive. This is easiest.

On a Windows box I recently tried cloud backup with Acronis. It was agonizingly slow. It seemed better to backup to a local drive (again in a USB/SATA dock).

I have rarely completely lost a file in the recent past.

Good luck ... cheers, drl
These 2 Users Gave Thanks to drl For This Post:
# 6  
Old 04-12-2016
Kudos to drl for his succinct description of how to handle file security. He has it 100% right.

Quote:
Originally Posted by galford
I am running CentOS under a VPS..
Yes, but this doesn't tell us which filesystem you are running. Possible candidates include "ext2", "ext3", "ext4" (with or without an underlying volume group) and some others.

Quote:
Originally Posted by galford
i dont think it has backups Smilie So this means my file is lost, right?
Essentially: yes. There are some low-level possibilities (see above) to retrieve the content nevertheless, but they all have in common that:

- they need in-depth knowledge of the filesystem involved and are for experts only - try it as a beginner and you are likely to get yourself even deeper into troubles than you are already;

- even then they are not guaranteed to work. Most of these tools are "best effort" and sometimes they work, sometimes they work partly and sometimes they do work not at all;

- the necessity of backups can not be stressed enough and it is a painful (but valuable!) lesson to learn this - unfortunately it seems to be the only way that has a lasting effect. Generations of admins and users have neglected backups and all these generations have been in your shoes once before they started to develop healthy habits. (fwiw: me too ;-) )

You might consider using a desktop environment, like GNOME, KDE or something such. I don't like any of them, but most desktops offer a "waste bin" - a hidden directory of some sorts where "deleted" files and directories go. One can pull them out of there if they were not meant to be deleted. To be honest, I'd rather recommend developing responsible user habits (like double-check if what you type is really what you want), but before that goal is achieved such a "waste bin" might come in handy as a crutch.

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

CentOS7 restoring file capabilities

Quite an obscure question I think. We have a rebuild process for remote sites that allows us to PXE rebuild a till (actually a PC with a touch screen and various fancy bits) running CentOS. The current CentOS5 tills work just fine with a tar image restore and some personalisation. Sadly,... (4 Replies)
Discussion started by: rbatte1
4 Replies

2. Shell Programming and Scripting

Restoring a file to its original location

Hello everyone, I am attempting to make a recycling bin type application in shell script (tcsh). I have the whole part of the application done where someone can recycle files from one location to the recycling bin (the lower half of the program), this is not a problem. However I wanted to make... (7 Replies)
Discussion started by: tastybrownies
7 Replies

3. Shell Programming and Scripting

restoring file to its default location...

Hello everyone, I am new to unix shell. I have a file called Path.txt....and i have data in that as 1 abhi 2 avi 3 ash so on..... 1 ,2 ,3 is the... (2 Replies)
Discussion started by: AbhijitIT
2 Replies

4. UNIX for Dummies Questions & Answers

Restoring back a deleted file in unix.

Hi, Can any one tell me how to restore back the deleted file in unix? I know the file name. If i know the inode number of the file does help more to restore back the file? (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

5. Shell Programming and Scripting

Restoring a file

I'm new to Unix and have just wrote a little program to move files to a recycle bin (a Directory i created) and restore them. The problem is that i need to keep track of all the full filenames so that i can restore them to the right place. I did this by creating a file called delreg and putting the... (4 Replies)
Discussion started by: zoolz
4 Replies

6. UNIX for Dummies Questions & Answers

Blocksize problem restoring file from tape

I was recently given the responsibility of the unix box at our work. Without much training, I now have to go back and restore a file from tape. I'm having some trouble with it. I'm getting an error with the blocksize. The part of the script that does the tar looks like this: tar cvfX... (11 Replies)
Discussion started by: citrowske
11 Replies

7. Solaris

Restoring TAR'd file to different location

Is it possible to restore a TAR'ed file off of a tape to a location other than the original location? If so, how? (The MAN pages give examples of how to restore only to the originating location.) Thanks!! (1 Reply)
Discussion started by: FredSmith
1 Replies

8. UNIX for Dummies Questions & Answers

restoring deleted files

I had a user run, by accident, the following line command on our UNIX server: rm -f /usr/* This apparently deleted some needed files on your system. Having very limited knowledge in UNIX, I thought I would ask the group if anyone knows how I can recover these file? The version of UNIX is... (3 Replies)
Discussion started by: mikem
3 Replies

9. UNIX for Dummies Questions & Answers

Restoring a single file...???

Can anyone please help...? Managed to do a ufsdump of files to tape. Having trouble using ufsrestore to pull a single file back by filename?? I have dumped a single file to tape also because looking through the other threads, I noticed that you have to tell it to skip files before you get to... (1 Reply)
Discussion started by: Jonathan
1 Replies

10. UNIX for Dummies Questions & Answers

Restoring a file from Tape

help please i have "inherited" a Sco Server (the administrator departed in a hurry...yes we are chasing him..) and haven't used Unix for 8 years. i have a file that i need to retrieve from a tape. i have been able to find the file on tape using the cpio -ivt command. however... the problem I... (3 Replies)
Discussion started by: mfischer
3 Replies
Login or Register to Ask a Question

Featured Tech Videos