| by Arround The Web | No comments

How to Remove Files Older than XXX Days in Linux

Not everyone considers deleting the older files, which could slow down the system. Hence, it is good to delete these files to free up the storage space. If you want to delete your older files from a particular date in Linux, you can do it quickly.

However, if you don’t know how to delete these files, please read this guide thoroughly. In this guide, we will explain the different methods to find and remove files older than xxx {any date} in the Linux operating system.

Remove Files Older than XX Days in Linux

Let’s take an example where you want to delete the files which you downloaded three days ago. First, execute the following command to list all files that are modified three days ago:

find -type f -mtime +3

This command comprises some symbols and keywords which have a specific meaning. For instance:

  • find searches all the older files
  • -mtime stands for the file modification time
  • +3 shows the number of days

For deleting the text files older than three days, you can execute the following command:

find /home/user/<directory>  -mtime +3 -exec rm {} \;

Let’s break down the previous command to get the complete information about deleting the files older than a specific date.

  • The /home/user/<directory> represents the targeted directory in which you want to delete the files.
  • The -mtime +3 represents all available files older than 3 days, and mtime shows the modification time in Linux. Here, you can change the number of days according to your requirements.
  • The -exec rm {} \ represents the deletion, and it works for deleting the files mentioned in the command.

Conclusion

Linux offers a set of commands to remove the files older than the xxx date of a specific directory. This command is beneficial for removing the files and freeing up the disk space. To make your system perform better and eliminate the older files of unimportant significance, you can delete such files and expand your system’s storage. If you want to learn more about Linux, visit our official website.

Share Button

Source: linuxhint.com

Leave a Reply