![]() ![]() Still in case you have questions, please feel free to get in touch with me. Would suggest you to try playing with the combinations on your own to deepen the understanding. If you want to delete files older than 1 day, you can try using -mtime 0 or - mtime 1 or - mmin $((60*24)). Rather to explain it further, it simply says to match files modified two or more days ago. So, when you specify -mtime 1, it looks for files older more than 1 day. Important point to note in the above statement is that the fractional part is always ignored. In the descriptions, wherever n is used as a primary argument, it shall be interpreted as a decimal integer optionally preceded by a plus ( ‘ ’ ) or minus-sign ( ‘-‘ ) sign, as follows: n More than n. mtime n The primary shall evaluate as true if the file modification time subtracted from the initialization time, divided by 86400 (with any remainder discarded), is n. The POSIX specification for find command states that : ![]() rm stands to remove in Unix.Īlthough it is a very simple command, still I want you understand the usage of mtime in find command in a little more detail. LastWrite (get-date).AddDays(-x) date(Get-Date). Unix find command is used to achieve the desired result.įind /path/to/the/directory/ -type f -name '*' -mtime 30 -exec rm \ : This is actually the execution command which calls for deletion of all the files filtered by all the above criteria. Replace x with the number of days before which the files have to be compressed. Recently I came across one such requirement of deleting files older than X days from a directory in Unix server and I thought of sharing the solution with you. It comes up with multiple options which when gets handy can help you cover a lot of functional requirements like moving files among directories, deleting old files, archiving files etc. find command is more powerful than you can really imagine. In order to delete files older than X number of days, try using Unix find command. In this simple tutorial, we’ll quickly look at the solution to this problem. ![]() The best way to achieve is to have a cron job or an autosys job which will delete the older log files from the directory. In Production server, there is always a need to free up the disk space from time to time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |