As an example, suppose you have a news site and add a few news articles every day, each containing a few images. After a while, you no longer need the news from a year ago, or your
disk space is insufficient. In this case, you may want to delete old articles and the files associated with them. If you were to do this one by one, it could take hours or even days.
To avoid spending a very long time on this operation and to be able to easily delete files on a specific date or before a specific date, it is sufficient to use the “find” command.
Example Command:
find . -type f -mtime +30 -delete
”.” : The dot refers to the directory you are currently in.
-mtime : Specifies that you will perform a time-based deletion using the find command.
+30 : The number 30 means delete all files in the directory except those from the last 30 days. You can change this value as desired.
-delete : Specifies that we will perform a file deletion operation in conjunction with the find command.
Leave a Comment
* Your comment will be published after approval.
Comments
0No comments yet. Be the first to comment!