BASH - count the number of executable files

I am trying to find the executable files and their total number in the folder, showing it, but the total is not my code below, can someone help me, I make mistakes, I'm just a beginner trying to learn some bash scripting I hope this is the right way do it thanks

#!/bin/bash To="home/magie/d2" cd "$To" find . -type f -perm 755 if find . -type f -perm 755 then echo | echo wc -l fi 
+4
source share
5 answers

Just remove the if and echo structure

 #!/bin/bash To="home/magie/d2" cd "$To" find . -type f -perm 755 find . -type f -perm 755 | wc -l 
+2
source

If you want to find all the executables , use this command:

 find home/magie/d2 -type f -perm -u+rx | wc -l 

OR

 find home/magie/d2 -type f -perm +111 | wc -l 

All answers here find files with a resolution of 755, but keep in mind that even 744 or 700 are also user executable files.

+3
source

I think I would do something like this:

 #!/bin/bash dir=$1 files="$(find $dir -perm 755)" total=$(wc -l <<< "$files") echo "$files" echo "Total: $total" 

where the desired directory should be passed as an argument on the command line, and quotation marks are used to preserve line breaks needed later by wc to correctly count the number of lines.

+2
source

Use / 111 to search for any file that has any of the executable bits.

to find. type f -perm / 111 | wc -l

+2
source

From the command line a simple single line layer should do the trick -

 wc -l < <(find /home/magie/d2 -type f -perm 755) 

<(..) - replacement of the process .

+1
source

Source: https://habr.com/ru/post/1391920/


All Articles