Hacker News new | ask | show | jobs
by loudmax 4916 days ago
I have this in my .bashrc:

function lc() { if [[ "$#" -gt 1 ]]; then for DIR in "$@"; do echo -n "$DIR - " ; ls -AU1 $DIR | wc -l ; done ; else ls -AU1 "$@" | wc -l ; fi; }

So, "lc /dir" will count the number of files in /dir and "lc /dir/*" will count the files in subdirectories of /dir. This is useful if you're working in an environment where you may have thousands of files in a directory, and a regular "ls -l" will lock your terminal while it eats your entire scrollback buffer.

2 comments

Here's an idea: always pipe ls throug a pager! If it's less than a page, it would just print the results (you have to set some flags on less that I don't remember). If it's more, then press d or /term-to-search :)

   less -F
Won't page if less than one screenful. zsh users can also do:

    < filename
(less than character)
This might be quicker than firing up a shell script:

> lc /dir" will count the number of files in /dir

  find /dir -type f -maxdepth 1 | wc -l
> and "lc /dir/*" will count the files in subdirectories of /dir.

  find /dir -type f -mindepth 2 | wc -l