Here is a one-liner which sorts all the directories under ‘/’ by the number of files contained: find / -type d -exec sh -c ‘ls -a1 "$1" | wc -l’ \"{}\" {} \; -print | \ sed ‘$!N;s/\n/ /’ | sort -gr I recently needed this on a linux server where the inode quota was exceeded.Continue reading “Sort directories by number of files contained”
Tag Archives: bash
Cycle through the last argument of previous commands in Bash
In Bash, when I want to repeat the last argument of the previous command, I usually type !$. I just discovered that you can also use ALT+. to cycle through the last argument of previous commands.
ESC-g for glob expansion in bash
Just like <TAB> expands a filename given a prefix you can also expand a file name given the middle part of a file name. Example: $ ls abc1def abc2def abc3def abc4def abc5def $ ls *2*<ESC>g Which will expand to: $ ls abc2def via a stackoverflow question
Bash extended pattern matching
If you don’t have extended pattern matching enabled you can enable it with shopt -s extglob From the bash manual page: If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are recognized. In the following description, a pattern-list is a list of one or more patterns separated byContinue reading “Bash extended pattern matching”