A selection of handy unix/linux one-liners

Over the years I’ve found myself repeatedly using (variations of) the same one-liners to achieve certain tasks in unix/linux environments. Task such as finding files containing strings, finding sizes of directories etc.

Most all these one liners seem to be centered around find, grep, xargs, awk on others, and so without further ado here’s my selection.

Which root directory subtree is using my disk space

find / -mindepth 1 -maxdepth 1 -type d | egrep -v "proc|mnt" | xargs du -sk

(Note: It is handy to remove /proc and /mnt, to prevent spurious errors and searching the 100Tb SAN…)

Which files in a directory tree contain a certain string

find . -type f -exec grep "mystring" '{}' \; -print

To be continued…

This entry was posted in Unix and tagged . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.