//View Tip #502
» Get an ordered list of subdirectory sizes
» Permanent bash history
» Reverse geocode with bash
» Checksum directory recursively
Similar Tips
» Being selfish - Kick all users except you» Get an ordered list of subdirectory sizes
» Permanent bash history
» Reverse geocode with bash
» Checksum directory recursively
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Counts files in the current directory and subdirectory
found is vserver-tools
alias lll='for i in *; do echo "`ls -1aRi $i | awk "/^[0-9]+ / { print $1 }" | sort -u | wc -l` $i" ; done | sort -n'
found is vserver-tools
Comments
Add your comment
if you want only the file count and not the directories stick to:
alias lll='find . -type f | wc -l'
alias lll='find . -type f | wc -l'
Posted 2009-02-04 01:24:35
unfortunately that also has a problem with filenames containing newlines (which are valid) in any case Techfun's implementation is not the same as the first one, Techfun's gives a total of the files while the original provides counts per directory.
this, as usual, can be better and more efficiently implemented by the shell alone:
lll() (
f() {
local files=0 dirs=()
for dir_entry in "$1"/*; do
[[ -d $dir_entry ]] && dirs+=("$dir_entry") || let "files++"
done
echo "$files $1"
for dirname in "${dirs[@]}"; do
f "$dirname"
done
}
shopt -u failglob dotglob
shopt -s nullglob
f "${1:-$PWD}"
)
notice the use of parenthesis instead of braces on the outer body to avoid corrupting the environment by changing the glob settings.
this, as usual, can be better and more efficiently implemented by the shell alone:
lll() (
f() {
local files=0 dirs=()
for dir_entry in "$1"/*; do
[[ -d $dir_entry ]] && dirs+=("$dir_entry") || let "files++"
done
echo "$files $1"
for dirname in "${dirs[@]}"; do
f "$dirname"
done
}
shopt -u failglob dotglob
shopt -s nullglob
f "${1:-$PWD}"
)
notice the use of parenthesis instead of braces on the outer body to avoid corrupting the environment by changing the glob settings.
Posted 2009-02-13 22:21:44


Try instead:
alias lll='find . | wc -l'