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/delete-file-30days-ago.sh
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/delete-file-30days-ago.sh

#command line Manual Run Shell Scripts one time.
sh /root/delete-file-30days-ago.sh

#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

Success!!!

Comments are closed.