Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Forum Community Discussions > The Community Cafe
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

The Community Cafe
The Community Chat area is for lighthearted and enjoyable discussions, like you might find around a water cooler at work.

Almost any non-tech-support topic may be discussed here. Discussions on religion and politics are not allowed, except for politics directly related to free and open source issues. Any topic or discussion that causes problems or drama will be closed. This area is intended for fun and community building, not arguments. Please take those elsewhere. Thanks!

 
Thread Tools Display Modes
Old June 24th, 2008   #1
george9233
Just Give Me the Beans!
 
george9233's Avatar
 
Join Date: Mar 2008
Location: Melbourne, AU
Beans: 71
Ubuntu 8.04 Hardy Heron
Lightbulb A shell script for moving your files to "Garbage bin"

Hello everyone. I've just written a shell script for moving files to the "Garbage bin". So unlike the "rm" command, you can retrieve files deleted by mistake on the command line simply by opening the garbage bin.

Code:
#!/bin/bash

until [ "$#" = "0" ];do
    mv $1 "$HOME/.local/share/Trash/files"
    shift
done
I saved it as a file named "ga", made it executable and put it in the "bin" folder in my home directory, so after adding "export PATH=$PATH:$HOME/bin" to my .bashrc I was able to use it as a normal command. Certainly it can just be put into "/bin" directory.

Since there's a loop, I'm able to operate on multiple files and/or folders. It's quite useful I think.

Last edited by george9233; June 24th, 2008 at 03:03 PM..
george9233 is offline   Reply With Quote
Old October 5th, 2009   #2
kc600
5 Cups of Ubuntu
 
Join Date: Dec 2007
Beans: 29
Ubuntu Karmic Koala (testing)
Re: A shell script for moving your files to "Garbage bin"

Thanks dude! I took the liberty of improving on it slightly, so the metadata (deleted when, and where from) are also stored: http://keeshink.blogspot.com/2009/10...-to-trash.html
kc600 is offline   Reply With Quote
Old October 5th, 2009   #3
NoaHall
Fresh Brewed Ubuntu
 
Join Date: Mar 2009
Beans: 1,527
Ubuntu 9.10 Karmic Koala
Re: A shell script for moving your files to "Garbage bin"

It's easy to make.
NoaHall is online now   Reply With Quote
Old October 5th, 2009   #4
bigboy_pdb
Ubuntu Extra Shot
 
bigboy_pdb's Avatar
 
Join Date: May 2007
Location: Canada
Beans: 352
Ubuntu 9.04 Jaunty Jackalope
Re: A shell script for moving your files to "Garbage bin"

You can simplify your script even more by making it:

Code:
#!/bin/bash
mv "$@" "$HOME/.local/share/Trash/files"
bigboy_pdb is offline   Reply With Quote
Old October 5th, 2009   #5
sisco311
Ubuntu Pale Lager
 
sisco311's Avatar
 
Join Date: Feb 2007
Location: romania
My beans are hidden!
Ubuntu Development Release
Re: A shell script for moving your files to "Garbage bin"

hhhm, reinventing the wheel?

Code:
trash path/to/file
Code:
man trash
sisco311 is offline   Reply With Quote
Old October 6th, 2009   #6
kc600
5 Cups of Ubuntu
 
Join Date: Dec 2007
Beans: 29
Ubuntu Karmic Koala (testing)
Re: A shell script for moving your files to "Garbage bin"

@bigboy: this doesn't create the info file.
@sisco: i found the app in the 'trash-cli' package, thanks for pointing this out!
kc600 is offline   Reply With Quote
Old October 6th, 2009   #7
bigboy_pdb
Ubuntu Extra Shot
 
bigboy_pdb's Avatar
 
Join Date: May 2007
Location: Canada
Beans: 352
Ubuntu 9.04 Jaunty Jackalope
Re: A shell script for moving your files to "Garbage bin"

Quote:
Originally Posted by kc600 View Post
@bigboy: this doesn't create the info file.
You're right. I had just looked at the first command, noticed it could be simplified, and thought it might be good to give a shorter version. I hadn't even thought about the mechanics of the trash bin or checked the other script. Sorry about that.

Now that you've mentioned it and I've looked at the link for the second version of a trash script and the source for trash-cli and I don't really think it's a good idea to write or use custom scripts to modify the trash bin since the trash applet will change over time and using custom trash scripts can corrupt it. trash-cli doesn't appear to be sharing code with the applet. If it were, I'd feel differently about it.

If a person knows about the location of trash files and how to clear it when it's corrupt then doing that might not be so bad.

Last edited by bigboy_pdb; October 6th, 2009 at 11:14 PM..
bigboy_pdb is offline   Reply With Quote

Bookmarks

Tags
shell script

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:43 AM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. lingonberry