Re: Auto-emptying of trash.

2014-06-09 Thread Tom H
On Sun, Jun 8, 2014 at 4:03 AM, Sharon Kimble
boudic...@skimble.plus.com wrote:

 Revisiting a question that I asked in March last year about how to
 auto-empty a trash bin.

 This has worked very well until today, when on one of my drives it
 also deleted the trash bin as well, so my follow-on script to give
 me the size of my trash bin failed as there wasn’t a trash bin to
 evaluate!

 Here is the script lines -
 --8---cut here---start-8---
 find /media/boudiccas/back2/.Trash-1000 -type f -mtime +$days -delete;
 find /media/boudiccas/back2/.Trash-1000 -depth -type d -exec rmdir 
 --ignore-fail-on-non-empty {} +;
 --8---cut here---end---8---

Use -mindepth 1:

[localhost:/home/th/Public]$ find .
.
[localhost:/home/th/Public]$ find . -mindepth 1
[localhost:/home/th/Public]$


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
https://lists.debian.org/CAOdo=SxcHvqb=sopcdrvjsjpodyhqn0xvmsoipiau1vs6qe...@mail.gmail.com



Re: Auto-emptying of trash.

2014-06-08 Thread Ralf Mardorf
That's strange, since rmdir --ignore-fail-on-non-empty seemingly
shouldn't remove the directory. I wasn't aware about this, so I tested
it, resp. compared it to rm -r [1].

Perhaps you should post the complete script, the culprit seems not to be
rmdir.

[1]
[rocketmouse@archlinux ~]$ touch ~/Desktop/test ~/Desktop/.test
[rocketmouse@archlinux ~]$ ls -hAl Desktop
total 0
-rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:33 test
-rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:33 .test
[rocketmouse@archlinux ~]$ rm -r ~/Desktop
[rocketmouse@archlinux ~]$ ls -hAld Desktop
ls: cannot access Desktop: No such file or directory
[rocketmouse@archlinux ~]$ mkdir Desktop ; touch ~/Desktop/test ~/Desktop/.test
[rocketmouse@archlinux ~]$ ls -hAl Desktop
total 0
-rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:34 test
-rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:34 .test
[rocketmouse@archlinux ~]$ rmdir --ignore-fail-on-non-empty ~/Desktop
[rocketmouse@archlinux ~]$ ls -hAld Desktop
drwxr-xr-x 2 rocketmouse rocketmouse 4.0K Jun  8 10:34 Desktop


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: https://lists.debian.org/1402216816.810.11.camel@archlinux



Re: Auto-emptying of trash.

2014-06-08 Thread Ralf Mardorf
On Sun, 2014-06-08 at 10:40 +0200, Ralf Mardorf wrote:
 That's strange, since rmdir --ignore-fail-on-non-empty seemingly
 shouldn't remove the directory. I wasn't aware about this, so I tested
 it, resp. compared it to rm -r [1].
 
 Perhaps you should post the complete script, the culprit seems not to be
 rmdir.
 
 [1]
 [rocketmouse@archlinux ~]$ touch ~/Desktop/test ~/Desktop/.test
 [rocketmouse@archlinux ~]$ ls -hAl Desktop
 total 0
 -rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:33 test
 -rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:33 .test
 [rocketmouse@archlinux ~]$ rm -r ~/Desktop
 [rocketmouse@archlinux ~]$ ls -hAld Desktop
 ls: cannot access Desktop: No such file or directory
 [rocketmouse@archlinux ~]$ mkdir Desktop ; touch ~/Desktop/test 
 ~/Desktop/.test
 [rocketmouse@archlinux ~]$ ls -hAl Desktop
 total 0
 -rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:34 test
 -rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:34 .test
 [rocketmouse@archlinux ~]$ rmdir --ignore-fail-on-non-empty ~/Desktop
 [rocketmouse@archlinux ~]$ ls -hAld Desktop
 drwxr-xr-x 2 rocketmouse rocketmouse 4.0K Jun  8 10:34 Desktop

PS:

But rmdir doesn't remove empty the directory ;).

[rocketmouse@archlinux ~]$ rmdir --ignore-fail-on-non-empty ~/Desktop
[rocketmouse@archlinux ~]$ ls -hAl ~/Desktop
total 0
-rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:34 test
-rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:34 .test



-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: https://lists.debian.org/1402217056.810.12.camel@archlinux



Re: Auto-emptying of trash.

