查找具有特定 mime 类型的所有文件

has*_*ian 1 permissions find 16.04

我将大量(Android SDK)文件从共享目录复制到我的系统。现在,它们的 MIME 类型为application/x-shellscriptor 的所有文件application/x-executable似乎都不可执行。例如,当我尝试运行时出现mksdcard此错误:

$ ./mksdcard
bash: ./mksdcard: Permission denied
Run Code Online (Sandbox Code Playgroud)

如何仅找到具有这些 MIME 类型的文件?然后我如何更改这些权限?

注意事项

1- 当我find <path> -type f -executable以 root 用户身份尝试时,它会显示所有文件(甚至 .PNG 文件),而当我以标准用户身份尝试时,它什么也没显示。我不知道如何过滤文件并注意它们的 MIME 类型。

2- 当前无法访问共享目录(源)。

ste*_*ver 6

find命令不会测试 mimetype 本身,但您可以使用它来执行mimetype命令和grep结果。

例如

find path/to/dir/ -type f -exec sh -c '
  for f; do 
    mimetype -b "$f" | grep -Eq "application/(x-shellscript|executable)" && 
    printf "%s\n" "$f"
  done
' sh {} +
Run Code Online (Sandbox Code Playgroud)

要对匹配的文件(例如 achmodchown)执行某些操作,请将printf命令替换为例如

find path/to/dir/ -type f -exec sh -c '
  for f; do 
    mimetype -b "$f" | grep -Eq "application/(x-shellscript|executable)" && 
    chmod u+x "$f"
  done
' sh {} +
Run Code Online (Sandbox Code Playgroud)

强烈建议您检查目前的所有权和权限例如使用ls

find path/to/dir/ -type f -exec sh -c '
  for f; do 
    mimetype -b "$f" | grep -Eq "application/(x-shellscript|executable)" && 
    ls -l "$f"
  done
' sh {} +
Run Code Online (Sandbox Code Playgroud)