Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers ls
# 1  
Old 08-16-2002

Hi all,
Is there a command ( or a set of pipped commands) in which I can specify all the files in specifed directory that are older than (for example) one year?
# 2  
Old 08-16-2002
You can use the -mtime option of find


find /usr/data -name "*" -mtime +365 -print

will find all files in /usr/data (& subdirectories) that were last modified over 365 days ago.
# 3  
Old 08-16-2002
Thank you very much for your valuable help...
Is there a way to move the file to another directory using the same commadn?
Thanks again
# 4  
Old 08-16-2002
Read the Man Page - the find command has the means to grab the files and move them, delete them, or rename them.

Part of the man page -

Remove all files in your home directory named a.out or *.o
that have not been accessed for a week:

example% find $HOME \( -name a.out -o -name '*.o' \) \
-atime +7 -exec rm {} \;

Note the last portion - -exec rm - you can change that to what you need. Practice on a test directory until you understand it. When I first started in UNIX (from VAX/VMS) my new boss had me write a script to rename soft links to hard links. I killed my test system one time because I forgot the \; on the end (or messed it up somehow). Anyway, his whole point was to teach me UNIX does not forgive - you tell it to do something screwy, it will.
# 5  
Old 08-16-2002

Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question