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 Code:
#!/bin/bash |
You are close:
Code:
START_DIR=/home/elgin19/d2 |
Code:
find . -type f -executable | wc -l |
Well, a couple of things. If you've set "To=" then your "cd" line should be
Code:
cd $To Code:
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: Code:
ls -l ${To}/*.sh | wc -l |
Here are a couple of links about using find. You may find them useful:
http://mywiki.wooledge.org/UsingFind http://www.grymoire.com/Unix/Find.html |
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 Code:
find . -type f -perm 755 Hope this helps some. |
its working but how do i find their total,im trying to use
Code:
wc -l |
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 03:10 PM. |