Question: How Do I Find Files Older Than 30 Days Unix?

How do I delete files older than 30 days Linux?

How to Delete Files Older than 30 days in LinuxDelete Files older Than 30 Days.

You can use the find command to search all files modified older than X days.

And also delete them if required in single command.

Delete Files with Specific Extension.

Instead of deleting all files, you can also add more filters to find command..

How do I delete files older than 7 days?

Here we used -mtime +7 to filter all files which are older than 7 days. Action -exec: this is generic action, which can be used to perform any shell command on each file which is being located. Here use are using rm {} \; Where {} represents the current file, it will expand to the name/path of found file.

How do I find files older than 5 days in Unix?

The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days. The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.

How do I find files older than 1 year in Unix?

/path/to/files* is the path to the files to be deleted. -mtime is used to specify the number of days old that the file is. +365 will find files older than 365 days which is one year. -exec allows you to pass in a command such as rm.

How do I delete the last 30 days in Unix?

mtime +30 -exec rm {} \;Save the deleted files to a log file. find /home/a -mtime +5 -exec ls -l {} \; > mylogfile.log. … modified. Find and delete files modified in the last 30 minutes. … force. force delete temp files older then 30 days. … move the files.

Where are files older than 30 days Linux?

Find and Delete Files Older Than X Days In Linuxdot (.) – Represents the current directory.-mtime – Represents the file modification time and is used to find files older than 30 days.-print – Displays the older files.

How do I delete files older than a certain date in Linux?

How to delete all files before a certain date in Linuxfind – the command that finds the files.. – … -type f – this means only files. … -mtime +XXX – replace XXX with the number of days you want to go back. … -maxdepth 1 – this means it will not go into sub folders of the working directory.-exec rm {} \; – this deletes any files that match the previous settings.

Where is the 10 day old file in Unix?

3 Answers. You could start by saying find /var/dtpdev/tmp/ -type f -mtime +15 . This will find all files older than 15 days and print their names. Optionally, you can specify -print at the end of the command, but that is the default action.

How do I delete old Linux logs?

How to clean log files in LinuxCheck the disk space from the command line. Use the du command to see which files and directories consume the most space inside of the /var/log directory. … Select the files or directories that you want to clear: … Empty the files.

How do I delete a directory more than 30 days in Unix?

You should use the command -exec rm -r {} \; and add the -depth option. The -r option to rm remove directories with all the content.