Maret 19, 2022
By
Firman
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
Maret 19, 2022
By
Firman
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:
- 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
- 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
- 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