![]() ![]() ![]() 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. This is the same find command as before, but with -delete appended. ![]() 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. If you don’t see the Search tab, click once in the search box and it should appear. Switch to the Search tab, click the Date Modified button, and then select a range. They are what we will use to test the commands on this page. How do I search files by date modified File Explorer has a convenient way to search recently modified files built right into the Search tab on the Ribbon. You should see that you have 50 files in that directory, dated one per day over the last fifty days. 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. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |