[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Undeleting files




----------  Forwarded Message  ----------
Subject: Re: Undeleting files
Date: Wed, 1 Aug 2001 07:40:23 +0800
From: Robert Storey <y2kbug@ms25.hinet.net>
To: rett@post.cz


On Tuesday 31 July 2001 22:07, rett@post.cz wrote:
> Is there any way to get
> back deleted files in Linux?

Undeleting files in Linux is a big chore, and success is not guaranteed.
While I can't help you with files you've already trashed, I can give you a
tip on how to totally avoid this problem in the future.

A simple Bash script file can be used to create a "trash can." The trash can
in your /tmp partition will normally hold "deleted" files for about 10 days
before it gets automatically emptied.

Use your favorite text editor and create a file named "delete" with this
content:

mkdir -p /tmp/$USER/del
   2>/dev/null
mv $* /tmp/$USER/del 2>/dev/null
echo "$# files moved"

The first line of this script creates a directory in your /tmp partition. If
your login name is "rett" then the name of the directory will be
"/tmp/rett/del". The second line of the script suppresses an error message
that will result if the directory already exists. The third line line moves
the files you want to delete into this directory and suppresses any error
message that might result if there are already files with the same name in
that directory. The fourth line informs you how many files were moved.

Before you can use this new delete command, make it executable with "chmod +x
delete". Then to test it, create a junk file called temp.txt and delete it
with the command:

./delete temp.txt

You should then find that the file was not actually deleted, but rather moved
to /tmp/rett/del (again, assuming that your login name is rett). If you are
now happy with this new delete command, permanently put it in your PATH. Most
people create a subdirectory in their home directory called /bin, so in your
case that might be /home/rett/bin. Copy this new delete command into that
directory. To place /bin in your path, you need to put the following in
.bashrc (in your home directory):

PATH=$PATH:$HOME/bin ; export PATH

After doing all this, don't use rm to remove files, but rather:

delete file_names


- Robert Storey

-------------------------------------------------------



Reply to: