如何从我的主文件夹上的递归“chmod -x”中恢复

Gau*_*lio 2 linux executable files

ENTER在我的主目录中输入以下愚蠢的命令后,我按下了按钮:

find . -type f -exec chmod -x '{}' ';'
Run Code Online (Sandbox Code Playgroud)

你有什么建议来解决这个问题。我的猜测是,除了做以下事情之外,我什么也做不了:

find . -type f -exec chmod og+x '{}' ';'
Run Code Online (Sandbox Code Playgroud)

或者可能会基于扩展做一些棘手的事情(这在 Linux 下似乎不太相关)。

或者你们中的一些人可能对如何知道在 linux 下哪个文件应该是可执行的以及如何检测它们以将它们恢复为可执行文件有一个想法或指针......

Gra*_*eme 6

这是我不久前编写的一个脚本,用于修复从 FAT 系统复制的文件的权限。如果文件名包含换行符,则不起作用(尽管如果有人想修复它,请随意):

#!/bin/sh

[ $# != 0 ] && dir="$1" || dir=.

[ -d "$dir" ] || { echo "usage: $0 [dir]"; exit 1; }

cat <<- EOF
  Will recursively alter permissions under directory '$dir'.
  Consider backing up permissions with 'getfacl -R $dir' first.
  Continue? [Y/n]"
EOF

read reply
[ "$reply" = Y ] || exit 0

echo "Changing all directories to mode 755..."
find "$dir" -type d -exec chmod 755 {} +

# simplest way for now is just to make all files non executable, then fix ones which should be
echo "Changing all files to mode 644..."
find "$dir" -type f -exec chmod 644 {} +

# use a temp file instead of a variable since the shell will strip nulls from the string
tmpfile=$(mktemp)

# screwed if filename contains a newline - fixable with a better sed script
echo "Using magic to find executables..."
find $dir -type f -exec file -hN0 -e apptype -e cdf -e compress -e elf -e tar -e tokens {} + |
  sed -n '/\x0.*executable/p' >"$tmpfile"

# ELF binaries
echo "\nSetting ELF executables to mode 755...\n"
sed '/\x0.*ELF/!d; s/\x0.*$//' "$tmpfile" | xargs -rd '\n' chmod -c 755

scripts=$(sed '/\x0.*text/!d; s/\x0.*$//' "$tmpfile")

IFS="
"

# only make scripts executable if they have a shebang
echo "\nSetting scripts with a shebang to mode 755...\n"
for file in $scripts
do
  head "$file" | grep -q '^#!' && chmod -c 755 "$file"
done

rm "$tmpfile"
Run Code Online (Sandbox Code Playgroud)