I'm new to bash, I have a task to delete all files older than 30 days, I can figure this out based on the files name Y_M_D.ext
2019_04_30.txt
.
I know I can list all files with ls
in a the folder containing the files. I know I can get todays date with $ date
and can configure that to match the file format $ date "+%Y_%m_%d"
I know I can delete files using rm
.
How do I tie all this together into a bash script that deletes files older than 30 days from today?
In pseudo-python code I guess it would look like:
for file in folder:
if file.name to date > 30 day from now:
delete file
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…