Member-only story
5 Powerful Unix Commands for Easier Troubleshooting
A collection of proven Unix commands to help you identify application issues
Identifying an application issue can be very time-consuming. That’s why it’s essential to know various troubleshooting commands which can make it easier for us to spot the problem.
Unix-like systems come with many powerful in-built commands. In this article, I’ve gathered the top ones which I’ve been using a lot. You can use the examples here to create your own cheat sheet for solving issues.
Let’s get started!
The lsof Command
lsof
stands for “list open files.” It’s undoubtedly one of the most powerful troubleshooting commands because you can get a lot of information from it.
Retrieve open files belonging to active process
Without any arguments, lsof
lists all open files belonging to all active processes. This can come in handy when you want to identify which process is using a file you are trying to delete.
To try it out, type this command in your Terminal:
$ lsof
Example output:
In another scenario, there might be a suspicious process you want to examine. You can check the files which are used by that process to receive more information.
Note that you might get “Permission denied” for some processes. It’s because your user is not allowed to view processes owned by other users. In such case, run the command as root
and you’ll be able to see all processes by all users.
List open files by user
If you want to find out which files are in use by a certain user, type this command:
$ lsof -u someuser
You’d be surprised how many open files there are. To narrow down the results, you might want to include the grep
command.