Command Line Tools Every PHP Developer Should Know About<br />By Andrew Kandels<br />
File Operations<br />tail -f  Output appended data as the file grows<br />Filter output with egrep: tail –f /log/file | eg...
strace<br />Traces the name of every system call, its arguments and return value.<br />Trick for strace’ing web requests:<...
Bash Command History<br />/etc/profile Improvements<br />export HISTCONTROL=erasedups<br />export HISTSIZE=10000<br />shop...
Get Some Stats<br />Step #1: Is there a problem? Get the CPU load.<br />1m      5m     15m<br />mpstat			CPU stats<br />io...
screen<br />Recoverable screen manager that emulates a VT100/ANSI terminal.<br />CTRL-a <command><br />cCreate new window<...
processes<br />ps –aux		List all processes<br />pstree –p		List processes in a tree (parent/child)<br />htop			Interactive...
There’s a Command For That<br />strings <file>		List readable strings in a binary (or any) file<br />file <file>			What ki...
awk<br />Pattern scanning and text processing language (it’s like pixie dust in vim)<br />    NR = Number or Records read ...
httperf<br />http://www.hpl.hp.com/research/linux/httperf/<br />Stress test your server by simulating web traffic.<br />Be...
Upcoming SlideShare
Loading in...5
×

Command Line Tools Every PHP Developer Should Know About

2,513
-1

Published on

With the increasing selection of modern IDEs supporting the PHP syntax and their bells and whistles, developers often lose sight of the command line and all of the utility it offers. Working with GNU tools can be a great way to identify problems, come up with creative and time saving solutions, and bolster your development productivity. I'll cover a variety of must-know commands you might not know about so that you can be prepared for your next big problem.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,513
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Command Line Tools Every PHP Developer Should Know About

  1. 1. Command Line Tools Every PHP Developer Should Know About<br />By Andrew Kandels<br />
  2. 2. File Operations<br />tail -f Output appended data as the file grows<br />Filter output with egrep: tail –f /log/file | egrep “ip-address”<br />lsof List open files (think of “ls open files”)<br />
  3. 3. strace<br />Traces the name of every system call, its arguments and return value.<br />Trick for strace’ing web requests:<br />strace –o /tmp/webtraffic.log –f /etc/init.d/apache2 start &<br />tail –f /tmp/webtraffic.log | egrep “No such file”<br />
  4. 4. Bash Command History<br />/etc/profile Improvements<br />export HISTCONTROL=erasedups<br />export HISTSIZE=10000<br />shopt -shistappend<br />!! Run last command<br />!string Run last command that matches string<br />!$ Last argument from last command (bang-bling)<br />CTRL-R Search/auto-complete command history<br />$? Exit code from last command (0 = win)<br />
  5. 5. Get Some Stats<br />Step #1: Is there a problem? Get the CPU load.<br />1m 5m 15m<br />mpstat CPU stats<br />iostat File I/O stats<br />top/htop Process/various other stats<br />cat /proc/loadavg Load averages<br />netstat Network stats<br />free -m Free memory/swap stats<br />netstat –tlpGet the listening TCP sockets (what ports are open)<br />
  6. 6. screen<br />Recoverable screen manager that emulates a VT100/ANSI terminal.<br />CTRL-a <command><br />cCreate new window<br />“ List windows<br />If you lose your connection, use screen –list to list previous screen sessions, and <br />screen –r # to recover a session:<br />
  7. 7. processes<br />ps –aux List all processes<br />pstree –p List processes in a tree (parent/child)<br />htop Interactively list all processes (with tree option)<br />apachetop View Apache connections interactively<br />mytop View MySQL queries interactively<br />iotop View I/O operations interactively<br />
  8. 8. There’s a Command For That<br />strings <file> List readable strings in a binary (or any) file<br />file <file> What kind of file is it?<br />stat <file> atime, ctime, mtime, size, type, inode<br />dig <url> Resolve a domain name into an IP address (and measure)<br />arp –a View the local ARP cache<br />cat /proc/cpuinfo How many CPUs do I have?<br />free –m How much memory am I using?<br />df –h How much disk space am I using?<br />du –ch /path How much space is a folder using?<br />echo $((2*4)) Quick math<br />
  9. 9. awk<br />Pattern scanning and text processing language (it’s like pixie dust in vim)<br /> NR = Number or Records read so far<br /> NF = Number of Fields in current record<br /> FS = the Field Separator<br /> RS = the Record Separator<br /> BEGIN = a pattern that's only true before processing any input<br /> END = a pattern that's only true after processing all input.<br />sed<br />Stream editor to replace text in file(s), delete lines and so much more.<br />In-place replace 2010 copyrights with 2011 in all PHP files:<br />find . –type f –name “*.php” –exec sed -I’’ ‘s/Copyright 2010/Copyright 2011/g’ ;<br />
  10. 10. httperf<br />http://www.hpl.hp.com/research/linux/httperf/<br />Stress test your server by simulating web traffic.<br />Beat the crap out of your server:<br />for x in {1..10}; do<br />httperf --hog –server=domain.com –wsess=250,5,10 --burst-length=5 --rate 100 --timeout 5 --uri /path/to/file<br /> echo “Run #$x… “<br /> sleep 1<br />done<br />250 – Number of clients<br />100 – Requests per second<br />Test load (server side):<br />while [ true ]; do uptime; sleep 5; done<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×