agapito
January 31st, 2006, 08:59 PM
First of all, I'm sorry for posting a howto with such a lame and easily replaceable one line shell script, but I think it will help keep the newbies and the distracted and/or lazy (like me! :)) a bit safer.
Have you ever done a deleted a file in in the shell, only to find out 3 seconds latter that you made a mistake? ](*,) This is what I do to keep that kind of trouble away from me:
1. Open you favourite editor and create a file called "del" (or whatever you wish to call it, but i'll use del in this exemple). Let's say it's gedit:
gedit ~/bin/del
2. Write this there:
#!/bin/bash
mv -vi -- "$@" $HOME/.Trash
You can see this in the manpage, but anyway:
v =verbose (i.e. explain what is being done)
i =interactive ( prompts you before overwriting)
-- = so you won't get in trouble with names that start with a -
"$@" = everything in front of the command (which in this case is our "del" shell script)
3. Save it.
4. Now let change the permissions of the file, so that you can execute it.
chmod -v 755 ~/bin/del
5. And that's it. Now, you can do things like:
del file1 file2 directory1/ directory2/ -strage_filename
and it all gets send to the Trash (a.k.a. Recycle Bin). ;)
Note: I assume you have a "bin" dir in you home directory. If you don't you have two options:
1. Create it...
mkdir ~/bin
and add it to your PATH variable...
echo "export PATH=$HOME/bin:$PATH" >> ~/.bashrc
You must use two > signs ( i.e. >> like above) or else you will overwrite your .bashrc file.
Note that you must restart the terminal, reload the env variables
. ~/.bashrc
or do export PATH=$HOME/bin:$PATH
for the ~/bin directory to be in you PATH variable.
2. Save your file to /usr/local/bin or /urs/bin modifying the howto accordingly.
You need more?
I made a "volume-aware" version of del, which autodetects the volume's Trash directory and deletes to there. It has interactive overwrite and rename, command line options and can be custumized to override the volume default trash directory. I'm attaching it to this howto. You just have to download
it, extract it (tar xvzf del.tar.gz) and move it to ~/bin, /usr/bin or /usr/local/bin.
For some help do
del -h
I did a great deal of testing but, since it's a relatively large script it may still have some bugs. I don't expect them to be dangerous because only "mv" command are used, but consider yourself warned. ;)
Any feedback, good or bad, and/or sugestions are highly apreciated.
I'm not explaining it step-by-step here, but I'll answer any questions about it.
Enjoy. :D
Have you ever done a deleted a file in in the shell, only to find out 3 seconds latter that you made a mistake? ](*,) This is what I do to keep that kind of trouble away from me:
1. Open you favourite editor and create a file called "del" (or whatever you wish to call it, but i'll use del in this exemple). Let's say it's gedit:
gedit ~/bin/del
2. Write this there:
#!/bin/bash
mv -vi -- "$@" $HOME/.Trash
You can see this in the manpage, but anyway:
v =verbose (i.e. explain what is being done)
i =interactive ( prompts you before overwriting)
-- = so you won't get in trouble with names that start with a -
"$@" = everything in front of the command (which in this case is our "del" shell script)
3. Save it.
4. Now let change the permissions of the file, so that you can execute it.
chmod -v 755 ~/bin/del
5. And that's it. Now, you can do things like:
del file1 file2 directory1/ directory2/ -strage_filename
and it all gets send to the Trash (a.k.a. Recycle Bin). ;)
Note: I assume you have a "bin" dir in you home directory. If you don't you have two options:
1. Create it...
mkdir ~/bin
and add it to your PATH variable...
echo "export PATH=$HOME/bin:$PATH" >> ~/.bashrc
You must use two > signs ( i.e. >> like above) or else you will overwrite your .bashrc file.
Note that you must restart the terminal, reload the env variables
. ~/.bashrc
or do export PATH=$HOME/bin:$PATH
for the ~/bin directory to be in you PATH variable.
2. Save your file to /usr/local/bin or /urs/bin modifying the howto accordingly.
You need more?
I made a "volume-aware" version of del, which autodetects the volume's Trash directory and deletes to there. It has interactive overwrite and rename, command line options and can be custumized to override the volume default trash directory. I'm attaching it to this howto. You just have to download
it, extract it (tar xvzf del.tar.gz) and move it to ~/bin, /usr/bin or /usr/local/bin.
For some help do
del -h
I did a great deal of testing but, since it's a relatively large script it may still have some bugs. I don't expect them to be dangerous because only "mv" command are used, but consider yourself warned. ;)
Any feedback, good or bad, and/or sugestions are highly apreciated.
I'm not explaining it step-by-step here, but I'll answer any questions about it.
Enjoy. :D