Deleting older log files

Ravi

There are some log files created after a certain amount of time with the time stamp.

/mylog/path
Log_file_2018-07-19-22-55-31Z.tgz
Log_file_2018-07-20-01-29-11Z.tgz
Log_file_2018-07-20-10-36-49Z.tgz
Log_file_2018-07-21-18-26-36Z.tgz

I need to delete older logs based on date. For example, I want only last 5 days logs and older logs should be deleted. Num of log files created daily varies. How to achieve this?

Siva

You can do with mtime (modified time) in find command.

 find /mylog/path -mindepth 1 -mtime +5 -delete
  • -mindepth 1 means process all files except the command line arguments.
  • -mtime +5 will check for the files modified 5 days ago.
  • -delete will delete

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Error deleting older kernel package

분류에서Dev

Files getting reverted to older version

분류에서Dev

Android 4.4.2 not deleting files

분류에서Dev

excessive creating and deleting files disadvantages

분류에서Dev

Finding and deleting files with a specific date

분류에서Dev

Find all files older than one minute

분류에서Dev

Find Files (Strictly) Older than Another File

분류에서Dev

Uploading/Deleting files from a database in Django

분류에서Dev

tmpfs — deleting files won't free the space

분류에서Dev

Deleting files except if the name contains a substring

분류에서Dev

Deleting Files from CMD or Powershell and Recycle Bin

분류에서Dev

Where are the postfix log files?

분류에서Dev

How to list files older than a day with "2015" in filename?

분류에서Dev

Powershell script to delete files older than x days, but not folders

분류에서Dev

Accidentally deleted all files older than 7 days

분류에서Dev

use powershell to copy files and folders to archive folder older 30 minutes

분류에서Dev

Mac OSX 10.7.5 deleting files, files still in Time Machine

분류에서Dev

why the second log files on /var/log are not compressed

분류에서Dev

How can I implement Deleting files to the Recycle bin rather than Permanently deleting?

분류에서Dev

Break up large log files

분류에서Dev

Deleting all old files after rebuilding world on FreeBSD

분류에서Dev

ext4 disk space not reclaimed after deleting files

분류에서Dev

Uploading multiple files with iOS SDK and deleting them locally when done

분류에서Dev

What is the command to reset a Windows installation without deleting any files

분류에서Dev

Trying to script deleting files from wildcards in a text file

분류에서Dev

Trying to script deleting files from wildcards in a text file

분류에서Dev

How to delete all files that match a pattern (or older than..) except the newest file that matches the pattern?

분류에서Dev

How can I view diffs or at least older versions of specific files with etckeeper?

분류에서Dev

log4j - Configure RollingFileAppender for backup log files as DailyRollingFileAppender

Related 관련 기사

  1. 1

    Error deleting older kernel package

  2. 2

    Files getting reverted to older version

  3. 3

    Android 4.4.2 not deleting files

  4. 4

    excessive creating and deleting files disadvantages

  5. 5

    Finding and deleting files with a specific date

  6. 6

    Find all files older than one minute

  7. 7

    Find Files (Strictly) Older than Another File

  8. 8

    Uploading/Deleting files from a database in Django

  9. 9

    tmpfs — deleting files won't free the space

  10. 10

    Deleting files except if the name contains a substring

  11. 11

    Deleting Files from CMD or Powershell and Recycle Bin

  12. 12

    Where are the postfix log files?

  13. 13

    How to list files older than a day with "2015" in filename?

  14. 14

    Powershell script to delete files older than x days, but not folders

  15. 15

    Accidentally deleted all files older than 7 days

  16. 16

    use powershell to copy files and folders to archive folder older 30 minutes

  17. 17

    Mac OSX 10.7.5 deleting files, files still in Time Machine

  18. 18

    why the second log files on /var/log are not compressed

  19. 19

    How can I implement Deleting files to the Recycle bin rather than Permanently deleting?

  20. 20

    Break up large log files

  21. 21

    Deleting all old files after rebuilding world on FreeBSD

  22. 22

    ext4 disk space not reclaimed after deleting files

  23. 23

    Uploading multiple files with iOS SDK and deleting them locally when done

  24. 24

    What is the command to reset a Windows installation without deleting any files

  25. 25

    Trying to script deleting files from wildcards in a text file

  26. 26

    Trying to script deleting files from wildcards in a text file

  27. 27

    How to delete all files that match a pattern (or older than..) except the newest file that matches the pattern?

  28. 28

    How can I view diffs or at least older versions of specific files with etckeeper?

  29. 29

    log4j - Configure RollingFileAppender for backup log files as DailyRollingFileAppender

뜨겁다태그

보관