0

How can I list all files that are older than "X" hours using a python script or bash script in Centos7?

Many thx!

Alex Manea
  • 110
  • 8

2 Answers2

0

You can use the GNU find command:

find [path] -mmin +[minutes]

Example: find all the files in / older than 2 hours:

find / -mmin +120
CanciuCostin
  • 1,773
  • 1
  • 10
  • 25
0

you can use find command :

find <path> <conditions> <actions>

File type condation:

-type f            # File
-type d            # Directory
-type l            # Symlink

Access time conditions :

-atime 0           # Last accessed between now and 24 hours ago
-atime +0          # Accessed more than 24 hours ago
-atime 1           # Accessed between 24 and 48 hours ago
-atime +1          # Accessed more than 48 hours ago
-atime -1          # Accessed less than 24 hours ago (same a 0)
-ctime -6h30m      # File status changed within the last 6 hours and 30 minutes
-mtime +1w         # Last modified more than 1 week ago

Actions :

-exec rm {} \;
-print
-delete

Also you can deal with size :

-size 8            # Exactly 8 512-bit blocks 
-size -128c        # Smaller than 128 bytes
-size 1440k        # Exactly 1440KiB
-size +10M         # Larger than 10MiB
-size +2G          # Larger than 2GiB

Examples:

find . -type f ctime -6h30m # File status changed within the last 6 hours and 30 minutes

find . -type f -mtime +29 # find files modified more than 30 days ago
Mahmoud Odeh
  • 942
  • 1
  • 7
  • 19