As a developer, there are certain UNIX commands you find yourself typing repeatedly. Whether it's to debug a production issue or just modifying some files, these commands have helped me do my job time and time again. Here's my top 8:
I would then take the pid of tomcat and run:
Now you may be wondering why the "Top 8", why not "Top 10". Well, because 8 is the new 10 and those are all UNIX commands I know :).
What are some of the commands that you use to get through the day?
- grep - Prints the lines that match the pattern provided in the files specified
- Usage:
grep <options> <pattern> <files>
- Example:
grep -n Exception production.log
- Prints all the line (showing line numbers) in the file
production.log
that contain the string 'Exception'
- Prints all the line (showing line numbers) in the file
- Usage:
- tail - Only interested in a the last couple of lines in a file? tail allows you to quickly view the end of the file
- Usage:
tail <options> <file>
- Example:
tail -fn100 production.log
- Shows the last 100 lines of the log and waits to display any new text appended to the file
- Usage:
- ssh - Log into remote servers
- Usage:
ssh -p<port> <username>@<hostname>
- Example:
ssh -p1234 theo@production
- Logs into the server named production on port 1234
- Usage:
- scp - Copies files to/from remote servers
- Usage:
scp -P<port> <source> <target>
- Example:
scp -P1234 /home/theo/myfile.txt production@/home/jsmith
- Copies
myfile.txt
from/home/theo
to the server named production under/home/jsmith
- Copies
- Usage:
- rm - Deletes stuff!
- Usage:
rm <options> <file>
- Example:
rm -rf mydir
- Removes the entire directory and files with no prompt for confirmation (Use with caution!)
- Usage:
- ps - Shows process status
- Usage:
ps <options>
- Example:
ps aux
- Displays the process status of processes for all users including those that are controlled by a terminal (system processes) sorted by CPU usage
- Usage:
- top - Similar to ps but it periodically updates the information such as CPU and memory usage
- Usage: top
- Example: top (duh!)
- kill - terminates a process
- Usage: kill <option> <pid>
- Example: kill -9 12345
- Terminates the process with id of 12345 using a non-catchable, non-ignorable signal (that just means you REALLY mean to kill it)
>> ps aux | grep tomcat
>> kill -9 <tomcat-pid>