-   Linux - Newbie (
-   -   find command (

congos 01-19-2012 11:09 AM

find command
how can i find the number of executable files in a folder/directory and display them on the terminal
this is my code below i do not know why its not working


cd "To"
find .type f -name "*.sh" | ls -l | wc -l

crabboy 01-19-2012 11:21 AM

You are close:

find $START_DIR -name '*.sh' -type f | wc -l

that will find all the .sh files in your starting directory and recursively search down.

jhwilliams 01-19-2012 11:22 AM


find . -type f -executable | wc -l

Snark1994 01-19-2012 11:25 AM

Well, a couple of things. If you've set "To=" then your "cd" line should be


cd $To
Secondly, there should be a space between the '.' and the 'type', and it should be '-type' not 'type' (you could even just write


find $To -type f -name "*.sh" | ...

Also, you're not finding executable files, you're finding files with a .sh extension - but as long as you're okay with that, then that's alright.

However, if you're just listing, you should use 'ls' on its own:


ls -l ${To}/*.sh | wc -l

David the H. 01-19-2012 11:26 AM

Here are a couple of links about using find. You may find them useful:

tronayne 01-19-2012 11:26 AM

You probably want to use the -perm option.

If you look at the manual page for find, the EXAMPLES section has a number of sample uses of -perm (you can search in the manual page by entering /perm to find the first, then n to find the next and so on).

If you use the more-or-less standard default (022), an executable file will be mode 755, so you might use

find . -type f -perm 755
to get a list of all executable files; see the manual page for others.

Hope this helps some.

congos 01-19-2012 01:05 PM

its working but how do i find their total,im trying to use

wc -l
but its not working

crabboy 01-19-2012 01:27 PM

Could you explain what you see?

wc -l should count the number of lines that were reported by the find command. If find found 4 .sh files you should see 4.

wc -l alone will not show anything because it is waiting for input, text piped in from find you should see what I described above.

All times are GMT -5. The time now is 11:15 PM.