Results 1 to 9 of 9
in CLI where to get Trash items.
suppose startX is not working and i deleted a file.... where to get it???...
- 06-01-2009 #1
command line RecycleBin
in CLI where to get Trash items.
suppose startX is not working and i deleted a file.... where to get it???
- 06-01-2009 #2
only when you delete a file using GUI interface for example , right click and Trash will be displayed on your Trash box and files will be placed under ~/.local/share/Trash.
If you delete files using rm command,they are same as shift + del , so files are not placed in any directories,they are lost.
Unless you have some kind of files protection tool( like giis
,if you are using ext3) you can't get them back without proper recovery tools .
- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 06-01-2009 #3
If you are really afraid of rm, you could alias it as copying to the trash.
- 06-03-2009 #4Linux User
- Join Date
- Jan 2006
- Posts
- 414
You could always write your own little trash script, something like:
name is trash, put it in /usr/bin and make it executable. Then you can trash things with:Code:#!/bin/sh if [ -f $1]; then mv $1 ~/.trash/.; elif [ -d $1]; then mv -R $1 ~/.trash/.; else echo "trash: $1: unknown file or directory"; fi exit 0;
Code:$ trash myfile
- 06-03-2009 #5Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
Tis' weird to say the least

Ending colons are not needed and I can't tell why do you use it on some lines and not anothers. You only need them to separate two instructions on the same line, like with "if...; then"
Another thing, please, when dealing with filenames, always quote them. Otherwise you are going to get lots of fun each time that a file name has spaces in the middle. The dots at the end of a path are useless as well. Redundant. You are already on that directory, you don't need to emphasize it any more.
Another small thing, this:
Is incorrect even if we obviate all the above. "]" must be a separate token, you missed a blank space in between "$1" and "]".Code:if [ -f $1]; then
Finally, mv has no "-R" flag. It already moves recursively directories. Which in turn means that the two cases that you separated really need no separation (unless you really want to treat directories in a different way to get some extra security. I assume that the answer to that is "no", so I will also add that you need write permissions on them because you are actually moving them to another place.
Adding it all, this would be the -syntactically correct- version of your script.
I would add some extra magic to check if the trash folder is writable, just in case. But that's just me.Code:#!/bin/sh if [ -w "$1" ] && [ -r "$1" ]; then mv "$1" ~/.trash/ else echo "$0: $1: unknown file or directory" fi exit 0
Note the usage of "$0", which is expanded to the name of the script. Not a big deal, but that way you won't get confused if you save the script with a different name.
- 06-03-2009 #6Linux User
- Join Date
- Jan 2006
- Posts
- 414
heh, yeah I don't do much shell scripting as you can tell, just threw that together quickly as an idea of what could be done

As for the dots at the ends of paths, just habit incase some obscure shell decides to move things and rename them trash instead of putting them in the directory... used to happen on some old unix boxen.
- 06-03-2009 #7
hmm... wanted to ask about the ending dot but found it answered...

Also, $1 is only for first filename. What if we want to delete multiple files? I used 'for loop' in the above code to achieve this. But is there any other method?
Code:#/bin/bash # Script to put files in trash in traditional 'Del' fashion than to # remove it completely in 'Shft+Del' fashion. for i in "$@" do if [ -w "$i" ] && [ -r "$i" ] ; then mv "$i" ~/.trash/ else echo "File or directory $i does not exit." fi done exit 0
A candle looses nothing by lighting other candles. - Khalil Zibran.
Registered Linux User #490076
- 06-03-2009 #8Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
There lots of methods
You could use $# along with shift so you don't need an $i. Something in the lines of
Shift acts like in DOS bat scripts. It discards the first positional parameter and "shifts" the rest of them to the left so $2 becomes $1. $# holds the number of parameters at a given time, when it's zero there's nothing else to look at. We iterate through the list and look always at $1, we don't need $iCode:while [ $# -ne 0 ] do if [ -w "$1" ] && [ -r "$1" ] ; then mv "$1" ~/.trash/ shilft else echo "File or directory $1 does not exit." exit 1 fi done
If a file doesn't exist, we exit with error (1).
- 06-03-2009 #9
Oh yes, totally forgot the 'shift'ing. Gracias i92guboj
A candle looses nothing by lighting other candles. - Khalil Zibran.
Registered Linux User #490076


Reply With Quote
