Deleting files and trash etc

Using applications, configuring, problems
Post Reply
Message
Author
tytower

Deleting files and trash etc

#1 Post by tytower »

When I right click I get a "delete" option to delete a file .
I would like all deleted files to go into the trash bin for say, a day , so that I could recover a file that I had deleted in error.

In fact noting the errors I have seen in Puppy where groups of files just disappear without explanation( probably because of something I have done anyway) it would be prudent to make all deleted files pass through trash anyway with an option to choose when the trash is emptied.

Can this be done at the moment?

User avatar
Hotdog
Posts: 134
Joined: Fri 30 Sep 2011, 03:15
Location: Georgia USA

#2 Post by Hotdog »

tytower,

Most Puppies have Trash as an option in the right-click menu. What version of Puppy do you have? And, what type of installation? Maybe we can figure out how to get it back.
[i]Puppy 5.2.8.7, Full Install[/i]

tytower

#3 Post by tytower »

I have 5.4.2 but I think you mean in Rox filer a trash can comes up next to the "delete" command . When you use this it does not go into trash it is deleted forever..I would like a trash can option on that right click menu at least but it would seem better to me to be able to trash it on all deletes and don't actually lose the file until a time has been reached or the user intentionally removes them to clear up space.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#4 Post by SFR »

You could try to play with this, but frankly I haven't used it since then and don't know if Darkcity has explored the subject deeper.

Regarding ROX-Filer's Trash - it depends on Puppy version.
Lucid, for instance, has it, but Slacko/Precise haven't.

If you'd like to add Trash to your right-click menu:

1. Safe, but inconvenient method:
Right-click a file/folder -> Customize Menu... -> drag'n'drop Trash icon from desktop into opened dir (create relative symlink).
It has to be repeated for each filetype.

2. Easy, but possibly unsafe method (I haven't had any problems with it, but it's better to make a backup before proceeding):

Code: Select all

#! /bin/bash

# Adds/removes Trash to the context menu

OpenWith_PATH="$HOME/.config/rox.sourceforge.net/OpenWith/"

case "$1" in
  "add")
    # Creates missing folders using 'globs' file contents
    for i in `cat /usr/share/mime/globs | grep ":" | cut -f1 -d ':' | tr '/' '_' | uniq`; do
      [ ! -d "$OpenWith_PATH"".""$i" ] && mkdir "$OpenWith_PATH"".""$i"
    done
    mkdir "$OpenWith_PATH"".inode_unknown"
    # Creates symlink to the Trash in every folder
    for i in `find "$OpenWith_PATH" -maxdepth 1 -type d -iname ".*"`; do
      [ ! -L "$i/Trash" ] && ln -s /usr/local/apps/Trash "$i"
    done
  ;;
  
  "remove")
    # Removes every symlink to the Trash and removes folder if empty
    for i in `find "$OpenWith_PATH" -maxdepth 1 -type d -iname ".*"`; do
      rm "$i/Trash"
      [ ! "$(ls -A "$i")" ] && rmdir "$i"
    done
  ;;
esac
  
exit
Save it in /root/my-applications/bin/ as, eg. add_remove_trash.sh and:
a). To add Trash:

Code: Select all

add_remove_trash.sh add
b). To remove Trash:

Code: Select all

add_remove_trash.sh remove
It will automatically create Trash entries for each known and unknown filetype + folders.

EDIT: Small correction in code.

HTH
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

tytower

#5 Post by tytower »

Works brilliantly . Thanks very much !

How would I get trash to emty automatically say in 2 days time ?

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#6 Post by SFR »

tytower wrote:How would I get trash to emty automatically say in 2 days time ?
Hmm, perhaps something like this:

Code: Select all

#!/bin/bash

HOW_OLD=2		# in days

while true; do
  find /root/.Trash -maxdepth 1 -and -not -name .Trash -ctime +"$HOW_OLD" -print0 | xargs -0 rm -rf
  sleep 1h
done
(save it as, eg. purge_trash.sh (no spaces in filename!) in /root/Startup/ and click to perform initial launch)

This script should search (every hour) for files/folders older than 2 days in /root/.Trash/ and delete them (if any).
But this one is really barely tested, so please be careful...
(btw, you can replace -ctime with -mmin to use minutes instead of days, but then adjust also the 'sleep' command)

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

tytower

#7 Post by tytower »

Can't be careful if I don't test the script so that warning covers your arse so thats good for you but it is pointless for me . . No Probs I'll give it a run for a few days and if my machine explodes I promise not to whine..

Thanks

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#8 Post by SFR »

Good point - to cover also your's, you can try this instead:
1. Stop the existing script (ps | grep purge_trash and kill its process)
2. Create a directory /root/Moved_From_Trash
3. Replace the appropriate line with:

Code: Select all

find /root/.Trash -maxdepth 1 -and -not -name .Trash -ctime +"$HOW_OLD" -print0 | xargs -0 mv -t /root/Moved_From_Trash 2>/dev/null
4. Re-launch the script
This way you can see if files that are supposed to be deleted are the good ones for sure.

Greetings!
Last edited by SFR on Fri 18 Jan 2013, 11:06, edited 1 time in total.
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

tytower

#9 Post by tytower »

All done I'll let you know

Should that be "All of importance I carry with me "?

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#10 Post by SFR »

Great! But you didn't tell me and I forgot to ask, and assumed that you've chosen the 'right-click -> Trash' method, not libtrash. Is that correct?
If so, all's fine. If not, the script simply won't work.
Should that be "All of importance I carry with me "?
Could be. I'm not an expert in Latin (far from that), but according to different sources: "All that is mine I carry with me" or "I carry all my things with me". But since I carry them, they must be somehow important. :wink:

EDIT:
I put -mmin instead of -ctime in the above line of code (leftover from testing).
Corrected now. Please replace it again, or all files from trash will be removed every hour. Sorry for inconvenience.

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

tytower

#11 Post by tytower »

Yes I left that (-mmin) there to prove it and it worked fine .
I'll have to look a bit closer at this though .
The new directory receives everything that was in the trash can so when opened the choices to open restore ,info ,delete,look inside etc come up . Something resets the trash can lid too when it is emptied so Ill try find that and add a line.

If you look inside you get all the "Appinfo.xml" link and "AppRun" file and "info" file for each trashed file and a Directory for the trashed file itself. I have yet to work out what is happening here but all that seems as it should be I suppose but the size of trash is increased by these as you tresh stuff. About 4.3K is added for each file put in there

Certainly it seems to empty Trash properly though as it should . Ill set up a better test over a longer time and let you know.
Thanks

Post Reply