[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
trm - a command that removes files into a temporary "trash" folder
As a newbie to Linux, but long time user of Mac/Win95, I have many times
removed stuff only to find out later that I needed it back. (Usually while
trying to configure my system as root...)
Tough luck! there is no undo for rm.
Well...
trm (trash-rm) is a tiny shell file that emulates the Macintosh "trash"
basket by removing files into the temporary directory ~/.trash instead of
really removing them off the disk.
Thus, you have the option to undo a remove by looking in ~/.trash, finding
the file and moving in back in place.
When sure, simply delete all files in ~/.trash by a real remove
(or use the enclosed rmtrash to do it for you).
Included are:
1. trm - a shell file to be used much like rm.
It uses a 'mv' command to move the "removed" files into ~/.trash
Thus, the parameters it recieves should be those that 'mv'
recognizes.
2. rmtrash - a shell file to clean up the ~/.trash by really removing its
contents.
3. filename.c - a C program to filter the filename oout of its entire
path.
4. next.c - a C program that takes a number as an argument, and prints out
the next biggest number.
** To install:
first compile the c programs:
gcc filename.c -o filename
gcc next.c -o next
now, move the files "trm", "rmtrash", "filename", "next" into a directory
pointed to by your PATH
(for example: create a bin directory in your home-directory, move the
files to
it, and write PATH=~/bin:$PATH
)
** I am sure that there are ways to accomplish what filename.c and next.c
do by shell commands instaed of having to compile tiny c programs.
Please tell me how this can be done so that "installation" of trm whould
be a simple copying of a script.
I hope this helps the newer linux-philes better deal with configuring
linux.
Tal Davidson
p.s. does anyone need a program to beutify (cleanly tabulate...) java
source-files? Give me an e-mail
#include <stdio.h>
main(int argc, char *argv[])
{
int num;
sscanf(argv[1], "%d", &num);
printf("%d", num+1);
}
#include <stdio.h>
#include <string.h>
main(int argc, char *argv[])
{
char *ptr;
ptr = strrchr(argv[1], '/');
if (ptr==NULL)
puts(argv[1]);
else
puts(ptr+1);
}
#!/bin/sh
/bin/rm -r $@ ~/.trash/*
#!/bin/sh
#
# trm - A shell envelope to /bin/rm that "removes" files by moving them into
# the file .trash in your home directory.
#
# by Tal Davidson
#
# clean variables:
PARAMS=
VERSION=
FILES=
# make sure that directory .trash exists at home directory (i.e. ~/.trash)
if ! test -d ~/.trash
then
mkdir ~/.trash
fi
# place command paremeters into PARAMS and FILES for removal into FILES
for i in $@
do
case $i in
-*) PARAMS="$PARAMS $i" ;;
*) FILES="$FILES `ls -d $i`" ;;
esac
done
# Find an apropriate file name in ~/.trash for the "removed" file.
# If there isn't a file by the source name, move to that name.
# Otherwise, add a ".X" to the name, where X is the smallest number
# from 0 and on to which a file "original-name.X" doesn't exist.
for i in $FILES
do
FILE=`filename $i`
if test -e ~/.trash/$FILE
then
VERSION=0
while test -e ~/.trash/$FILE.$VERSION
do
VERSION="`next $VERSION`"
done
VERSION=.$VERSION
fi
# move the file to ~/.trash, with wanted parameters.
/bin/mv $PARAMS $i ~/.trash/$FILE$VERSION
done