Saturday, June 19

Ten Linux Commands Every Web Developer Should Know

Intimidated by the Linux command line? Ease into the interface by taking advantage of these ten easy yet powerful commands.


In the early days of the Web, you could build an appealing portfolio with little more than a basic understanding of HTML and a server-side scripting language such as PHP. Although these days the learning curve for developing websites remains remarkably shallow, the industry's growing complexity requires today's professional developer to embrace a variety of technologies. For many developers, this shift hasn't come willfully; in fact, many developers still choose to limit their interaction with the Web server to uploading files via an FTP client. This approach leaves developers unable to manage website assets effectively, monitor server performance, and easily carry out other tasks that are otherwise time-consuming and tedious.


In this article, I'll introduce you to 10 indispensable Linux commands that can make your web development work much easier and even more enjoyable. Whether you prefer to limit your Linux exposure to the occasional SSH session, or have recently switched your desktop operating system to a Linux distribution such as Ubuntu, these 10 commands will hopefully prompt you to begin making your own investigations into the power of the Linux command-line.




1. Retrieving a Software Package

If you need to install some software by retrieving the source package, you can save a step from the process of downloading the package to your laptop and then transferring the file anew via FTP client. Instead, just retrieve the package directly from your web server using the wget command. For instance, to retrieve the latest version of the Zend Framework you can just copy the download link directly from the Zend Framework website and then pass it to the wget command like this:
%>wget http://framework.zend.com/
releases/ZendFramework-1.10.3/
ZendFramework-1.10.3-minimal.tar.gz

2. Monitoring Server Processes

These days a typical website is powered by much more than just a few HTML pages, often relying on various regularly executing server-side scripts to carry out a variety of maintenance-related tasks. You can keep tabs on your server's executing processes using the top command. This command provides you with a real-time overview of the server's processor activity and memory consumption, listing all processes, the process owner, percentage of CPU used, and duration of execution. To execute top, just run the command from the command line without any accompanying options (although other options are supported) %>top
...
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                      
 2121 wjgilmor  20   0  956m 389m  44m R   66 13.5   1692:22 firefox                                                                      
 1136 root      20   0  126m  42m  16m S   12  1.5  67:22.95 Xorg                                                                         
 7297 wjgilmor  20   0  119m  41m  16m S    4  1.4  25:19.19 filezilla                                                                    
 1919 wjgilmor  20   0 95828 9.8m 7908 S    2  0.3  38:54.57 pulseaudio                                                                   
14159 wjgilmor  20   0  2468 1084  784 R    2  0.0   0:00.02 top                                                                          
    1 root      20   0  2660 1528 1128 S    0  0.1   0:01.05 init
3. Reviewing Log Files
You'll often need to review your server's log files to monitor and 
resolve any unexpected errors and other issues. Of course, these log 
files have a tendency to grow as rapidly as your traffic volume. Many 
novice Linux users will be familiar with the DOS more 
command, which they use to page through even large log files. Linux 
offers a far more efficient method for reviewing files, particularly the
 "end" of files: using the tail command. For instance, to 
display the last 10 lines of a file just pass the file to the tail
 command:


%>tail /var/log/apache/error.log
You can use the -n switch to specify a larger number of 
lines, additionally using the more command to view the 
output one screen at a time:

%>tail -n 100 /var/log/apache/error.log | more 
To interactively output the newly appended lines as they appear in the 
file, you can use the -f switch, which will refresh the 
output every few seconds:
%>tail -f /var/log/apache/error.log

4. Copying Files with scp
An FTP client such as FileZilla works well for transferring files between a developer's laptop and web server, but what about when you need to transfer a file while in the midst of an SSH session? Rather than go through the hassle of logging into the server anew using an FTP client, consider using the scp (secure copy) command.
%>scp id_rsa.pub webuser@192.168.1.103:/home/webuser/.ssh/id_rsa.pub

In this example, I copy the file id_rsa.pub to the web 
server identified by the IP address 192.168.1.103 using the server 
account webuser, and placing the file in the directory /home/webuser/.ssh/.
....

Rest Commands would be in next post....

No comments:

Post a Comment