get PID hogging a port

 i keep needing this but keep forgetting how to as well

netstat -abo | grep -A 1 '61618'

-a: display all connections and listening port

-b: display the executable involved

-o: display PID of the above

-A x: print x line following a match. This is important because on windows, the PID of the owning process is printed on the next line

Bash directory string expansion

 Nifty way to shorten commands involving multiple directories in bash.

{term1,term2,term3} in a directory string will be expanded and will result in 3 separate strings with each term inside the parentheses plugged in.

Examples:

  1. Removing files from multiple directories can be done with either

    rm /d/dir1/lib/xyz.jar /d/dir2/lib/xyz.jar /d/dir3/lib/xyz.jar

    or shorter

    rm /d/{dir1,dir2,dir3}/lib/xyz.jar

  2. Copying files FROM multiple directories to a single directory

    cp /d/{dir1,dir2,dir3}/lib/xyz.jar /c/doc

    is equal to longer copy command as follows

    cp /d/dir1/lib/xyz.jar /d/dir2/lib/xyz.jar /d/dir3/lib/xyz.jar /c/doc

  3. With xargs, the often needed task to copy files to multiple directories can also be done.

    xargs -n 1 cp -v xyz.jar <<< `echo /d/{dir1,dir2,dir3}/lib/`

    The above example is copying (verbosely) xyz.jar from current directory to 3 directories, namely /d/dir1/lib, /d/dir2/lib and /d/dir3/lib