#!/bin/bash #find only derctoris older then 10 days DIR_NAME=($(find /opt/backup/database/ -maxdepth 1 -type d -ctime +10)) for dir in "${DIR_NAME[@]}" do echo "tar -cvPf $dir.tgz $dir --remove-files" done #this will tar and remove #tar -cvf /home/roy/Desktop/test/some_dir.tgz /home/roy/Desktop/test/some_dir --remove-files