Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • don't use -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 of ls 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. Commented Sep 17, 2024 at 12:38
  • 3
    I'd re-think your approach entirely - see for example How can I get a count of files in a directory using the command line? or What's the best way to count the number of files in a directory? Commented Sep 17, 2024 at 13:11
  • Many thanks to all for the help and advice! Commented Sep 25, 2024 at 12:53