I have inadvertently rm’d an important file.
It has just been created so thus it has never been backed up.
Is there anyway I can restore it ?
SunOS enterprise 5.6 Generic_105181-29 sun4u sparc SUNW,Ultra-Enterprise
Thanks in advance.
It may be possible. If you recall that when a uxix file is removed/deleted from the disk the inodes are NOT. They're only marked as FREE. The actual data contained in the files is still on disk and can potentially be retrieved before being over-written. It's important to put your file system in a safe/read-only state to prevent the file from being over written. Then use dd to copy the file system (not just your home directory) to a file:
dd if=/dev/dsk/c0t0d0s1 of=/export/recovery.txt
Then try to find out which entries are out there by:
cat -n /export/recovery.txt | fgrep "something inside the file"
200214 #!/bin/sh something inside the file
345678 # This is my deleted file something inside the file
123456 something inside the file
If this returns something, then you're in good shape. If not then try to look for something else that is unique inside the file. It's easier if you have something on the first line but it isn't critical.
Now comes the tricky part. The easiest method is by using the GNU version of grep which allows for a certain number of lines before/after a match to be displayed. Or you can check out seekcat.
Example:
fgrep -A 10 "something inside the file" /export/recover.txt > recoveredfile.txt
Where 10 is the number of lines to grab after the text (-B = # lines before text)
If there is more than one occasion you will have to clean up the recoveredfile.txt to get your file back to its original form.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.