![]() Once you’re happy that the command works as intended, it can be wrapped in a shell script and perhaps dropped into /etc/cron.daily so that it runs every night.Ĭould this Linux Tip be improved? Let us know in the comments below. The third argument, -delete, deletes all the files that match the selection criteria. +40 specifies files last modified more than 40 days ago similarly, -3 would specify files last modified less than three days ago. The second argument, -mtime, is used to specify the “last modified” age in days of the files to search for. The first argument to the find command, /tmp/mytestdir, specifies the starting point: by default, only files in or below this directory will be acted upon. As you might expect, this deletes the files that match the selection criteria. And date with -d option which is not POSIX compatible. bin/bash Simple script to delete files older than specific number of days from FTP. Paste the below command in the Add arguments field. Type powershell in the Program/Script field. This is the same find command as before, but with -delete appended. You need to uncomment STOREDAYS6 to specify count manually. Use task scheduler to delete files older than X days Open task scheduler. Once we’ve checked which files will be selected, we can delete them: find /tmp/mytestdir -mtime +40 -delete The command above shows how to select files based on their last-modified date. Let’s start by listing all files over 40 days old: find /tmp/mytestdir -mtime +40 /tmp/mytestdir/50.txt We can use the find command to select files according to various criteria. They are what we will use to test the commands on this page. ![]() You should see that you have 50 files in that directory, dated one per day over the last fifty days. The above command will find and display the older files which are older than 30 day in the current working directory. Let’s start by creating 50 files dated yesterday, the day before, and so on for 50 days: mkdir /tmp/mytestdirįor a in $(seq 50) do touch $.txt -date="$a days ago" done When it comes to automatically deleting files, it makes sense to carry out the initial configuration in a test environment. For example, you may want to remove all mail files in a “Trash” folder older than 90 days, or all files in the Samba Recycle Bin that are older than 30 days. Sometimes it can be helpful to delete files over a certain age from a directory.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |