Re: [Hampshire] Finding files not used in the last 365 days …

Top Page
Author: Andy Smith
Date:  
To: hampshire
Subject: Re: [Hampshire] Finding files not used in the last 365 days - Adifferent idea using tar

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x58248100.hantslug.org.uk.18210': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Mon May 21 16:46:40 2007 BST
gpg: using DSA key 2099B64CBF15490B
gpg: Can't check signature: No public key
On Mon, May 21, 2007 at 04:04:58PM +0100, Brian Chivers wrote:
> Andy Smith wrote:
> >Hi Brian,
> >
> >On Mon, May 21, 2007 at 11:25:07AM +0100, Brian Chivers wrote:
> >>I've been playing with all the options and it would appear that the user
> >>who has created the files likes to use STUPID characters like brackets in
> >>her filenames :-/ and this is causing the script to error out at random
> >>points so I've been having a rethink.
> >
> >Does what I suggested in:
> >
> >        http://www.hants.lug.org.uk/lurker/message/20070508.120756.ee622777.en.html

> >
> >not work?
> >
> Not tried it yet, trying to get my mind round what each of the bits does.


Okay,

find /path -type f -atime +365 -print0 | xargs -0 tar pcf - | (cd /target && tar pxvf -)

find /path -type f -atime +365

        Find files whose last *access time* was more than 365 days
        ago.  If you prefer to use your mtime rule as before then do
        that instead.  -atime's not going to work if the filesystem
        is munted noatime, either.


-print0

        Print the names of the above files delimited by ascii NUL
        characters.  This allows the filenames/paths to contain
        anything, so solves your problem of things like spaces,
        brackets, or other shell metacharacters.


| xargs -0


        Pipe that list of paths through xargs -0, which takes a list
        of NUL-separated things and passes them to a command..


tar pcf -

        The tar command will compress (-c) the list of files it gets
        from xargs, preserving permissions (-p), and it will write
        out a tar archive to its standard output (-f -).


| (cd /target && tar pxvf -)


        The standard output of the previous tar gets piped through
        this subshell, which changes directory to your target, and
        runs another tar to extract (-x) its standard input (-f -)
        verbosely (-v) preserving permissions (-p).


        Could probably also be done as just:


                tar -C /target pxvf -


        but I'm set in my ways..


Hope that makes more sense.

Cheers,
Andy

--
http://bitfolk.com/ -- No-nonsense VPS hosting
Encrypted mail welcome - keyid 0x604DE5DB

My words are my own and do not represent Jacqui Caren.