annaadvertising.blogg.se

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 archive#
  3. Bash delete files older than 30 days full#

Find & delete find /path/to/files/ -type f -name '*.tar.gz' -mtime +30 -exec rm \ Ībove shell script will work on most of the Linux distributions.

Bash delete files older than 30 days archive#

Put the ' to avoid the substituted file/directory name to be interpreted by the shell, just like we protect the semicolon with a backslash.In this article we are going to find older files and then archive and delete after certain days.įor this to achieve we will be using certain linux bash commands mentioned below in details. We’ll use this in order to figure out what files are older than a certain number of days, and then use the rm command to delete them. Did you mean /path/to/files/ or are you expecting the wildcard to expand to several file and folder names? I know I can list all files with ls in a the folder containing the files. 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 YMD.ext 20190430.txt.

Bash delete files older than 30 days how to#

To launch File Explorer, press Win + E on your keyboard and find the. Delete all files older than 30 days, based on file name as date. Here I am going to tell you how to delete backup files older than 30 days through bash scripts or command line, which help to save your system, server space &.

bash delete files older than 30 days

You'd need rm -r for that.Īlso, /path/to/files* is confusing. Delete files older than 30 days with Task Scheduler is the simplest way for novice users. I wonder how the command would have removed a folder, since you can't remove a folder with rm only. maxdepth 0 would not recurse into subdirectories. mtime - Indicates the file modification time and is used to find files older than 30 days. Here, dot (.) - Indicates the current directory. For example, -maxdepth would allow you to only restrict the found items to a specific depth, e.g. -mtime +30 -print The above command will find and display the older files which are older than 30 day in the current working directory. I use filename because they are for backups so they would look like this:. You might want to read man find, as there are some more options you could need in the future. 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. The first argument is the path to files which can be files, directories or even wildcard characters. Use -type d for the inverse, only listing directories that match your arguments. Let us look at the above command in detail. That would only run on files, not directories.

Bash delete files older than 30 days full#

Leave out -delete to show what it'd delete, and once you've verified that, go ahead and run the full command.

bash delete files older than 30 days

find has options to read files creation ( ctime ), access ( atime ) and modification ( mtime ). crontab -e 0 7 /bin/bash /opt/script/delete-old-folders.sh You will get an output like the one below.

bash delete files older than 30 days

chmod +x /opt/script/delete-old-folders.sh Finally add a cronjob to automate this. find /path/to/files -type f -mtime +10 -delete Delete all files older than 30 days, based on file name as date Ask Question Asked 4 years ago Modified 1 year, 2 months ago Viewed 18k times 3 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 YMD.ext 20190430.txt. Sometimes, you may need to delete files older than x days. Set an executable permission to delete-old-folders.sh file.

bash delete files older than 30 days

Find accepts the type option for selecting, for example, only files.






Bash delete files older than 30 days