Сценарий Bash для создания файла для каждого уникального разрешения в команде листинга/поиска и печати каждого экземпляра пути к каталогу/файлу этого разрешения

El siguiente es el preámbulo del archivo sudoersen mi Mac. (No creo que su redacción haya cambiado en los últimos quince años.)

This file MUST be edited with the 'visudo' command as root. Failure to use 'visudo' may result in syntax or file permission errors that prevent sudo from running.

See the sudoers man page for the details on how to write a sudoers file.

Aquí hay un fragmento devisudo man page:

After the edits are made, visudo parses the sudoers file. It will not save the changes if there is a syntax error.

Upon finding an error, visudo will print a message stating the line number(s) where the error occurred and the user will receive a "What now?" prompt. At this point, the user may enter e to re-edit the sudoers file, x to exit without saving the changes, or Q to quit and save changes.

The Q option should be used with extreme care because if visudo believes there is a parse error, so will sudo, and no one will be able to sudo again until the error is fixed. If e is typed to edit the sudoers file after a parse error has been detected, the cursor will be placed on the line where the error occurred.

... Y esa es la razón por la que en realidad usovisudoen lugar de, digamos, nano. Si hay un problema, visudome advertirá y me dirigirá a él antes de comprometerme y bloquear no solo a mí, sino a todos fuera del acceso de root. (Como lo hice yo hace quince años, no es que lo admita. )De todos modos, dado que $sudose queja de un error de sintaxis en un número de línea no existente -, apuesto a que es un carácter EOF extraviado o un error tipográfico similar que causa el problema.

1
07.06.2019, 02:59
1 ответ

Попробуйте это:

#!/bin/bash

while read file; do
        stat -c '%A %n' "$file" >> $(stat -c '%a' "$file").txt
done < <(find "$1")

Использование:

./script.sh /path/to/directory
  • первый stat -c '%A %n' "$file"печатает разрешения и путь к файлу, например.-rw-rw-rw- /foo/bar
  • второй stat -c '%a' "$file"печатает разрешения в восьмеричной форме, например.666

Вывод первого statдобавляется к имени файла, созданному вторым stat, с суффиксом .txt.

3
27.01.2020, 23:22

Теги

Похожие вопросы