Using find command with awk or basename

Hi,
I am using the following command to extract any log files that are older than 3 days using the following command.

find DIR/LOGDIR -type f -mtime +3 |grep LOG > log_list.out
The results are
DIR/LOGDIR/1.LOG
DIR/LOGDIR/2.LOG
DIR/LOGDIR/3.LOG
DIR/LOGDIR/4.LOG

How do inculde (basename or awk ??) to extract just the file name instead of the complete directory like in log_list.out file.
1.LOG
2.LOG
3.LOG
4.LOG

Thanks all.

You can do something like that :

find DIR/LOGDIR -type f -mtime +3 -name '*LOG*' | sed 's_.*/__'  > log_list.out

Jean-Pierre.

Great..
Thanks again..

You could also do this:

find DIR/LOGDIR -type f -mtime +3 -name '*LOG*' -exec basename {} \;

but this runs "basename" for each file. The "sed" command above is probably several hundred milliseconds faster. :slight_smile:

if you have GNU find

find /path -type f -mtime +3 -name '*LOG*'  -printf "%f\n"