Hi:-
I need help with a script I need to modify: - what's the best/easiest way to find out the oldest file in a directory and then move this file to another directory?
Thanks,
Hi:-
I need help with a script I need to modify: - what's the best/easiest way to find out the oldest file in a directory and then move this file to another directory?
Thanks,
in the sense
are u referring to the
usage time of the file (or)
modified time ?
then use,
ls -lurt
or
ls -lrt
oldest_file=`ls -1 -t /path/to/directory/* | head -1`
Hi JIM,
if you put the command (ls -l -t | head -2) it will return the latest file in the partcular dir
if you want retreive the oldest file in the dir, you can use the below command
$ ls -gt | tail -1
Thanks.
ls -lrt | head -2
mv `ls -tr |tail -1` newdirname