How do I delete 7 day old logs in Linux?

How do I delete 7 days old file in Linux?

-mtime +7 : only consider the ones with modification time older than 7 days. -execdir … ; : for each such result found, do the following command in … . rm — ‘{}’ : remove the file; the {} part is where the find result gets substituted into from the previous part.

How do I remove old Linux logs?

How to clean log files in Linux

  1. Check 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. …
  2. Select the files or directories that you want to clear: …
  3. Empty the files.

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 delete a log file in Linux?

Is there a proper way to clear log files on Unix? You can simply truncate a log file using > filename syntax. For example if log file name is /var/log/foo, try > /var/log/foo as root user.

IT IS INTERESTING:  Which command is used to remove files in Linux?

How do I remove old days from a file in Linux?

If you want to delete files older than 1 day, you can try using -mtime +0 or -mtime 1 or -mmin $((60*24)) .

How do I delete 2 days old files 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 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.

Can I delete old log files?

Yes, log files can be safely deleted. Next time a log file needs to be appended to and is missing, it will be created (don’t delete the actual Logs folder itself though). Log files are always presumed transient.

How do I delete one week old files in UNIX?

You could start by saying find /var/dtpdev/tmp/ -type f -mtime +15 .

4 Answers

  1. -exec rm -f {} ; (or, equivalently, -exec rm -f {} ‘;’ ) This will run rm -f on each file; e.g., …
  2. -exec rm -f {} + …
  3. -delete.

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.

IT IS INTERESTING:  How do I make Ubuntu look like Mac Dock?

How do I delete a 6 month file in Unix?

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 you delete files older than date in Unix?

type f -newermt “YYYY-MM-DD HH:MM:SS” -delete . It saves you from having to pipe everything through xargs, and having to handle filesnames with spaces or other disruptive characters.