rm folders, sub-folders and files older than one hour

rm folders, sub-folders and files older than one hour

Post by DS » Sun, 09 Mar 2003 12:47:55



Hi,

I am looking for a bash example that will delete all folders and
sub-folders including files that are older than one hour.

I tried

find foo foo/../gif -type f -a \( -size 0 -o ! -newer ??? \) -exec rm {}
\;

Of course it is not working,  "???" is unknown to me.

Thanks for the help!

 
 
 

rm folders, sub-folders and files older than one hour

Post by Just Another Use » Sun, 09 Mar 2003 13:15:35



Quote:> Hi,

> I am looking for a bash example that will delete all folders and
> sub-folders including files that are older than one hour.

> I tried

> find foo foo/../gif -type f -a \( -size 0 -o ! -newer ??? \) -exec rm {}
> \;

> Of course it is not working,  "???" is unknown to me.

> Thanks for the help!

Get current time in seconds since epoch.  (say t)
Subtract 1 hr (in seconds) from that  ( t - 3600)
Convert (t - 3600) into date in YYYYMMDDhhmmss form. (say T)
Use touch to create dummy file with timestamp T.
Run find.
Delete dummy file.

 
 
 

rm folders, sub-folders and files older than one hour

Post by William Par » Sun, 09 Mar 2003 13:18:59



> Hi,

> I am looking for a bash example that will delete all folders and
> sub-folders including files that are older than one hour.

> I tried

> find foo foo/../gif -type f -a \( -size 0 -o ! -newer ??? \) -exec rm {}
> \;

> Of course it is not working,  "???" is unknown to me.

> Thanks for the help!

What does '-size' have to do with testing for age of files?  Also, you
want to delete directories, but '-type f' tests for files.

man find        --> -type -mmin

--

Linux solution for data management and processing.

 
 
 

rm folders, sub-folders and files older than one hour

Post by DS » Sun, 09 Mar 2003 15:45:27


William,
Found it also! I had to do some more test before posting my results, if
someone else need it.

First, i create a file foo.txt and use this :

find . \( -newer foo.txt \) -print -exec rm -fr {} \;

for newer files and folders.

and this :

find . \! \( -newer foo.txt \) -print -exec rm -fr {} \;

for older files and folders.



> Hi,

> I am looking for a bash example that will delete all folders and
> sub-folders including files that are older than one hour.

> I tried

> find foo foo/../gif -type f -a \( -size 0 -o ! -newer ??? \) -exec rm {}
> \;

> Of course it is not working,  "???" is unknown to me.

> Thanks for the help!

 
 
 

rm folders, sub-folders and files older than one hour

Post by Stephane CHAZELA » Sun, 09 Mar 2003 23:07:39



> I am looking for a bash example that will delete all folders and
> sub-folders including files that are older than one hour.

> I tried

> find foo foo/../gif -type f -a \( -size 0 -o ! -newer ??? \) -exec rm {}
> \;

[...]

use zsh

rm ./**/*(.Dmh+1,.DL0)

To remove files that are either empty or are more than one hour
old.

./: to avoid problem with files starting with "-"
**/: recursively descend
*: any file
(...): qualifiers:

  (<a>,<b>): files of <a> type or <b> type
  <a>:
    .: regular files
    D: including dot files
    mh+1: whose [m]odification time, is more (+) than [1] [h]our
          in the past.
  <b>
    .: regular files
    D: including dot files
    L0: of 0 [L]ength.

If you want to remove empty directories afterwards:

rmdir ./**/*(/od) 2> /dev/null

qualifiers:
  /: only directories
  od: sorted in depth order (so that dir/subdir is removed
  before dir).

--
Stphane