LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-19-2012, 10:09 AM   #1
congos
LQ Newbie
 
Registered: Oct 2011
Posts: 20

Rep: Reputation: Disabled
Post 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
To=/home/elgin19/d2
cd "To"
find .type f -name "*.sh" | ls -l | wc -l
 
Old 01-19-2012, 10:21 AM   #2
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
You are close:
Code:
START_DIR=/home/elgin19/d2
find $START_DIR -name '*.sh' -type f | wc -l
that will find all the .sh files in your starting directory and recursively search down.
 
Old 01-19-2012, 10:22 AM   #3
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 206Reputation: 206Reputation: 206
Code:
find . -type f -executable | wc -l
 
Old 01-19-2012, 10:25 AM   #4
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

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

Code:
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

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
 
Old 01-19-2012, 10:26 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
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
 
Old 01-19-2012, 10:26 AM   #6
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 2,992

Rep: Reputation: 737Reputation: 737Reputation: 737Reputation: 737Reputation: 737Reputation: 737Reputation: 737
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
to get a list of all executable files; see the manual page for others.

Hope this helps some.
 
1 members found this post helpful.
Old 01-19-2012, 12:05 PM   #7
congos
LQ Newbie
 
Registered: Oct 2011
Posts: 20

Original Poster
Rep: Reputation: Disabled
its working but how do i find their total,im trying to use
Code:
wc -l
but its not working
 
Old 01-19-2012, 12:27 PM   #8
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
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.
 
  


Reply

Tags
bash, bash scripting, ubuntu 11.04, unix


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Find a file in directories without using find command sikanders Linux - Newbie 14 08-06-2010 08:47 PM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 05:55 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 04:45 PM
Using a single "Find" Command to find files bases on multiple criteria roboxooo Linux - Newbie 6 01-15-2009 04:13 AM
can't find my find command! how to replace? dave247 Debian 4 11-19-2008 10:51 AM


All times are GMT -5. The time now is 06:42 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration