Prerequisites: VM/ Physical – It is recommended to have the time server as a physical server, but VMs should be okay depending on your setup and requirement. My virtual lab environment is VMware based so here’s the guide for a VM. Once the CentOS Minimal is installed on the VM make sure to install open-vm-tools….
Tag: 7
Delete Files and Folders Older Than X Days
Often times admin have to creates tasks like removing log files or some other files on a regular schedule. Here is an automated way of removing files / folders older than X days. Create a Batch file or Powershell script and add it to scheduled task. Batch File:
1 2 3 4 5 6 7 8 9 10 11 12 |
@echo off :: set folder path set dump_path=c:\shares\dump :: set min age of files and folders to delete set max_days=7 :: remove files from %dump_path% forfiles -p %dump_path% -m *.* -d -%max_days% -c "cmd /c del /q @path" :: remove sub directories from %dump_path% forfiles -p %dump_path% -d -%max_days% -c "cmd /c IF @isdir == TRUE rd /S /Q @path" |
Powershell:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# set folder path $dump_path = "C:\shares\dump" # set min age of files $max_days = "-7" # get the current date $curr_date = Get-Date # determine how far back we go based on current date $del_date = $curr_date.AddDays($max_days) # delete the files Get-ChildItem $dump_path -Recurse | Where-Object { $_.LastWriteTime -lt $del_date } | Remove-Item |
How to Start and Enable Firewalld on CentOS 7
It is highly recommended that you have a firewall protecting your server. Pre-Flight Check These instructions are intended specifically for enabling and starting firewalld CentOS 7. I’ll be working from a Liquid Web Self Managed CentOS 7 server, and I’ll be logged in as root. Check the Status of Firewalld To check the status of…