2014-06-08 Thread Ralf Mardorf
On Sun, 2014-06-08 at 10:44 +0200, Ralf Mardorf wrote:
 On Sun, 2014-06-08 at 10:40 +0200, Ralf Mardorf wrote:
  That's strange, since rmdir --ignore-fail-on-non-empty seemingly
  shouldn't remove the directory. I wasn't aware about this, so I tested
  it, resp. compared it to rm -r [1].
  
  Perhaps you should post the complete script, the culprit seems not to be
  rmdir.
  
  [1]
  [rocketmouse@archlinux ~]$ touch ~/Desktop/test ~/Desktop/.test
  [rocketmouse@archlinux ~]$ ls -hAl Desktop
  total 0
  -rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:33 test
  -rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:33 .test
  [rocketmouse@archlinux ~]$ rm -r ~/Desktop
  [rocketmouse@archlinux ~]$ ls -hAld Desktop
  ls: cannot access Desktop: No such file or directory
  [rocketmouse@archlinux ~]$ mkdir Desktop ; touch ~/Desktop/test 
  ~/Desktop/.test
  [rocketmouse@archlinux ~]$ ls -hAl Desktop
  total 0
  -rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:34 test
  -rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:34 .test
  [rocketmouse@archlinux ~]$ rmdir --ignore-fail-on-non-empty ~/Desktop
  [rocketmouse@archlinux ~]$ ls -hAld Desktop
  drwxr-xr-x 2 rocketmouse rocketmouse 4.0K Jun  8 10:34 Desktop
 
 PS:
 
 But rmdir doesn't remove empty the directory ;).
 
 [rocketmouse@archlinux ~]$ rmdir --ignore-fail-on-non-empty ~/Desktop
 [rocketmouse@archlinux ~]$ ls -hAl ~/Desktop
 total 0
 -rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:34 test
 -rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:34 .test

Oops, pardon you want to delete dirs inside the trash dir?!

It doesn't work either [2]. Is this something that should work in
combination with find?

[2]
[rocketmouse@archlinux ~]$ mkdir ~/Desktop/testdir ; touch 
~/Desktop/testdir/test ~/Desktop/testdir/.test
[rocketmouse@archlinux ~]$ ls -hAl ~/Desktop/testdir
total 0
-rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:50 test
-rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:50 .test
[rocketmouse@archlinux ~]$ rmdir --ignore-fail-on-non-empty ~/Desktop/testdir
[rocketmouse@archlinux ~]$ ls -hAl ~/Desktop/testdir
total 0
-rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:50 test
-rw-r--r-- 1 rocketmouse rocketmouse 0 Jun  8 10:50 .test
[rocketmouse@archlinux ~]$ ls -hAld ~/Desktop/testdir
drwxr-xr-x 2 rocketmouse rocketmouse 4.0K Jun  8 10:50 
/home/rocketmouse/Desktop/testdir



-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: https://lists.debian.org/1402217660.810.15.camel@archlinux



Re: Auto-emptying of trash.

2014-06-08 Thread Filip
Sharon Kimble boudic...@skimble.plus.com writes:

 Revisiting a question that I asked in March last year about how to
 auto-empty a trash bin.

 This has worked very well until today, when on one of my drives it
 also deleted the trash bin as well, so my follow-on script to give
 me the size of my trash bin failed as there wasn’t a trash bin to
 evaluate!

 Here is the script lines -
 find /media/boudiccas/back2/.Trash-1000 -type f -mtime +$days -delete;
 find /media/boudiccas/back2/.Trash-1000 -depth -type d -exec rmdir 
 --ignore-fail-on-non-empty {} +;

 and this is the evaulation script line -
 echo 'Back2' - $(du -sh /media/boudiccas/back2/.Trash-1000 | cut -f1)

 How can I get it such that it empties the trash bin but does not
 delete the bin itself please?

 Thanks
 Sharon.

Add '-mindepth 1' to the conditions, so the that actions actions in the
find command only apply to the directory levels below the starting
level.


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: https://lists.debian.org/877g4r69xt@orac.fil



Re: Auto-emptying of trash.

2014-06-08 Thread Slavko
Ahoj,

Dňa Sun, 08 Jun 2014 09:03:48 +0100 Sharon Kimble
boudic...@skimble.plus.com napísal:

 Revisiting a question that I asked in March last year about how to
 auto-empty a trash bin.
 

I am created this for cca 2 years (sorry, comments in my language). It
takes mount points for block devices, check the Trash-* dirs and then
uses autotrash to take action:

#!/bin/bash
#
#  empty_trash.sh
#  
#  Copyright 2012 Slavko li...@slavino.sk
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.

usage() {
# malý pomocník
echo -e Použitie:
echo -e \t$(basename $0) [ -hrs ] [ -d dni ]
echo -e **
echo -e 
echo -e \t-r\t- reálne vyprázdnenie koša
echo -e \t-s\t- reálne vyprázdnenie koša so zobrazením štatistiky
echo -e \t-d dni\t- vymazať súbory staršie ako počet dní [predvoelne 
10]
echo -e \t-h\t- vypíše tohoto pomocníka a skončí
}

STARE=10
PARAMS=--dry-run --stat
VERBOSE=yes

# spracovanie parametrov vstupu
while getopts hrsd: OPT; do
  case $OPT in
  h) # pomocník
usage
exit 0
;;
  r) # realne vykonanie
PARAMS=
VERBOSE=no
;;
  s) # realne vykonanie so štatistikami
