UNIX Useful Commands

In the course of trouble-shooting or performance tuning, it is inevitable to go down to the OS level. Typically enterprise Java applications would be hosted on UNIX, Solaris, Linux or AIX. Here are some commands that I’d used or seen system engineers using. I’ll add to the list whenever I remember something.

As there’re many variants of UNIX, it is best to consult your man pages for these commands.

To find out the top processes in terms of CPU/memory usage:

top

If you discover that your Java application is hogging the CPU or memory, sometimes you might have to kill the process. The top command gives you the PID of the process. The results of the top command are dynamically refreshed.

To kill a process by its PID:

kill <pid>

If the process is persistent and showed up again in the top command, try:

kill -9 <pid>

Sometimes you would want to have a core dump to analyze what went wrong:

kill -3 <pid>

To do a directory listing (with files details), similar to your Windows’ dir command, do this:

ls -l

Sometimes you want to see hidden files:

ls -la

Changing directory is similar to Windows:

cd /<target directory>

If you want to read your running log files, especially the latest logs:

tail -f /Applications/jboss/logs/superapp.log

There’s the head command too! Say your log files are capped at 5 MB, and it will roll over to a new file once the limit is reached, you might want to use the head command to look at the first few lines of this new log file:

head -f /Applications/jboss/logs/superapp.log

To display contents of (non-binary) small files, we could:

cat /<directory>/<filename>

For large files:

more /<directory>/<filename>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: