I have the following alias defined in my .bashrc
alias lsfc='ls -l "$@" | tee /dev/tty | grep -v / | echo "File count: `wc -l`"'
which is intended to give me the number of files in a directory but is giving me that number +1 - because it's also including the initial line giving the total size of the directory. How can I modify my alias to either exclude that first line or reduce the line count by one? I can't even begin to work out what to Google for to try and solve this on my own.
-l
if you don't want the information it prints. Or remove the first line with e.g.sed 1d
. Or use the shell's arithmetic expansion to subtract one,$(( $(wc -l) - 1 ))
. But also note that if someone gives you a filename with a newline in it (something unix-like OSes sadly don't stop you from doing), some versions ofls
will happily print it with a raw newline, messing up the count. Anyway, you should probably turn that into a shell function too, in particular because"$@"
doesn't even work in an alias the way you'd hope it does.