PARAMS=--stat
VERBOSE=yes
;;
  d) # počet dní veku položky na vymazanie
STARE=$OPTARG
[ $STARE -lt 1 ]  STARE=1
;;
  \?) # neznámy parameter
usage
exit 1
;;
   esac
done

shift $(expr $OPTIND - 1)

# hlavný kôš používateľa (XDG)
if [ -z $XDG_DATA_HOME ]; then
BASE_TRASH=$HOME/.local/share
else
BASE_TRASH=$XDG_DATA_HOME
fi

BASE_TRASH=$BASE_TRASH/Trash

if [ -d $BASE_TRASH/info ]; then
[ $VERBOSE != no ]  echo $BASE_TRASH:
autotrash --days $STARE --trash-path $BASE_TRASH $PARAMS
fi

# pre každý prípojný bod, ktorý je blokové zariadenie
for MOUNTPOINT in $(mount | egrep ^/dev | awk '{print $1 @ $3}'); do
DEVIC=${MOUNTPOINT/@*}
CESTA=${MOUNTPOINT#*@}
TRASH=${CESTA}/.Trash-${UID}
if [ -d ${TRASH}/info ]; then
[ $VERBOSE != no ]  echo
[ $VERBOSE != no ]  echo $TRASH
autotrash --days $STARE --trash-path $TRASH $PARAMS
fi
done

regards

-- 
Slavko
http://slavino.sk


signature.asc
Description: PGP signature


Re: Auto-emptying of trash.

2014-06-08 Thread Andrew McGlashan
On 8/06/2014 6:03 PM, Sharon Kimble wrote:
 Revisiting a question that I asked in March last year about how to
 auto-empty a trash bin.
 
 This has worked very well until today, when on one of my drives it
 also deleted the trash bin as well, so my follow-on script to give
 me the size of my trash bin failed as there wasn’t a trash bin to
 evaluate!

I wonder if it is as simple as touching the .Trash folder itself so that
it cannot be considered old enough to remove?

Or you could do a find condition like this:
   -a ! -name .Trash-1000


Cheers
A.



signature.asc
Description: OpenPGP digital signature


Re: Auto-emptying of trash.

2014-06-08 Thread Paul Johnson
On Jun 8, 2014 3:11 AM, Sharon Kimble boudic...@skimble.plus.com wrote:

 Revisiting a question that I asked in March last year about how to
 auto-empty a trash bin.

 This has worked very well until today, when on one of my drives it
 also deleted the trash bin as well, so my follow-on script to give
 me the size of my trash bin failed as there wasn’t a trash bin to
 evaluate!

Have you considered the tmpreaper package?  Seems like an off-label use of
that would be to tell it your trash directory is a temp directory...


Re: Auto-emptying of trash.

2013-03-04 Thread Sergey Spiridonov

Hello Sharon

On 03/03/2013 11:04 PM, Sharon Kimble wrote:

I'm trying to get a bash script working from a cron job that will empty
trash of all files and directories that are older than $N [7 days in
this case].


May be it is not what you need, but I look at package tmpreaper.

--
Best regards, Sergey Spiridonov


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/kh1pbg$sem$1...@ger.gmane.org



Re: Auto-emptying of trash.

2013-03-04 Thread Slavko
Dňa 03.03.2013 23:04 Sharon Kimble  wrote / napísal(a):
 I'm trying to get a bash script working from a cron job that will empty
 trash of all files and directories that are older than $N [7 days in
 this case]. This partly works but is very inefficient in that it
 doesn't delete everything that is available to be deleted, just tends
 to leave stuff with no apparent reasoning.
 

The autotrash package was mentioned. I have this script:

#!/bin/bash

# remove files older than 10 days
OLD=10

#pre každý prípojný bod, ktorý je blokové zariadenie
for MOUNTPOINT in $(mount | egrep ^/dev | awk '{print $1 @ $3}'); do
#DEVICE=${MOUNTPOINT/@*}
#echo Debug: $DEVICE
PATH=${MOUNTPOINT#*@}
TRASH=${PATH}/.Trash-${UID}
if [ -d ${TRASH} ]; then
autotrash --days $OLD --trash-path $TRASH 
fi
done

This script is regularly executed from my fcrontab, but you can call it
from the ~/.xsessionrc file. Script cheecks the mount points and the
.Trash-$UID directories, then executes the autotrash on these
directories (Trash's paths).

regards

-- 
Slavko
http://slavino.sk



signature.asc
Description: OpenPGP digital signature


Re: Auto-emptying of trash.

2013-03-03 Thread Bob Proulx
Sharon Kimble wrote:
 I'm trying to get a bash script working from a cron job that will empty
 trash of all files and directories that are older than $N [7 days in
 this case]. This partly works but is very inefficient in that it
 doesn't delete everything that is available to be deleted, just tends
 to leave stuff with no apparent reasoning.

Very likely you are running into the problem that removing files from
the directory causes the directory to be updated.  Because the
directory is updated it ceases to be old enough to be aged off.  This
leaves them around until they become old enough to be an age candidate
again.

Let's walk through the problem step by step.

 #!/bin/bash

Since there are no bash features I suggest using /bin/sh the standard
shell.  Others would say use bash features. :-)  I like standard
better.  A preference.

 # emptyTrash.sh

The use of a .sh on the end is frowned upon.  Sure it is a shell
script at this instant.  But you actually have a bash script and so it
should be called .bash instead of .sh.  But next week you might want
to convert it to a perl script.  Two weeks after that you might want
to convert it to a python script.  Or Ruby.  Encoding the language in
the extension then gets in the way.  It isn't needed.  If your editor
is a smart one, and most are these days, then it doesn't need the
extension to know how to syntax highlight it.

 for SUBDIR in files info
 do
 echo Lookin\' in Trash/${SUBDIR}...
 find ${HOME}/.local/share/Trash/$SUBDIR  -mtime +${DAYS} -exec rm -vrf {} 
 \; done

Running 'find' and 'for' is inconsistent.  The 'find' command can do
both.  I would have it do both.

The \; part is the classic old legacy way of running find's -exec.
It runs one argument per command.  That is less efficient than running
as many arguments as possible.  The new (ten years old is still new)
way to do this and POSIX standard is using +.  Using + will stack
as many arguments as possible and is very efficient.

Let's start by printing the entries and then work from there.

  find $HOME/.local/share/Trash -mtime +$DAYS -print

Files and directories.  I would like to remove only the files first.

  find $HOME/.local/share/Trash -type f -mtime +$DAYS -print

I would like find to remove them itself.  The -delete option was added
to GNU find some years ago and is available in all current GNU systems.

  # Warning: This fires the -delete option and will delete those files!
  find $HOME/.local/share/Trash -type f -mtime +$DAYS -delete

The files are gone.  Directories may be left behind.  I would like to
remove the directories as a second pass.

  find $HOME/.local/share/Trash -type d -print

Looks good.  Let's remove those too.  But I am likely to avoid looking
to see if a directory should be removed and simply try to remove it
and deal with the non-empty errors.  These are not files and were only
created because the files were put there.  No need to look at mtime on
the trash directories.  Just rmdir any empty directory.  Using
rmdir is very safe because it cannot remove files.  The rmdir can
only remove empty directories making it a quite safe command to simply
fling out without looking.  Can only remove directories from the
bottom up so turn on -depth.

  find $HOME/.local/share/Trash -depth -type d -exec rmdir {} +
  ...may have some errors about non-empty directories...

Looking better.  But if a directory is not empty the GNU rmdir command
has an option specifically for it.  Let's ignore only that case.

  find $HOME/.local/share/Trash -depth -type d -exec rmdir 
--ignore-fail-on-non-empty {} +

And there we have the components for this type of cleanup the way I
would do them.  (Others would undoubtedly prefer a different way.
There is more than one way to do this.)  And so we are left with these
two commands run one after the other to do the full clean up.

  #!/bin/sh
  # emptyTrash
  DAYS=7 #   retain for N days
  find $HOME/.local/share/Trash -type f -mtime +$DAYS -delete
  find $HOME/.local/share/Trash -depth -type d -exec rmdir 
--ignore-fail-on-non-empty {} +

Hope that helps.
Bob


signature.asc
Description: Digital signature


Re: Auto-emptying of trash.

2013-03-03 Thread Sharon Kimble
Thanks for this, and I've tried it out but its still not deleting files, as
I output it to a txt.file which still remain empty.

There is a programme, ported from ubuntu, called 'autotrash' in the repos.
And although I've set it up as per its man page, but its output remains at
zero, and not working.

Maybe I'm going about this from the wrong end?

Sharon.


On 3 March 2013 22:43, Bob Proulx b...@proulx.com wrote:

 Sharon Kimble wrote:
  I'm trying to get a bash script working from a cron job that will empty
  trash of all files and directories that are older than $N [7 days in
  this case]. This partly works but is very inefficient in that it
  doesn't delete everything that is available to be deleted, just tends
  to leave stuff with no apparent reasoning.

 Very likely you are running into the problem that removing files from
 the directory causes the directory to be updated.  Because the
 directory is updated it ceases to be old enough to be aged off.  This
 leaves them around until they become old enough to be an age candidate
 again.

 Let's walk through the problem step by step.

  #!/bin/bash

 Since there are no bash features I suggest using /bin/sh the standard
 shell.  Others would say use bash features. :-)  I like standard
 better.  A preference.

  # emptyTrash.sh

 The use of a .sh on the end is frowned upon.  Sure it is a shell
 script at this instant.  But you actually have a bash script and so it
 should be called .bash instead of .sh.  But next week you might want
 to convert it to a perl script.  Two weeks after that you might want
 to convert it to a python script.  Or Ruby.  Encoding the language in
 the extension then gets in the way.  It isn't needed.  If your editor
 is a smart one, and most are these days, then it doesn't need the
 extension to know how to syntax highlight it.

  for SUBDIR in files info
  do
  echo Lookin\' in Trash/${SUBDIR}...
  find ${HOME}/.local/share/Trash/$SUBDIR  -mtime +${DAYS} -exec rm
 -vrf {} \; done

 Running 'find' and 'for' is inconsistent.  The 'find' command can do
 both.  I would have it do both.

 The \; part is the classic old legacy way of running find's -exec.
 It runs one argument per command.  That is less efficient than running
 as many arguments as possible.  The new (ten years old is still new)
 way to do this and POSIX standard is using +.  Using + will stack
 as many arguments as possible and is very efficient.

 Let's start by printing the entries and then work from there.

   find $HOME/.local/share/Trash -mtime +$DAYS -print

 Files and directories.  I would like to remove only the files first.

   find $HOME/.local/share/Trash -type f -mtime +$DAYS -print

 I would like find to remove them itself.  The -delete option was added
 to GNU find some years ago and is available in all current GNU systems.

   # Warning: This fires the -delete option and will delete those files!
   find $HOME/.local/share/Trash -type f -mtime +$DAYS -delete

 The files are gone.  Directories may be left behind.  I would like to
 remove the directories as a second pass.

   find $HOME/.local/share/Trash -type d -print

 Looks good.  Let's remove those too.  But I am likely to avoid looking
 to see if a directory should be removed and simply try to remove it
 and deal with the non-empty errors.  These are not files and were only
 created because the files were put there.  No need to look at mtime on
 the trash directories.  Just rmdir any empty directory.  Using
 rmdir is very safe because it cannot remove files.  The rmdir can
 only remove empty directories making it a quite safe command to simply
 fling out without looking.  Can only remove directories from the
 bottom up so turn on -depth.

   find $HOME/.local/share/Trash -depth -type d -exec rmdir {} +
   ...may have some errors about non-empty directories...

 Looking better.  But if a directory is not empty the GNU rmdir command
 has an option specifically for it.  Let's ignore only that case.

   find $HOME/.local/share/Trash -depth -type d -exec rmdir
 --ignore-fail-on-non-empty {} +

 And there we have the components for this type of cleanup the way I
 would do them.  (Others would undoubtedly prefer a different way.
 There is more than one way to do this.)  And so we are left with these
 two commands run one after the other to do the full clean up.

   #!/bin/sh
   # emptyTrash
   DAYS=7 #   retain for N days
   find $HOME/.local/share/Trash -type f -mtime +$DAYS -delete
   find $HOME/.local/share/Trash -depth -type d -exec rmdir
 --ignore-fail-on-non-empty {} +

 Hope that helps.
 Bob




-- 
A taste of linux = http://www.sharons.org.uk/taste/index.html
efever = http://www.efever.blogspot.com/
efever = http://sharon04.livejournal.com/
Debian Wheezy, LXDE 2 LibreOffice 3.5.4.2
Registered Linux user 334501


Re: Auto-emptying of trash.

2013-03-03 Thread Sharon Kimble
I've done some googling, and got it to work using this line 'rm -rf
/home/YOURUSERNAME/.local/share/Trash/files/*' but this just
blanket-empties the trash can without any care for retaining 7
days worth of files.

Sharon.


On 3 March 2013 23:27, Sharon Kimble skimbl...@gmail.com wrote:

 Thanks for this, and I've tried it out but its still not deleting files,
 as I output it to a txt.file which still remain empty.

 There is a programme, ported from ubuntu, called 'autotrash' in the repos.
 And although I've set it up as per its man page, but its output remains at
 zero, and not working.

 Maybe I'm going about this from the wrong end?

 Sharon.


 On 3 March 2013 22:43, Bob Proulx b...@proulx.com wrote:

 Sharon Kimble wrote:
  I'm trying to get a bash script working from a cron job that will empty
  trash of all files and directories that are older than $N [7 days in
  this case]. This partly works but is very inefficient in that it
  doesn't delete everything that is available to be deleted, just tends
  to leave stuff with no apparent reasoning.

 Very likely you are running into the problem that removing files from
 the directory causes the directory to be updated.  Because the
 directory is updated it ceases to be old enough to be aged off.  This
 leaves them around until they become old enough to be an age candidate
 again.

 Let's walk through the problem step by step.

  #!/bin/bash

 Since there are no bash features I suggest using /bin/sh the standard
 shell.  Others would say use bash features. :-)  I like standard
 better.  A preference.

  # emptyTrash.sh

 The use of a .sh on the end is frowned upon.  Sure it is a shell
 script at this instant.  But you actually have a bash script and so it
 should be called .bash instead of .sh.  But next week you might want
 to convert it to a perl script.  Two weeks after that you might want
 to convert it to a python script.  Or Ruby.  Encoding the language in
 the extension then gets in the way.  It isn't needed.  If your editor
 is a smart one, and most are these days, then it doesn't need the
 extension to know how to syntax highlight it.

  for SUBDIR in files info
  do
  echo Lookin\' in Trash/${SUBDIR}...
  find ${HOME}/.local/share/Trash/$SUBDIR  -mtime +${DAYS} -exec rm
 -vrf {} \; done

 Running 'find' and 'for' is inconsistent.  The 'find' command can do
 both.  I would have it do both.

 The \; part is the classic old legacy way of running find's -exec.
 It runs one argument per command.  That is less efficient than running
 as many arguments as possible.  The new (ten years old is still new)
 way to do this and POSIX standard is using +.  Using + will stack
 as many arguments as possible and is very efficient.

 Let's start by printing the entries and then work from there.

   find $HOME/.local/share/Trash -mtime +$DAYS -print

 Files and directories.  I would like to remove only the files first.

   find $HOME/.local/share/Trash -type f -mtime +$DAYS -print

 I would like find to remove them itself.  The -delete option was added
 to GNU find some years ago and is available in all current GNU systems.

   # Warning: This fires the -delete option and will delete those files!
   find $HOME/.local/share/Trash -type f -mtime +$DAYS -delete

 The files are gone.  Directories may be left behind.  I would like to
 remove the directories as a second pass.

   find $HOME/.local/share/Trash -type d -print

 Looks good.  Let's remove those too.  But I am likely to avoid looking
 to see if a directory should be removed and simply try to remove it
 and deal with the non-empty errors.  These are not files and were only
 created because the files were put there.  No need to look at mtime on
 the trash directories.  Just rmdir any empty directory.  Using
 rmdir is very safe because it cannot remove files.  The rmdir can
 only remove empty directories making it a quite safe command to simply
 fling out without looking.  Can only remove directories from the
 bottom up so turn on -depth.

   find $HOME/.local/share/Trash -depth -type d -exec rmdir {} +
   ...may have some errors about non-empty directories...

 Looking better.  But if a directory is not empty the GNU rmdir command
 has an option specifically for it.  Let's ignore only that case.

   find $HOME/.local/share/Trash -depth -type d -exec rmdir
 --ignore-fail-on-non-empty {} +

 And there we have the components for this type of cleanup the way I
 would do them.  (Others would undoubtedly prefer a different way.
 There is more than one way to do this.)  And so we are left with these
 two commands run one after the other to do the full clean up.

   #!/bin/sh
   # emptyTrash
   DAYS=7 #   retain for N days
   find $HOME/.local/share/Trash -type f -mtime +$DAYS -delete
   find $HOME/.local/share/Trash -depth -type d -exec rmdir
 --ignore-fail-on-non-empty {} +

 Hope that helps.
 Bob




 --
 A taste of linux = http://www.sharons.org.uk/taste/index.html
 efever = 

Re: Auto-emptying of trash.

2013-03-03 Thread Bob Proulx
Sharon Kimble wrote:
 Thanks for this, and I've tried it out but its still not deleting files, as
 I output it to a txt.file which still remain empty.

Please say more.  It works for me.  You say it isn't deleting files
for you.  It is possible the permissions will prevent you from
deleting files but in that case there should be errors from the
command.  Please provide an example.

Start with this:

  find $HOME/.local/share/Trash -type f -mtime +7

If that prints files then adding the -delete option will delete them.
Honest! :-)

You say it isn't deleting files.  Pick a file that you think it should
delete but isn't deleting.  Show the file and the permissions of the
directory holding that file.  The permissions of the directory is the
important detail about creating or deleting files.

  ls -ld $HOME/.local/share/Trash/files/foo
  ls -ld $HOME/.local/share/Trash/files

I think that there simply are not any files old enough to need to be
aged away.  I think all of the files are current.  Since they are
current they do not meet your +7 days of mtime age that you originally
requested.  A +7 mtime age for trash files seemed reasonable to me.

 There is a programme, ported from ubuntu, called 'autotrash' in the repos.
 And although I've set it up as per its man page, but its output remains at
 zero, and not working.

Probably for the same reason.  Probably because the files are all
current and none of them old enough, past your seven day threshold, to
be candidates to be aged away.

The 'find' command will be easier to debug.  I would use it first to
figure things out.  Understanding a simple command is much better than
not understanding a magical black box.

 Maybe I'm going about this from the wrong end?

You have help here on the mailing list for your problem.  If you make
good use of it then you can understand and solve your task.  There is
no need to give up so easily.  Stick to it! :-)

Bob


signature.asc
Description: Digital signature


Re: Auto-emptying of trash.

2013-03-03 Thread Sharon Kimble
Thanks, after repopulating .trash with files suitable for deleting, i was
able to test it out. And' find $HOME/.local/share/Trash -type f -mtime
+7' did find one file, which i was then able to delete by running the same
command again with '-delete' at the end.

I now see in .trash that there are two directories, one dated 8th February,
and one dated 16th February which should be eligible for deletion. Except,
if you go by its properties date, it was last accessed 3/3/13, which means
that its not deletable until the 10th. Is that correct please?


On 3 March 2013 23:54, Bob Proulx b...@proulx.com wrote:

 Sharon Kimble wrote:
  Thanks for this, and I've tried it out but its still not deleting files,
 as
  I output it to a txt.file which still remain empty.

 Please say more.  It works for me.  You say it isn't deleting files
 for you.  It is possible the permissions will prevent you from
 deleting files but in that case there should be errors from the
 command.  Please provide an example.

 Start with this:

   find $HOME/.local/share/Trash -type f -mtime +7

 If that prints files then adding the -delete option will delete them.
 Honest! :-)

 You say it isn't deleting files.  Pick a file that you think it should
 delete but isn't deleting.  Show the file and the permissions of the
 directory holding that file.  The permissions of the directory is the
 important detail about creating or deleting files.

   ls -ld $HOME/.local/share/Trash/files/foo
   ls -ld $HOME/.local/share/Trash/files

 I think that there simply are not any files old enough to need to be
 aged away.  I think all of the files are current.  Since they are
 current they do not meet your +7 days of mtime age that you originally
 requested.  A +7 mtime age for trash files seemed reasonable to me.

  There is a programme, ported from ubuntu, called 'autotrash' in the
 repos.
  And although I've set it up as per its man page, but its output remains
 at
  zero, and not working.

 Probably for the same reason.  Probably because the files are all
 current and none of them old enough, past your seven day threshold, to
 be candidates to be aged away.

 The 'find' command will be easier to debug.  I would use it first to
 figure things out.  Understanding a simple command is much better than
 not understanding a magical black box.

  Maybe I'm going about this from the wrong end?

 You have help here on the mailing list for your problem.  If you make
 good use of it then you can understand and solve your task.  There is
 no need to give up so easily.  Stick to it! :-)

 Bob




-- 
A taste of linux = http://www.sharons.org.uk/taste/index.html
efever = http://www.efever.blogspot.com/
efever = http://sharon04.livejournal.com/
Debian Wheezy, LXDE 2 LibreOffice 3.5.4.2
Registered Linux user 334501


Re: Auto-emptying of trash.

2013-03-03 Thread Bob Proulx
Sharon Kimble wrote:
 Thanks, after repopulating .trash with files suitable for deleting, i was
 able to test it out. And' find $HOME/.local/share/Trash -type f -mtime
 +7' did find one file, which i was then able to delete by running the same
 command again with '-delete' at the end.

Yay!  :-)

 I now see in .trash that there are two directories, one dated 8th February,
 and one dated 16th February which should be eligible for deletion. 

The top two directories files, and info will always be created and
those will always be new.  If those are the two you see then I would
simply leave those.  It is subdirectories that are more interesting.

 Except, if you go by its properties date, it was last accessed
 3/3/13, which means that its not deletable until the 10th. Is that
 correct please?

You say properties making me think you are using a graphical file
manager.  That's fine.  But often those make things too simple.
Usually they hide too much.  And they make it impossible to concisely
show us what you are seeing.

Instead could you show us the output using shell command line tools?
Open a terminal window and run the commands.  Then cut and paste the
output from the commands back for us to see.  Using 'ls -l' is good.
Or there are other ways such as the find -ls option.  Or 'stat'.  But
'ls -l' is good.

Really when deleting these files the access time is most interesting.
But these days many people turn atime off!  It isn't available then.
If you don't turn it off then atime might be a better choice than
mtime.

When files are put into the trashcan what timestamps (if any) are
updated?  I wonder if a file could be put in the trash and immediately
be a candidate due to having been old before and not modified when it
was put in the trashcan.  That might cause the emptytrash script to
immediately delete it.

Bob


signature.asc
Description: Digital signature


Re: Auto-emptying of trash.

2013-03-03 Thread Sharon Kimble
I'm using 'Dolphin' from KDE as my file manager, that's the only GUI'ness
in usage in this situation! :)

The 'emptytrash' script  is called at 1300 each day from cron, giving
plenty of time to leave stuff in the waste bin for future retrieval.

'atime' is not installed as its not in the wheezy repos, and when i want
to install it apt-get comes back at me saying E: Unable to locate package
atime

You give me the commands and i'll run them. ls-l didn't show  up any
mention of trash/wastebin!

Sharon.


On 4 March 2013 01:37, Bob Proulx b...@proulx.com wrote:

 Sharon Kimble wrote:
  Thanks, after repopulating .trash with files suitable for deleting, i was
  able to test it out. And' find $HOME/.local/share/Trash -type f
 -mtime
  +7' did find one file, which i was then able to delete by running the
 same
  command again with '-delete' at the end.

 Yay!  :-)

  I now see in .trash that there are two directories, one dated 8th
 February,
  and one dated 16th February which should be eligible for deletion.

 The top two directories files, and info will always be created and
 those will always be new.  If those are the two you see then I would
 simply leave those.  It is subdirectories that are more interesting.

  Except, if you go by its properties date, it was last accessed
  3/3/13, which means that its not deletable until the 10th. Is that
  correct please?

 You say properties making me think you are using a graphical file
 manager.  That's fine.  But often those make things too simple.
 Usually they hide too much.  And they make it impossible to concisely
 show us what you are seeing.

 Instead could you show us the output using shell command line tools?
 Open a terminal window and run the commands.  Then cut and paste the
 output from the commands back for us to see.  Using 'ls -l' is good.
 Or there are other ways such as the find -ls option.  Or 'stat'.  But
 'ls -l' is good.

 Really when deleting these files the access time is most interesting.
 But these days many people turn atime off!  It isn't available then.
 If you don't turn it off then atime might be a better choice than
 mtime.

 When files are put into the trashcan what timestamps (if any) are
 updated?  I wonder if a file could be put in the trash and immediately
 be a candidate due to having been old before and not modified when it
 was put in the trashcan.  That might cause the emptytrash script to
 immediately delete it.

 Bob




-- 
A taste of linux = http://www.sharons.org.uk/taste/index.html
efever = http://www.efever.blogspot.com/
efever = http://sharon04.livejournal.com/
Debian Wheezy, LXDE 2 LibreOffice 3.5.4.2
Registered Linux user 334501


Re: Auto-emptying of trash.

2013-03-03 Thread Alois Mahdal
Hello Sharon, bob and everyone!

On Mon, 4 Mar 2013 02:29:09 +
Sharon Kimble skimbl...@gmail.com wrote:
 [...] 
 'atime' is not installed as its not in the wheezy repos, and
 when i want to install it apt-get comes back at me saying E:
 Unable to locate package atime

That is expected.  atime is not a package.  atime (UNIX-ish
short for access time) is property of files/directories that
your filesystem takes care of any time a file is accessed--it
updates this field anytime the file is accessed.

You can review atime, mtime and ctime (change time) using
mentioned `stat` command:

me@here:~$ stat myfile.txt 
  File: `myfile.txt'
  Size: 6   Blocks: 8  IO Block: 4096
regular file
Device: 805h/2053d  Inode: 285632  Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/ me)   Gid:
( 1000/me)
Access: 2013-03-04 04:47:02.929754566 +0100
Modify: 2013-03-04 04:46:22.457204523 +0100
Change: 2013-03-04 04:46:22.457204523 +0100
 Birth: -
me@here:~$

However, there is at least one common exception to this
anytime.  As you might know, in UNIX, file system tree is
very often composed of multiple partitions (e.g. different
for /home than for /usr or for /var), often using different
settings on how exactly kernel behaves to them.  One common
option is to tell kernel that for particular filesystem (or
partition, if you prefer), you prefer *not* to have this
atime update done.  (Typically people do that for performance
reasons, e.g. on partitions that are designated for files for
which this information is not important.)

One way of knowing if this option is on (not sure if the most
reliable way) is running `mount` command which, if run without
arguments, shows where each filesystem is currently mounted to
which folder and which options are active.  You want to look
for noatime option:

me@here:~$ mount # shortened for readability
[...]
/dev/disk/by-uuid/f82f7997-1779-4bff-9f06-912e0019b79b on / type ext4
(rw,relatime,errors=remount-ro,user_xattr,barrier=1,data=ordered)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=2049720k)
/dev/sda9 on /var type ext4 
(rw,relatime,user_xattr,acl,barrier=1,data=ordered)
/dev/sda5 on /home type ext4 
(rw,relatime,user_xattr,acl,barrier=1,data=ordered)
/dev/sda7 on /mnt/pub type fuseblk (rw,nosuid,nodev,noatime,...)
[...]
me@here:~$

Notice the last two lines.  Partition /dev/sda5 is mounted
as /home does not have atime turned off (or noatime turned
on :)) Partition /dev/sda7, which I use as /mnt/pub *does* have
it (for whatever reason I had in mind when setting this up).

(For sake of correctness:  I was using terms partition and
filesystem kind of interchangeably.  It is not the same,
filesystem is not partition, it's something that lives on the
partition.)


 You give me the commands and i'll run them.

I do not recommend running any command without understanding it
first! :)

`rm -rf` yo mentioned in other post is *particularly* dangerous.
One typo and you could irreversibly screw up a LOT in no time!
(Remember that there's no such thing as undelete on
Linux/UNIX.)


 ls-l didn't show up any mention of trash/wastebin!

(It's typo, right? (I mean, it's `ls -l`).)

Without saying at least *where* (in what dir) you ran the
command, it is impossible to know whether the output is as
expected.  If you simply open your terminal, your shell starts
in $HOME, and since Trash is not in that folder, `ls -l` will
not mention it.  Correct.


Thanks,
aL.

-- 
Alois Mahdal


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20130304055106.2612d...@hugo.daonet.home