Tux, the Linux penguin

(Photo credit: Wikipedia)

Most of the applications that I’ve worked on as a Software Developer were running in a Linux environment. Using the right tools can boost our productivity and save us a considerable amount of time.

Here’s a list of command line tools that I find most convenient when working Linux.

less file.log

Less is like vi, the editor in read-only mode with the ability to tail files. Some useful shortcuts:
SHIFT+F: jump to the end of the file and start tailing
W: page up
Z: page down
?: search forward
/: search backwards
N: jump to next search result
SHIFT+N: jump to previous search result

sudo su – <username>

Start acting as if you were logged in as a different user on the server. If no username is provided, you’ll become root (given you got the permissions granted).

ps aux | grep <keyword>

Search for a keyword in the list of running processes. For example, we can use it to find all running java apps with a specific library on the classpath. This can come handy when we need to kill an unresponsive process.

ls lrt

List files in a folder ordered by last modified timestamp. Use this to find out which file in the logs folder was modified last.

top

Top is the linux command line version of the Windows Task Manager.

df -h

This command can tell us if the server ran out of disk space.

grep error *.log

Testers reported an exception in your code? Above command will list you all log entries that contain keyword ‘error’.

CTRL+R

When using bash, you can take advantage of the bash history, a history of commands you executed before. Never type the same command twice, just hit CTRL+R and start typing some bits from the command you’re looking for. If the result is not the right one, keep typing more bits or press CTRL+R. In case you want to go back in the search results, use CTRL+SHIFT+R.

Enhanced by Zemanta