How do I delete files older than 7 days?

How do I delete files older than 7 days?

Break Down Of Command 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.

How do I delete 7 day old logs in Linux?

Explanation:

  1. find : the unix command for finding files/directories/links and etc.
  2. /path/to/ : the directory to start your search in.
  3. -type f : only find files.
  4. -name ‘*.
  5. -mtime +7 : only consider the ones with modification time older than 7 days.
  6. -execdir …

How do I delete 10 days old files in UNIX?

3 Answers

  1. ./my_dir your directory (replace with your own)
  2. -mtime +10 older than 10 days.
  3. -type f only files.
  4. -delete no surprise. Remove it to test your find filter before executing the whole command.

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

5 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 more than 10 days in Linux?

How to Delete Files Older than 30 days in Linux

  1. Delete Files older Than 30 Days. You can use the find command to search all files modified older than X days.
  2. Delete Files with Specific Extension. Instead of deleting all files, you can also add more filters to find command.
  3. Delete Old Directory Recursively.

How do I find files older than 30 days?

The above command will find and display the older files which are older than 30 day in the current working directorys….Find and delete files older than X days in Linux

  1. dot (.)
  2. -mtime – Represents the file modification time and is used to find files older than 30 days.
  3. -print – Displays the older files.

How do I delete files older than 2 days Linux?

Explanation

  1. The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above.
  2. The second argument, -mtime, is used to specify the number of days old that the file is.
  3. The third argument, -exec, allows you to pass in a command such as rm.

How do I delete files older than 180 days 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.

How do I delete the last 30 days in Unix?

How do I delete a 6 month file in Unix?

How do I delete files older than 5 days 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 delete a 1 year old file in Linux?

  1. find /path/to/files -type f -mtime +365 -delete would be easier.
  2. -delete isn’t in my aix find so I’m not accustomed to using it.
  3. find …
  4. Also, it’s a good idea to use — in case the first file name begins with a – (although you can guarantee it won’t happen if the directory passed to find doesn’t begin with a – ).

You Might Also Like