- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在 bash 脚本中,我尝试结合使用 stat 和 find 根据文件的八位字节来查找文件,但是我想跳过一些文件(file1、file2 等)。但是,这似乎不起作用。为什么会这样,我该如何解决?这是最好的方法吗?
$(stat --format %a 2>&1 $(find /example/dir -type f -not \( -name 'file1' -o \
-name 'file2' -o -name 'file3' -o -name 'file4' \) -prune) | egrep "777|755"
最佳答案
如果您要查找具有 777 权限的文件,请使用 find
来执行此操作:
find /example/dir -type f -perm 777
如果您不想在输出中包含 file1
、file2
、file3
或 file4
,也使用 grep
:
find /example/dir -type f -perm 777 | grep -Ev 'file[1234]'
如果您想要这些文件的 stat
输出,那么:
find /example/dir -type f -perm 777 | grep -Ev 'file[1234]' | xargs stat --format %a
或:
stat --format %a $(find /example/dir -type f -perm 777 | grep -Ev 'file[1234]')
如果文件列表很大,这更有可能遇到问题。您可以根据需要在任何 find
命令上恢复 -prune
选项。但是,运行 find example/dir -type f
和 find example/dir -type f -prune
对我看到的结果没有影响。
如果您正在寻找 777 或 775 许可,那么您需要:
find /example/dir -type f -perm +775
这恰好有效,因为 777 和 775 权限之间只有一点点不同。更通用和可扩展的解决方案将使用 -or
操作:
find /example/dir -type f \( -perm 777 -or -perm 775 \)
随着数字的变化,这可以寻找 664 或 646 权限而不获取可执行文件,-perm +622
将获取。
至于问题中的代码出了什么问题——我不完全确定。
$ find example/dir -type f
example/dir/a/filea
example/dir/a/fileb
example/dir/b/filea
example/dir/b/fileb
example/dir/c/filea
example/dir/c/fileb
example/dir/filea
example/dir/fileb
$ find example/dir -type f -not \( -name filea -o -name fileb \)
$ find example/dir -type f -not \( -name filea -or -name fileb \)
$ find example/dir -type f \( -name filea -or -name fileb \)
example/dir/a/filea
example/dir/a/fileb
example/dir/b/filea
example/dir/b/fileb
example/dir/c/filea
example/dir/c/fileb
example/dir/filea
example/dir/fileb
$ find example/dir -type f ! \( -name filea -or -name fileb \)
$ find example/dir -type f \( -not -name filea -and -not -name fileb \)
$
-not
或 !
运算符似乎完全把事情搞砸了,这是我没有预料到的。从表面上看,这看起来像是一个错误,但在我声称“错误”之前,我必须有更多的证据并且必须对 find
规范进行大量非常仔细的审查。
此测试是在 Mac OS X 10.8.3 (BSD) 上使用 find
完成的,没有 GNU find
。
(您在问题中使用术语'octet' 令人费解;它通常用于指示网络通信中的一个字节,更严格的意思是它恰好是 8 位字节不需要。权限以八进制表示,并基于 inode 中的 16 位,2 个八位字节。)
关于linux - Stat with find 不排除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16673158/
所以,我正在尝试创建一种 ls 函数。这是我对每个文件的描述的代码 struct stat fileStat; struct dirent **files; num_entries = scandir
我最近一直在尝试实现我自己的 linux ls 命令版本。一切都很好,但是当我尝试使用 ls -l 功能时,struct stat 的某些字段未初始化 - 我得到 NULL 指针或垃圾值,尽管它似乎只
我在 Yii 中遇到 STAT 关系问题。我不确定我正在寻找的东西是否可以通过本地 Yii 关系实现。我会尽力描述我的问题,如果不清楚,请询问任何具体细节。 我有三个表,因此有三个模型 | table
我正在为一个严重依赖 scipy.stats.stats(scipy 版本 0.9.0)的包创建一个 django-powered (1.3) 接口(interface),称为 ovl 。在早期开发阶
为了安全起见,我喜欢显式初始化我的变量(当您编写大量代码时,它通常会使它更安全,因为您的代码最终不会崩溃那么多。) 对于大多数类型,无论是结构还是整数等基本 C++ 类型,我都可以编写以下内容: ti
我一直在使用 stat() 检查文件是否存在,据我所知,这比尝试打开文件更好。但是,stat() 不适用于包含其他语言的 unicode 字符的文件名。是否有 stat() 的宽字符版本或我可以使用的
错误: File "/usr/lib/python2.7/dist-packages/statsmodels/regression/linear_model.py", line 36, in
下面是我要运行的脚本。我不能在 awk 中使用 stat。 cat /etc/passwd | awk 'BEGIN{FS=":"}{print $6 }' | (stat $6 | sed -n '
我正在尝试拟合 xlog 线性回归。我使用 Seaborn regplot 来绘制拟合,看起来很合适(绿线)。然后,因为 regplot 不提供系数。我使用 stats.linregress 来查找系
我正在尝试使用共享库 (libscplugin.so) 中包含的方法。 我已经满足了库的所有要求: libc.so 带有指向 libc.so.6 的符号链接(symbolic link) libz.s
嘿,感谢阅读。 我正在制作一个程序,它接受 1 个参数(目录)并使用 opendir()/readdir() 读取目录中的所有文件,并使用 stat 显示文件类型(reg、链接、目录等)。当我在 sh
简单问题:在 Linux 中,我 stat() 一个不是设备的文件。 st_rdev 字段的期望值是多少?我可以运行 major(stat.st_rdev) 和 minor(stat.st_rdev)
我正在尝试为我的 Angular 6 应用程序生成 stats.json 文件。下面的事情我已经尝试过,但根本没有生成文件。我的系统需要有 “npm 运行”在每个 angular cli 命令之前。
我正在尝试使用返回的 stat 结构中的 st_mode,该结构是我通过以下方式从 stat() 调用获得的; char *fn = "test.c" struct s
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我有一个程序,是我通过修改原始暗网(深度学习图像识别,Yolov2)的许多地方而制作的。几个月前我一直在使用它,但是今天当我编译它时,它给了我一个错误: gcc -DSAVE_LAYER_INPUT
我预计 scipy.stats.mstats.pearsonr 对于屏蔽数组输入的结果将与 scipy.stats.pearsonr 对于输入数据的 unmasked 值给出相同的结果,但它不会't:
给定 tmp.c: #include #include #include int main(int argc, const char *argv[]) { struct stat st;
In [15]: a = np.array([0.5, 0.5, 0, 0, 0]) In [16]: b = np.array([1, 0, 0, 0, 0]) In [17]: entropy(a
当我们运行 stat filename我们得到 Access: 2021-06-25 15:40:18.532621916 +0530 Modify: 2020-08-13 15:57:30.0000
我是一名优秀的程序员,十分优秀!