zoukankan      html  css  js  c++  java
  • linux 对文件的时间atime,mtime进行修改

    As long as you are the owner of the file (or root), you can change the modification time of a file using the touch command:

    touch filename
    

    By default this will set the file's modification time to the current time, but there are a number of flags, such as the -d flag to pick a particular date. So for example, to set a file as being modified two hours before the present, you could use the following:

    touch -d "2 hours ago" filename
    

    If you want to modify the file relative to its existing modification time instead, the following should do the trick:

    touch -d "$(date -R -r filename) - 2 hours" filename
    

    If you want to modify a large number of files, you could use the following:

    find DIRECTORY -print | while read filename; do
        # do whatever you want with the file
        touch -d "$(date -R -r "$filename") - 2 hours" "$filename"
    done
    

    You can change the arguments to find to select only the files you are interested in. If you only want to update the file modification times relative to the present time, you can simplify this to:

    find DIRECTORY -exec touch -d "2 hours ago" {} +
    

    This form isn't possible with the file time relative version because it uses the shell to form the arguments to touch.

    As far as the creation time goes, most Linux file systems do not keep track of this value. There is a ctime associated with files, but it tracks when the file metadata was last changed. If the file never has its permissions changed, it might happen to hold the creation time, but this is a coincidence. Explicitly changing the file modification time counts as a metadata change, so will also have the side effect of updating the ctime.

    而我使用的命令如下:

    find DIRECTORY | xargs touch -d "2 hours ago"

  • 相关阅读:
    多线程中的wait与sleep到底谁释放了锁?
    Java并发编程:volatile关键字解析
    Spring的bean为什么是单例的?
    Java学习之反射
    Http && Https(绕过证书) 请求工具类 (Java)
    Java工具-检验ftp服务器的指定文件是否存在
    文件读取FileUtil工具类 亲测可用
    MyBatis 遇到的报错
    Mac终端 mysql Operation not permitted错误解决方案
    Kubernetes---修改证书可用年限
  • 原文地址:https://www.cnblogs.com/L-O-N/p/13672819.html
Copyright © 2011-2022 走看看