簡體   English   中英

BASH腳本。 如何在指定的修改日期之前觸摸每個文件

[英]BASH script. How to touch every file before a specified modify date

因此,我希望能夠進入一個文件夾並更新其中每個文件的“上次修改”數據。

到目前為止,我認為我應該使用:

touch --date "2012-12-31" /tmp/date
find /filestotouch -type f -not -newer /tmp/date

這應該列出所有匹配的文件。 現在,我是否需要做一個循環,或者是否有一種簡單的方法來傳遞此數據以進行觸摸並使其全部完成?

有兩種選擇:

  1. 添加選項-exec :...-非-not -newer /tmp/date -exec touch "{}" \\;
  2. 管道到xargs :...- -not -newer /tmp/date -print0 | xargs -0 touch -not -newer /tmp/date -print0 | xargs -0 touch

嘗試執行find命令:

find /filestotouch -iname "*.type" -mtime +60 -exec touch "{}" \;

上面的命令將提取60天后修改的所有文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM