查找 Change > 的文件出生

发布于 2025-01-09 16:53:53 字数 575 浏览 3 评论 0原文

是否可以找到 Change > > 的文件出生?

Stat somefile 显示已修改文件的修改时间

Access: 2022-02-24 17:07:45.562037727 +0000
Modify: 2022-02-24 17:07:26.682343514 +0000
Change: 2022-02-24 17:07:26.682343514 +0000
 Birth: 2022-02-24 16:35:56.737147848 +0000

和未修改文件(复制的文件)的

Access: 2022-02-23 18:27:00.000000000 +0000
Modify: 2022-02-23 18:27:00.000000000 +0000
Change: 2022-02-24 15:57:29.334302184 +0000
 Birth: 2022-02-24 15:57:29.334302184 +0000

修改时间是原始文件的时间戳,略小于将其复制到 docker 映像中的时间。

我只想查找仅修改过的文件。

Is it possible to find files where Change > Birth?

Stat somefile shows this for a modifed file

Access: 2022-02-24 17:07:45.562037727 +0000
Modify: 2022-02-24 17:07:26.682343514 +0000
Change: 2022-02-24 17:07:26.682343514 +0000
 Birth: 2022-02-24 16:35:56.737147848 +0000

and this for a non-modifed one (a copied file)

Access: 2022-02-23 18:27:00.000000000 +0000
Modify: 2022-02-23 18:27:00.000000000 +0000
Change: 2022-02-24 15:57:29.334302184 +0000
 Birth: 2022-02-24 15:57:29.334302184 +0000

The modification time is the timestamp of the orginal file, a little less than the time it was copied into a docker image.

I'd like to find only the modified files.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以可爱出名 2025-01-16 16:53:54

这是 bash 中的一个小脚本,用于查找 change "path1" >诞生“path2”

以下脚本草图假设 change,birth 具有值。

change=$(stat "<path1>" | awk '/Change/ {$1=""; print}')
birth=$(stat "<path2>" | awk '/Birth/ {$1=""; print}')

if [ $change -ge $birth ];
then
    echo "greater"
fi

Here is a little script in bash, to find if change "path1" > birth "path2".

The following sketch for a script assumes that change, birth have values.

change=$(stat "<path1>" | awk '/Change/ {$1=""; print}')
birth=$(stat "<path2>" | awk '/Birth/ {$1=""; print}')

if [ $change -ge $birth ];
then
    echo "greater"
fi
2025-01-16 16:53:53

假设您创建了 6 个文件,等待一秒钟,然后再次触摸其中 3 个来更新其 mtime

$ touch file{1..6}; sleep 1; touch file{2..4}

您可以使用 ruby 找到已修改的文件:

ruby -e '
    Dir.glob("file*").each{|fn|
        st=File.stat(fn)
        puts "\"#{fn}\" satisfies the condition" if st.mtime>st.birthtime
    }
'

或者使用 Bash:

# The `stat` command tends to be SUPER platform specific
# This is BSD and likely only works on BSD / Mac OS
# Just modify that `stat` command to print mtime and btime for your platform
for fn in file*; do
    mtime=$(stat -f "%m" "$fn")
    btime=$(stat -f "%B" "$fn")
    (( mtime>btime )) && echo "\"${fn}\" satisfies the condition"
done    

要么打印:

"file2" satisfies the condition
"file3" satisfies the condition
"file4" satisfies the condition

Suppose you create six files, wait a sec then touch 3 of them again to update their mtime:

$ touch file{1..6}; sleep 1; touch file{2..4}

You can find the files that have been modified with ruby:

ruby -e '
    Dir.glob("file*").each{|fn|
        st=File.stat(fn)
        puts "\"#{fn}\" satisfies the condition" if st.mtime>st.birthtime
    }
'

Or with Bash:

# The `stat` command tends to be SUPER platform specific
# This is BSD and likely only works on BSD / Mac OS
# Just modify that `stat` command to print mtime and btime for your platform
for fn in file*; do
    mtime=$(stat -f "%m" "$fn")
    btime=$(stat -f "%B" "$fn")
    (( mtime>btime )) && echo "\"${fn}\" satisfies the condition"
done    

Either prints:

"file2" satisfies the condition
"file3" satisfies the condition
"file4" satisfies the condition
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文