If, like me, you work on terminals connected via ssh to remote computer/server you are probably used to tmux and screen and so it’s not a problem if you have to close your session, as you’ll be able to easily re-connect when you need it, but sometimes you could forget about using one of these […]
Article by Daniel Miessler first posted on his blog
lsof is the sysadmin/security über-tool. I use it most for getting network connection related information from a system, but that’s just the beginning for this powerful and too-little-known application. The tool is aptly called lsof because it “lists openfiles“. And remember, in UNIX just about everything (including a network socket) is a file.
lsof is also the Linux/Unix command with the most switches. It has so many it has to use both minuses andpluses.
usage: [-?abhlnNoOPRstUvV] [+|-c c] [+|-d s] [+D D] [+|-f[cgG]] [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+|-M] [-o [o]] [-p s] [+|-r [t]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
As you can see,
lsof has a truly staggering number of options. You can use it to get information about devices on your system, what a given user is touching at any given point, or even what files or network connectivity a process is using.
lsof replaces both
ps entirely. It has everything I get from those tools and much, much more. So let’s look at some of its primary capabilities: