简体   繁体   中英

Bash Script: Check if multiple files are executable and output them?

Can you make a script that iterates through a folder (for example the home directory) and prints the names of all regular files that are executable?

Are you aware that the find command has an -executable switch?

If you want to see all executable files in all subdirectories, you might do:

find ./ -type f -executable

If you want to see all executable files, but just in your directory, you might do:

find ./ -maxdepth 1 -type f -executable

I can.

#!/bin/bash
for d in "$@"
do [[ -d "$d" ]] || { printf '\n"%s" not a directory\n' "$d"; continue; }
   for f in "$d"/* "$d"/.*; do [[ -f "$f" && -x "$f" ]] && ls -l "$f"; done
done

But use find as Dominique advised.
Why reinvent the wheel?

Still, there's a lot going on there that could be useful.
Let me know if you have questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM