Bash 我可以更改一个文件或所有文件的修改日期吗?
我可以更改一个文件或所有文件的修改日期吗? 我一直在寻找导致我触摸的Bash 我可以更改一个文件或所有文件的修改日期吗?,bash,touch,Bash,Touch,我可以更改一个文件或所有文件的修改日期吗? 我一直在寻找导致我触摸的 $ ls -l *.txt -rw-r--r-- 1 kevin.smith mkpasswd 3319 Nov 21 2017 adjectives.txt -rw-r--r-- 1 kevin.smith mkpasswd 25562 Aug 11 2015 checklist.txt -rwxr-xr-x 1 kevin.smith mkpasswd 11347 May 9 14:28 cw_text.txt -
$ ls -l *.txt
-rw-r--r-- 1 kevin.smith mkpasswd 3319 Nov 21 2017 adjectives.txt
-rw-r--r-- 1 kevin.smith mkpasswd 25562 Aug 11 2015 checklist.txt
-rwxr-xr-x 1 kevin.smith mkpasswd 11347 May 9 14:28 cw_text.txt
-rw-r--r-- 1 kevin.smith mkpasswd 9260 May 9 14:31 cw_text2.txt
-rw-r--r-- 1 kevin.smith mkpasswd 4786 May 9 14:38 cw_text3.txt
-rw-r--r-- 1 kevin.smith mkpasswd 390 Jun 25 2014 Delete_log.txt
-rw-r--r-- 1 kevin.smith mkpasswd 6891 Jul 27 2015 log.txt
-rw-r--r-- 1 kevin.smith mkpasswd 53828 Jan 17 2017 pin1.txt
-rw-r--r-- 1 kevin.smith mkpasswd 39412 Jan 17 2017 pip2.txt
-rw-r--r-- 1 kevin.smith mkpasswd 167 Dec 5 2015 romeo.txt
$ touch -t 2018* *.txt
预期产出:仅将年份改为2018年
$ ls -l *.txt
-rw-r--r-- 1 kevin.smith mkpasswd 3319 Nov 21 2018 adjectives.txt
-rw-r--r-- 1 kevin.smith mkpasswd 25562 Aug 11 2018 checklist.txt
-rwxr-xr-x 1 kevin.smith mkpasswd 11347 May 9 14:28 cw_text.txt
-rw-r--r-- 1 kevin.smith mkpasswd 9260 May 9 14:31 cw_text2.txt
-rw-r--r-- 1 kevin.smith mkpasswd 4786 May 9 14:38 cw_text3.txt
-rw-r--r-- 1 kevin.smith mkpasswd 390 Jun 25 2018 Delete_log.txt
-rw-r--r-- 1 kevin.smith mkpasswd 6891 Jul 27 2018 log.txt
-rw-r--r-- 1 kevin.smith mkpasswd 53828 Jan 17 2018 pin1.txt
-rw-r--r-- 1 kevin.smith mkpasswd 39412 Jan 17 2018 pip2.txt
-rw-r--r-- 1 kevin.smith mkpasswd 167 Dec 5 2018 romeo.txt
您需要使用for
循环来迭代文件,并逐个查询/更新mtime
您需要使用
for
循环来迭代文件,并逐个查询/更新mtime不,没有类似的。您需要获取当前的mtime,将其年份替换为2018
,然后使用touch
将mtime更改为该日期。您真的要将修改后的时间设置为将来的日期吗?@glennjackman no,很抱歉错过了,dis关于2015年12月5日/2018年12月5日不,没有类似的事情。您需要获取当前的mtime,将其年份替换为2018
,然后使用touch
将mtime更改为该日期。您真的想将修改后的时间设置为将来的日期吗?@glennjackman否,很抱歉错过了,请参阅2015/2018年12月5日
ls -l file.txt; touch -t "$(date -d "@$(stat -c '%Y' file.txt)" "+2020%m%d%H%M")" file.txt; ls -l file.txt
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-rw-r--r-- 1 jackman jackman 0 Oct 23 16:47 file.txt
-rw-r--r-- 1 jackman jackman 0 Oct 23 2020 file.txt