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:
- 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)
I use lots of these commands in combination. For example, if tomcat seems to hang and won’t properly shut down I would do the following:
>> ps aux | grep tomcat
I would then take the pid of tomcat and run:
>> kill -9 <tomcat-pid>
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?
sudo “make me a sandwich” 🙂
awk, sed, cut, sort, and find.
and the best one of all: man
also, try kill -9 `pidof tomcat`
I simply can’t believe you left out both “find” and “less” on that list 🙂
instead of using kill -9 `pidof tomcat`, just do a pgrep -f -l. once you’ve confirmed that those are the processes you want to kill, pkill -f
Ugh.. that should be pgrep -f [pattern] -l and pkill -f [pattern]
sudo rm -vfR /mnt/windows
😛
‘split’ and ‘wc’
And ‘tar’. 🙂
People who use kill -9 should be smacked on their heads.
http://sial.org/howto/shell/kill-9/