21 ms·
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 "$@" |
by loudmax 14y 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.
- pooriaazimi 14y agoHere'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 :)
- crazydiamond 14y agoless -F Won't page if less than one screenful. zsh users can also do: < filename (less than character)
- Nick_C 14y agoThis 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