Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Create a script haven’t been accessed for a week, then delete them

rajeshkumar created the topic: Create a script haven’t been accessed for a week, then delete them
Create a script for a cronjob that checks a special directory for files with the extension .tmp that haven’t been accessed for a week, then delete them. Also remove all empty directories.

#!/bin/bash

usage()
{
echo "Usage: $0 [-d Valid Directory] [-e Valid File extension] [-a Access time in a day]" 1>&2;
exit 1;
}

while getopts ":d:e:a:" o; do
case "${o}" in
d)
d=${OPTARG}
if [ ! -d "$d" ]; then
echo "Directory $d not found"
usage
fi
;;
e)
e=${OPTARG}
echo "Passed file extension is $e"
;;
a)
a=${OPTARG}
echo "Passed number of days for access is $a"
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))

# for Debug for output
echo "Directory is $d"
echo "File extension is $e"
echo "Accessed time is $a"

# Based on Inputs, this will find the specified file and delete it found accessed according to parameters
#find $d -iname "*$e" -atime -$a -type f -print0
#find /root/raj -iname "*.txt" -atime -1 -type f -print0

find $d -iname "*$e" -atime -$a -type f -print0 | xargs -0 rm -rf

# This can be used as well but xargs would be faster for large file sets.
# find $d -iname "*$e" -atime -$e -type f | exec rm {} \;

# To Remove the empty directory
find $d -type d -empty -exec rmdir {} \;

if [ -z "${d}" ] || [ -z "${e}" ] || [ -z "${a}" ]; then
usage
fi

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Chmod: Change File Permissions Recursively

Rajesh KumarI’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at Holiday…

Read More

Shell Bash Scripting: Assignment & Excercise – 14

Write a Shell Bash Script for convert Decimal Number to Binary Rajesh KumarI’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus….

Read More

Shell Bash Scripting: Assignment & Excercise – 13

Write a Shell Bash Script for test if a number being entered is a Fibonacci or not Rajesh KumarI’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and…

Read More

Shell Bash Scripting: Assignment & Excercise – 12

Write a Shell Bash Script for check if a number is prime or not Rajesh KumarI’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have…

Read More

Shell Bash Scripting: Assignment & Excercise – 11

Write a Shell Bash Script for check if a provided number is Armstrong or not Rajesh KumarI’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I…

Read More

Shell Bash Scripting: Assignment & Excercise – 10

Write a Shell Bash Script for check if a number input from standard input is odd or even Rajesh KumarI’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x