3 ms·
Don' stop there. You've solved a real problem in your life, and you might want that information another day. Make a tiny script that encapsulates it. Generalize
by kmstout 7y ago
Don' stop there. You've solved a real problem in your life, and you might want that information another day. Make a tiny script that encapsulates it. Generalize it a tiny bit, and give it a memorable name (perhaps lsof-tree). That done, you can stop worrying about the mechanics of the solution and build on it.
#! /bin/bash
# lsof-tree: list open files in a given directory tree (default /home)
NAME=9 # set to 10 for CentOS
BASE="${1:-/home}"
lsof | awk -v NAME=$NAME '{print $NAME}' | grep "^$BASE" | sort -u
- jabl 7y agoYMMV, but I find it easier and faster to know the basic utilities and how to compose them with pipes than remembering the name of a zillion such scripts. I guess it depends on how often you need that particular pipeline. Every day? Sure, make a script. Every few months? Nah, I won't remember it anyway,or probably I remember that I've made a script like that but then I have to start searching my bin directory in the end using more time than just writing the pipeline in the first place.
- Communitivity 7y agoSpot on. My ~/bin has a large number of such little scripts, and my current project has a 'scripts' repository for the same reason.