{"id":22446008,"url":"https://github.com/richbl/old-files-delete","last_synced_at":"2025-08-01T20:31:27.263Z","repository":{"id":20549655,"uuid":"57079046","full_name":"richbl/old-files-delete","owner":"richbl","description":"A bash script to recursively delete files older than (n) days... uses the BaT (bash template)","archived":false,"fork":false,"pushed_at":"2023-02-28T00:23:29.000Z","size":46,"stargazers_count":9,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-08-24T15:27:30.522Z","etag":null,"topics":["bash","bash-script","bash-template","cron","cron-jobs","delete","old","old-files","shell","shell-script"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/richbl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-25T21:56:22.000Z","updated_at":"2023-08-24T13:10:00.000Z","dependencies_parsed_at":"2023-01-11T20:53:24.258Z","dependency_job_id":null,"html_url":"https://github.com/richbl/old-files-delete","commit_stats":null,"previous_names":[],"tags_count":4,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richbl%2Fold-files-delete","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richbl%2Fold-files-delete/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richbl%2Fold-files-delete/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richbl%2Fold-files-delete/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/richbl","download_url":"https://codeload.github.com/richbl/old-files-delete/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228402307,"owners_count":17914243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","bash-script","bash-template","cron","cron-jobs","delete","old","old-files","shell","shell-script"],"created_at":"2024-12-06T03:17:59.157Z","updated_at":"2024-12-06T03:17:59.867Z","avatar_url":"https://github.com/richbl.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Old-Files-Delete\n**Old-Files-Delete** (`old_files_delete.sh`) is a [bash](https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29) script to recursively delete files older than (n) number of days.\n\n`run_old_files_delete.sh` is a related script intended to be used for making unattended script calls into `old_files_delete.sh` (*e.g.*, running cron jobs).\n\n## [Developed with a Bash Template (BaT)](https://github.com/richbl/a-bash-template)[\u003cimg src=\"https://user-images.githubusercontent.com/10182110/145758715-b127adfc-710b-49d3-9ede-151adc83ae76.png\" width=\"150\" /\u003e](https://github.com/richbl/a-bash-template)\n\n**Old-Files-Delete** uses a Bash shell template (BaT) called **[A-Bash-Template](https://github.com/richbl/a-bash-template)** designed to make script development and command line argument management more robust, easier to implement, and easier to maintain. Here are a few of those features:\n\n- Dependencies checker: a routine that checks all external program dependencies (*e.g.*, [jq](https://stedolan.github.io/jq/))\n- Arguments and script details--such as script description and syntax--are stored in the [JSON](http://www.json.org/) file format (*i.e.*, `config.json`)\n- JSON queries (using [jq](https://stedolan.github.io/jq/)) handled through wrapper functions\n- A script banner function automates banner generation, reading directly from `config.json`\n- Command line arguments are parsed and tested for completeness using both short and long-format argument syntax (*e.g.*, `-f|--font`)\n- Optional command line arguments are permissible and managed through the JSON configuration file\n- Template functions organized into libraries (see the [Bash-Lib](https://github.com/richbl/bash-lib) project for details) to minimize code footprint in the main script\n\nFor more details about using a bash template, [check out the BaT sources here](https://github.com/richbl/a-bash-template).\n\n## Requirements\n\n- An operational [Bash](https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29) environment (Bash 5.1.8 used during development)\n- One additional external program:\n  - [jq](https://stedolan.github.io/jq/), for parsing the `config.json` file\n\nWhile this package was initially written and tested under Linux (Ubuntu 21.10), there should be no reason why this won't work under other shells or Unix-like operating systems that support the `gsettings` application.\n\n## Basic Usage\n**Old-Files-Delete** is run through a command line interface, so all of the command options are made available there.\n\nHere's the default response when running `old_files_delete.sh` with no arguments:\n\n    $ ./old_files_delete.sh\n\n    |\n    |  A bash script to recursively delete files older than (n) days\n    |    1.2.0\n    |\n    |  Usage:\n    |    old_files_delete.sh -d directory -n days_ago\n    |\n    |  -d, --directory           file directory\n    |  -n, --days_ago            last modified (n) or more days ago\n    |  -f, --file_pattern_match  OPTIONAL: file pattern to match ('*.jpg')\n    |\n\n    Error: directory argument (-d|--directory) missing.\n    Error: days ago argument (-n|--days_ago) missing.\n\nIn this example, the program responds by indicating that the required script arguments must be set before proper operation.\n\nWhen arguments are correctly passed, the script provides feedback on the success or failure of the script actions:\n\n    $ ./old_files_delete.sh -d ~/desktop -n 6\n\n    |\n    |  A bash script to recursively delete files older than (n) days\n    |    1.2.0\n    |\n    |  Usage:\n    |    old_files_delete.sh -d directory -n days_ago\n    |\n    |  -d, --directory           file directory\n    |  -n, --days_ago            last modified (n) or more days ago\n    |  -f, --file_pattern_match  OPTIONAL: file pattern to match ('*.jpg')\n    |\n\n    Deleting old files...\n\n    Success.\n\nAlso, using the optional `-f` flag, **Old-Files-Delete** can be run to filter filenames, so file deletes can be specifically pattern matched ([globbing](https://en.wikipedia.org/wiki/Glob_(programming))). For example, if the use case is to delete files in `/home/user/pics` older than 10 days, but only to delete jpg images files, then the following script would be run:\n\n    $ ./old_files_delete.sh -d ~/pics -n 10 -f '*.jpg'\n\n    |\n    |  A bash script to recursively delete files older than (n) days\n    |    1.2.0\n    |\n    |  Usage:\n    |    old_files_delete.sh -d directory -n days_ago\n    |\n    |  -d, --directory           file directory\n    |  -n, --days_ago            last modified (n) or more days ago\n    |  -f, --file_pattern_match  OPTIONAL: file pattern to match ('*.jpg')\n    |\n\n    Deleting old files...\n\n    Success.\n\n## Automation with Cron\n\nPerhaps the most powerful use case for **Old-Files-Delete** is the automated, regular execution of this script using a job scheduler such as [cron](https://en.wikipedia.org/wiki/Cron). **Old-Files-Delete** can be installed, a cron job created and saved, and then promptly forgotten: cron will periodically run the script, removing old files as they go out of date.\n\nThe example below represents my own cron job set to run nightly at 00:15 on my Raspberry Pi devices configured as surveillance cameras running the [Distributed-Motion-Surveillance](https://github.com/richbl/distributed-motion-surveillance) project:\n\n\t# run periodic file delete on motion image files\n\t15 0 * * * /bin/bash /home/pi/dev/old-files-delete/run_old_files_delete.sh\n\nAs configured, I no longer have to worry about motion-captured image files (jpg and avi files) getting generated over time, and eventually consuming available disk space on my IoT device.\n\n## IMPORTANT: This Project Uses Git Submodules \u003cpicture\u003e\u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://user-images.githubusercontent.com/10182110/208980142-08d4cf6e-20ac-4243-ac69-e056258b0315.png\" width=\"150\"\u003e\u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://user-images.githubusercontent.com/10182110/208980142-08d4cf6e-20ac-4243-ac69-e056258b0315.png\" width=\"150\"\u003e\u003cimg src=\"https://user-images.githubusercontent.com/10182110/208980142-08d4cf6e-20ac-4243-ac69-e056258b0315.png\" width=\"150\"\u003e\u003c/picture\u003e\n\nThis project uses [Git submodule project(s)](https://git-scm.com/book/en/v2/Git-Tools-Submodules) (located in the `bash-lib` folder) to keep this project up-to-date without manual intervention.\n\n**Be sure to clone this project with the `--recursive` switch** (`git clone --recursive https://github.com/richbl/this_project`) so any submodule project(s) will be automatically cloned as well. If you clone into this project without this switch, you'll likely see empty submodule project folders (depending on your version of Git).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichbl%2Fold-files-delete","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frichbl%2Fold-files-delete","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichbl%2Fold-files-delete/lists"}