Linux How to..

Linux How to ,Share Knowledge

TAG : Shell Scripts Delete File on Folder older than 30 Days

Example : if you need to delete file older than 30 days ago on folder /home/test/

#Create file shell scripts
vi /root/
input line below :

โค๊ด: [Select]

#! /bin/sh
find /home/test/ -type f -mtime +30 -exec rm -f {} \; >> /root/log-delete-file-30days-ago.log

:wq! save and quit

#permission shell scripts allow root only can Read-Write-Execute
chmod 700 /root/

#command line Manual Run Shell Scripts one time.
sh /root/

#on running scripts above you can check realtime log delete with command below:
tail -f /root/log-delete-file-30days-ago.log

exit tail -f  with Ctl+c


Comments are closed.