-mtime +30 : This refers to all the files which are older than 30 days. mtime stands for Modification time in Unix. You can change the number based on your requirement. -exec rm {} : This is actually the execution command which calls for deletion of all the files filtered by all the above criteria.
How do I remove 30 days old files in UNIX?
How to Delete Files Older than 30 days in Linux
- Delete Files older Than 30 Days. You can use the find command to search all files modified older than X days. …
- Delete Files with Specific Extension. Instead of deleting all files, you can also add more filters to find command. …
- Delete Old Directory Recursively.
How do I delete old files in UNIX?
3 Answers
- ./my_dir your directory (replace with your own)
- -mtime +10 older than 10 days.
- -type f only files.
- -delete no surprise. Remove it to test your find filter before executing the whole command.
How do I delete old files in Linux?
Delete Files Older Than x Hours on Linux
- Delete files older than 1 Hour. find /path/to/files * -mmin +60 – exec rm {} ;
- Delete files older than 30 days. find /path/to/files * -mtime +30 – exec rm {} ;
- Delete files modified in the last 30 minutes.
How do I delete a 3 month file in Linux?
As before, the -mtime parameter is used to find files older than X. In this case, it’s older than 180 days. You can either use the -delete parameter to immediately let find delete the files, or you can let any arbitrary command be executed ( -exec ) on the found files.
Where are 2 days old files Linux?
4 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.
Where is the last 30 days file in Linux?
You can also search the files modified before X days. Use -mtime option with the find command to search files based on modification time followed by the number of days. Number of days can be used in two formats.
How do I find files older than 7 days UNIX?
Explanation:
- find : the unix command for finding files/directories/links and etc.
- /path/to/ : the directory to start your search in.
- -type f : only find files.
- -name ‘*. …
- -mtime +7 : only consider the ones with modification time older than 7 days.
- -execdir …
How do I delete 5 days old files in Linux?
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 you nullify a file?
log in the following examples.
- Empty File Content by Redirecting to Null. …
- Empty File Using ‘true’ Command Redirection. …
- Empty File Using cat/cp/dd utilities with /dev/null. …
- Empty File Using echo Command. …
- Empty File Using truncate Command.
How do I delete 15 days old files in UNIX?
Unix – Delete files older than a certain number of days using…
- 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.
How do I list old files in Linux?
To find files that are at least 24 hours old, use -mtime +0 or (m+0) . If you want to find files that were last modified yesterday or before, you can use find with the -newermt predicate: find -name ‘*2015*’ !
How do I delete a file before a certain date in Linux?
How to delete all files before a certain date in Linux
- find – 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.