Find out if file has changed

前端 未结 3 1752
耶瑟儿~
耶瑟儿~ 2021-02-05 18:14

I want to find out if a file has been modified since the last time my shell script was started, maybe by creating a boolean or something... Maybe it would be possible to save th

3条回答
  •  梦谈多话
    2021-02-05 18:57

    kev's solution in Python, works if you have permissions to touch the script:

    #!/usr/bin/python 
    import os
    import sys
    
    files= ('a.txt', 'b.txt')
    me= sys.argv[0]
    mytime= os.path.getmtime(me)
    for f in files:
        ft= os.path.getmtime(f)
        if ft > mytime:
            print f, "changed"
    os.utime(me, None)
    

提交回复
热议问题