hiltactive.blogg.se

Bash delete files older than 30 days
Bash delete files older than 30 days













bash delete files older than 30 days
  1. #BASH DELETE FILES OLDER THAN 30 DAYS HOW TO#
  2. #BASH DELETE FILES OLDER THAN 30 DAYS FREE#

tmp files older than 7 days run the following command: forfiles /p "C:\Users\User\AppData\Local\Temp" /s /m *.tmp /d -7 /c "cmd /c del Method 2 - PowerShell We can filter files by specific extension. /c - specifies command to run it on each file.The *.* means to find all files regardless of the file extension. /s - find all files in the specified directory and all subdirectories.For example, to find files older than 7 days run the following command: forfiles /p "C:\Users\User\AppData\Local\Temp" /s /m *.* /d -7 /c "cmd /c echo confirmed, specify the del command instead of echo to delete files: forfiles /p "C:\Users\User\AppData\Local\Temp" /s /m *.* /d -7 /c "cmd /c del meaning of parameters that used in forfiles command: The most voted solution here is missing -maxdepth 0 so it will call rm -rf for every subdirectory, after deleting it. Havent tried, someone may confirm in comments. Before deleting files, we can print them. find supports -delete operation, so: find /base/dir/ -ctime +10 -delete I think theres a catch that the files need to be 10+ days older too. The forfiles command allows to select files and run another command on these files.

#BASH DELETE FILES OLDER THAN 30 DAYS HOW TO#

This tutorial shows how to delete files older than X days on Windows.

bash delete files older than 30 days bash delete files older than 30 days

I use filename because they are for backups so they would look like this:. It can be backup files, log files, and other temporary files. I use one to delete backups older than 10 days and it looks something like this: 50 17 find /path/to/files/filename -type f -mtime +10 xargs rm. On of them to delete old files which are no longer needed after a certain period of time.

#BASH DELETE FILES OLDER THAN 30 DAYS FREE#

There are various ways to free up disk space on the system. The find command also supports the -delete action to remove the matching files: find logs/ -regex.















Bash delete files older than 30 days