使用 find 的 -prune 操作

使用 find 的 -prune 操作

在此脚本中:

#!/bin/bash

# Get the current epoch time minus 1 second to be sure all files are captured. 
eptime=$((EPOCHSECONDS-1))

# Execute the commands that will do the sought for file changes:
gio set "/home/stephen/Desktop/Flameshot.desktop" "metadata::trusted" no
gio set "/home/stephen/Desktop/Flameshot.desktop" "metadata::trusted" yes

# Create a test file to verify the script works
touch ./gio_set_file_changes_test.txt

# List all files changed after eptime
eptimestart=$EPOCHSECONDS
find / -name /proc/ -prune -o -newermt @$eptime -printf '%T+\t%s\t%p\n' 2>/dev/null | sort -r
echo Search time $((EPOCHSECONDS-eptimestart)) seconds
rm ./gio_set_file_changes_test.txt

find 命令的 -prune 操作未能按预期消除 /proc 目录。执行此操作的正确语法是什么?

答案1

如果您没有将标准错误流重定向到 /dev/null,您可能会看到一条消息:

find: warning: ‘-name’ matches against basenames only, but the given pattern contains 
a directory separator (‘/’), thus the expression will evaluate to false all the time.

你可能想要-path代替-name

find / -path /proc -prune -o -newermt "@$eptime" -printf '%T+\t%s\t%p\n' 2>/dev/null | sort -r

(请注意,没有尾随//proc

相关内容