Garl, not the final script, just some related ideas.
In case you don't just want to move those old files, but rather archive
and/or compress them the tar program may come handy -- it takes care of
DIR structure and compression.
# substitute 'somePath' with relative or absolute path.
# make a file list:
find somePaths -name '*' -mtime -10 -exec ls {} > older10d.ls \;
# tar it up and compress:
tar -czf optPath/older10d.tgz -C older10d.ls
# remove those files:
find somePaths -name '*' -mtime -10 -exec rm {} \;
### Note, the timestamp of involved DIRs got changed after this -
### - i.e. just repeating the commands may mean something different now.
### do some cleanup (older10d.ls ...)
### check 'man tar' for other options
This is not a clip&paste script, rather a pseudo code idea --however,
(briefly) tested on a real tempDir of my system.
Good luck .................................. Horst, onDigest
On Monday 11 March 2002 18:50, Grigsby, Garl wrote:
> I have a question on a shell script I am trying to piece together
> (and it must be a shell script. I am trying to find time to learn
> Perl, but at this point it looks to me like a cat walked across a
> keyboard....). I need to go through a directory and move any file
> older than 10 days. How do I go about this? I know that I can get the
> date from 'ls -l', but I don't know how to use this in a comparison?
> I know that I could probably come up with a really (really) ugly set
> of logic statements, but there has got to be an easier way. Anybody
> want to share their thoughts/ideas? Please?
A start would be with the find command. To find all files in your home
directory modified within the last 10 days and do an "ls -l" on them:
find ~ -mtime +10 -exec ls -l {} \;
The "+10" is for more than 10 days ("-10" would be for less than 10
days), the {} will be replaced by each file found. The escaped ";"
ends the parameter list to find.
Change the "ls -l" to whatever command you like. However, moving files
in subdirectories to corresponding target subdirectories will take a
bit of finesse. You may want to use a function that parses the file
name and makes non-existant subdirs before doing the move.
I bet someone here has a really clever way of doing that. ;)