How to count the number of files recursively with wild card
Hello,
How can I count the number of files in a directory. I need to know the number of files in one of my web sites. I do not want to include junk like pdf's and jpeg's so I just want to count the php and html pages. In windows for example I would use dir *.php and get a list with a number at the bottom. I of course need to do this recursively. I have found some use of the wc command but is'nt that just for line counting? Can that be piped through something else? Thanks in advance. redir |
use -o in find to specify multiple extensions,
nl or wc can be piped to count anything, like so: Code:
find . -name '*.html' -o -name '*.php' |wc -l In general, relative to the current dir: find ./some_dir In general, absolute: find /some_dir |
You can combine find and wc to get a count of php files:
$ find -iname '*.php' | wc -l The "find" part(find -iname '*.php') will give a recursive search for all php files in the current directory and print them out one line per file found matching the search. Run the find command separately and you will see what I mean. That output is piped through to wc which counts the new lines and prints the total. The above will only output the number from wc which is, in effect, the file count found by the find command. |
Here is what I came up with ...
Code:
#!/bin/bash Code:
chmod +x filename If anything is a bit confusing, just ask, and I can tell you why I did whatever. |
Excellent, thank you. Now let me take this one step further. How can I omit certain subdirectories from this process. There are a few directories that I would like to not have their files counted. Possible?
Thanks again. |
Well, if you are using the find command, pipe it through egrep, and return just the ones that you want. I.e.
Code:
find . -name "*php" | egrep -v 'directory1|directory2|...' | wc -l Code:
script_name.sh /directory_path | egrep -v 'directory1|directory2|...' Code:
#!/bin/bash |
All times are GMT -5. The time now is 05:13 PM. |