linux - 在Linux中查找目录下所有user1拥有和user1所属组的可执行文件

标签 linux

我想在Linux目录下找到所有user1拥有和user1所属组的可执行文件.

使用 find 以下工作正常:

find /$mydir -type f -user user1 -perm -010

但我需要知道如何使用 lsgrep 做同样的事情。

最佳答案

如果未指定 maxdepth,则 find 命令执行递归搜索。

对于当前目录:

ls -l | awk '$3=="user1"&&$4=="user1group"&&substr($1,1,1)=="-"&&substr($1,7,1)=="x"{print $NF}' 将在您知道用户 1 的组时工作。

或者在所有子文件夹中的组中使用递归搜索:

user="user1";for s in `groups $user| sed 's/.*: //g'`; do awkstmt="ls -R -l | awk '\$3==\"$user\"&&\$4==\""$s"\"&&substr(\$1,1,1)==\"-\"&&substr(\$1,7,1)==\"x\" {print \$NF}'"; eval $awkstmt; done | sort | uniq

或者在当前文件夹中的组之间递归搜索:

user="user1";for s in `groups $user| sed 's/.*: //g'`; do awkstmt="ls -l | awk '\$3==\"$user\"&&\$4==\""$s"\"&&substr(\$1,1,1)==\"-\"&&substr(\$1,7,1)==\"x\" {print \$NF}'"; eval $awkstmt; done | sort | uniq

关于linux - 在Linux中查找目录下所有user1拥有和user1所属组的可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46066523/

相关文章:

linux - bash shell 脚本变量赋值

linux - 打印 A 字符串(任何字符串)重复自身 3 次的行 - sed

linux - Cumulocity Raspberry PI - 连接问题

c - 运行没有缓存的程序

c - 伪终端(pty)报告资源暂时不可用

c - pci_find_capability 返回 0 : "device does not support it"

linux - 移动文件并在 Bash 上包含它的目录后重命名它

linux - 没有这样的文件或目录。但只有在通过 shell 脚本运行时

c语言通过指定文件进行客户端socket连接

c - 易于为 C 扩展 IDE