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. ;)