Showing posts with label delete. Show all posts
Showing posts with label delete. Show all posts

Tuesday, June 16, 2020

find and delete file on server linux

how to find and delete file on server linux

#find /data/001/ -name -delete

Ref:
inux-unix-how-to-find-and-remove-files


1. Find Files Using Name in Current Directory

# find . -name tecmint.txt

./tecmint.txt








Friday, May 29, 2015

Backup, check space and delete old file backup

1.Backup file

------------------------script backup.sh---------------------------------------------------------
###mount -o username=administrator,password=xxxx //IP address/Path /mnt/backup

LISTS="/home"
BACKUPLAST=2
BACKUP_PATH="/media/Backup"

DAY_DELETE=`date -d "+%Y%m%d"`
DAY_BACKUP=`date "+%Y%m%d"`
DELETE="${BACKUP_PATH}/${DAY_DELETE}.tar.bz2"
BACKUP="${BACKUP_PATH}/${DAY_BACKUP}.tar.bz2"

if [ -s ${DELETE} ]
then
   rm -rf ${DELETE}
fi
if [ -s ${BACKUP} ]
then
   rm -rf ${BACKUP}
fi
#tar cfvz ${BACKUP} ${LISTS}
tar -jPcf ${BACKUP} ${LISTS}

--------------------------------------------------------------------------------------------------

2. Check space and send mail every day
-------------------------checkspace.sh----------------------------------------------------------
df -H >checkspace.txt
echo "Check disk space complete" | mutt -a "checkspace.txt" -s "Check disk space complete" -- email@domain.com
---------------------------------------------------------------------------------------------------

3. delete old file backp
------------------------script removeoldfilebackup.sh--------------------------------------------
find /media/Backup/ -type f -mtime +7 -name '*.bz2' -execdir rm -- {} +
ls -lt /media/Backup > listbackup.txt
echo "Delete old file backup complete" | mutt -a "listbackup.txt" -s "Delete old file backup complete" -- email@domain.com
-----------------------------------------------------------------------------------------------

* find /location/* -type f -mtime +7 -exec rm -rf {} \;
find /location/findname.log -type f -mtime +7 -exec rm -rf {} \;

4.crontab -l
0 */3 * * * /sbin/service dovecot reload
0 0 * * * /root/./backup.sh
0 4 * * * /root/./checkspace.sh
0 5 * * * /root/./removeoldfilebackup.sh