<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Open source blog, linux, php, python, security &#187; command</title>
	<atom:link href="http://www.alonon.net/tag/command/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alonon.net</link>
	<description></description>
	<lastBuildDate>Wed, 02 Jun 2010 08:11:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>

   <image>
    <title>Open source blog, linux, php, python, security</title>
    <url>http://1.gravatar.com/avatar/5152c5736f5f8dd9570ffb2f9068e8ab?s=</url>
    <link>http://www.alonon.net</link>
   </image>
		<item>
		<title>SSH Shell Commands</title>
		<link>http://www.alonon.net/ssh-shell-commands/</link>
		<comments>http://www.alonon.net/ssh-shell-commands/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 14:37:49 +0000</pubDate>
		<dc:creator>ALonon</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.alonon.net/?p=72</guid>
		<description><![CDATA[I moved my vps so i need some ssh commands, i found very usefull article for ssh command. ls : list files/directories in a directory, comparable to dir in windows/dos. ls -al : shows all files (including ones that start with a period), directories, and details attributes for each file. cd : change directory · &#8230; <a href="http://www.alonon.net/ssh-shell-commands/">Read more <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I moved my vps so i need some ssh commands, i found very usefull article for ssh command.</p>
<p><strong>ls </strong>: list files/directories in a directory, comparable to dir in windows/dos.<br />
<em>ls -al</em> : shows all files (including ones that start with a period), directories, and details attributes for each file.</p>
<p><strong>cd </strong>: change directory · · cd /usr/local/apache : go to /usr/local/apache/ directory<br />
<em>cd ~ </em>: go to your home directory<br />
<em>cd -</em> : go to the last directory you were in<br />
<em>cd .. </em>: go up a directory cat : print file contents to the screen</p>
<p><em>cat filename.txt </em>: cat the contents of filename.txt to your screen</p>
<p><strong>chmod:</strong> changes file access permissions<br />
The set of 3 go in this order from left to right:<br />
USER &#8211; GROUP &#8211; EVERONE<br />
0 = &#8212;  No permission<br />
1 = &#8211;X  Execute only<br />
2 = -W-  Write only<br />
3 = -WX  Write and execute<br />
4 = R&#8211;  Read only<br />
5 = R-X  Read and execute<br />
6 = RW-  Read and write<br />
7 = RWX  Read, write and execute</p>
<p>Usage:<br />
chmod numberpermissions filename</p>
<p><span class="green">chmod 000</span> : No one can access<br />
<span class="green">chmod 644</span>: Usually for HTML pages<br />
<span class="green">chmod 755</span>: Usually for CGI scripts</p>
<p><strong>chown</strong>: changes file ownership permissions<br />
The set of 2 go in this order from left to right:<br />
USER &#8211; GROUP</p>
<p><span class="green">chown root myfile.txt</span> : Changes the owner of the file to root<br />
<span class="green">chown root.root myfile.txt</span> : Changes the owner and group of the file to root</p>
<p><strong>tail</strong> : like cat, but only reads the end of the file<br />
<em>tail /var/log/messages </em>: see the last 20 (by default) lines of /var/log/messages<br />
<em>tail -f /var/log/messages </em>: watch the file continuously, while it&#8217;s being updated<br />
<em>tail -200 /var/log/messages </em>: print the last 200 lines of the file to the screen</p>
<p><strong>more</strong><em> </em>: like cat, but opens the file one screen at a time rather than all at once<br />
<em>more /etc/userdomains </em>: browse through the userdomains file. hit <em>Space</em>to go to the next page, <em>q</em> to quit</p>
<p><strong>pico</strong> : friendly, easy to use file editor<br />
<em>pico /home/burst/public_html/index.html </em>: edit the index page for the user&#8217;s website.</p>
<p><strong>File Editing with VI ssh commands</strong><br />
<strong>vi</strong> : another editor, tons of features, harder to use at first than pico<br />
<em>vi /home/burst/public_html/index.html </em>: edit the index page for the user&#8217;s website.<br />
Whie in the vi program you can use the following useful commands, you will need to hit SHIFT + : to go into command mode</p>
<p><span class="green">:q! </span>: This force quits the file without saving and exits vi<br />
<span class="green">:w</span> : This writes the file to disk, saves it<br />
<span class="green">:wq</span> : This saves the file to disk and exists vi<br />
<span class="green">:LINENUMBER</span> : EG :25 : Takes you to line 25 within the file<br />
<span class="green">:$ </span>: Takes you to the last line of the file<br />
<span class="green">:0</span> : Takes you to the first line of the file</p>
<p><strong>grep</strong> : looks for patterns in files<br />
<em>grep root /etc/passwd </em>: shows all matches of root in /etc/passwd<br />
<em>grep -v root /etc/passwd </em>: shows all lines that do not match root</p>
<p><strong>ln</strong> : create&#8217;s &#8220;links&#8221; between files and directories<br />
<em>ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf </em>: Now you can edit /etc/httpd.conf rather than the original. changes will affect the orginal, however you can delete the link and it will not delete the original.</p>
<p><strong>last</strong> : shows who logged in and when<br />
<em>last -20 </em>: shows only the last 20 logins<br />
<em>last -20 -a </em>: shows last 20 logins, with the hostname in the last field</p>
<p><strong>w</strong> : shows who is currently logged in and where they are logged in from.<br />
<span class="green">who</span> : This also shows who is on the server in an shell.</p>
<p><strong>netstat</strong> : shows all current network connections.<br />
<em>netstat -an </em>: shows all connections to the server, the source and destination ips and ports.<br />
<em>netstat -rn </em>: shows routing table for all ips bound to the server.</p>
<p><strong>top</strong> : shows live system processes in a nice table, memory information, uptime and other useful info. This is excellent for managing your system processes, resources and ensure everything is working fine and your server isn&#8217;t bogged down.<br />
<em>top</em> then type <em>Shift + M</em> to sort by memory usage or <em>Shift + P </em>to sort by CPU usage</p>
<p><strong>ps: </strong>ps is short for process status, which is similar to the <em>top</em> command. It&#8217;s used to show currently running processes and their PID.<br />
A process ID is a unique number that identifies a process, with that you can kill or terminate a running program on your server (see kill command).<br />
<em>ps U username</em> <em>:</em> shows processes for a certain user<br />
<em>ps aux</em> : shows all system processes<br />
<em>ps aux &#8211;forest</em> : shows all system processes like the above but organizes in a hierarchy that&#8217;s very useful!</p>
<p><strong>touch</strong> : create an empty file<br />
<em>touch /home/burst/public_html/404.html </em>: create an empty file called 404.html in the directory /home/burst/public_html/</p>
<p><strong>file </strong>: attempts to guess what type of file a file is by looking at it&#8217;s content.<br />
<em>file * </em>: prints out a list of all files/directories in a directory</p>
<p><strong>du </strong>: shows disk usage.<br />
<em>du -sh </em>: shows a summary, in human-readble form, of total disk space used in the current directory, including subdirectories.<br />
<em>du -sh * </em>: same thing, but for each file and directory. helpful when finding large files taking up space.</p>
<p><strong>wc : </strong>word count<br />
<em>wc -l filename.txt </em>: tells how many lines are in filename.txt</p>
<p><strong>cp </strong>: copy a file<br />
<em>cp filename filename.backup </em>: copies filename to filename.backup<br />
<em>cp -a /home/burst/new_design/* /home/burst/public_html/ </em>: copies all files, retaining permissions form one directory to another.<br />
<span class="green">cp -av * ../newdir</span> : Copies all files and directories recurrsively in the current directory INTO newdir</p>
<p><strong>mv</strong> : Move a file command<br />
<span class="green">mv oldfilename newfilename </span>: Move a file or directory from oldfilename to newfilename</p>
<p><strong>rm </strong>: delete a file<br />
<em>rm filename.txt </em>: deletes filename.txt, will more than likely ask if you really want to delete it<br />
<em>rm -f filename.txt </em>: deletes filename.txt, will not ask for confirmation before deleting.<br />
<em>rm -rf tmp/</em> : recursively deletes the directory tmp, and all files in it, including subdirectories. BE VERY CAREFULL WITH THIS COMMAND!!!<br />
<strong><br />
TAR</strong>: Creating and Extracting .tar.gz and .tar files<br />
<span class="green">tar -zxvf file.tar.gz</span> : Extracts the file<br />
<span class="green">tar -xvf file.tar</span> : Extracts the file<br />
<span class="green">tar -cf archive.tar contents/</span> : Takes everything from contents/ and puts it into archive.tar<br />
<span class="green">gzip -d filename.gz</span> : Decompress the file, extract it</p>
<p><strong>ZIP Files</strong>:  Extracting .zip files shell command<br />
<span class="green">unzip file.zip</span></p>
<p><strong>Firewall - iptables commands<br />
</strong><span class="green">iptables -I INPUT -s IPADDRESSHERE -j DROP</span> : This command stops any connections from the IP address<br />
<span class="green">iptables -L </span>: List all rules in iptables<br />
<span class="green">iptables -F</span> : Flushes all iptables rules (clears the firewall)<br />
<span class="green">iptables &#8211;save</span> : Saves the currenty ruleset in memory to disk<br />
<span class="green">service iptables restart</span> : Restarts iptables</p>
<p><strong>Apache Shell Commands</strong><br />
<span class="green">httpd -v</span> : Outputs the build date and version of the Apache server.<br />
<span class="green">httpd -l</span> : Lists compiled in Apache modules<br />
<span class="green">httpd status</span> : Only works if mod_status is enabled and shows a page of active connections<br />
<span class="green">service httpd restart</span> : Restarted Apache web server</p>
<p><strong>MySQL Shell Commands</strong><br />
<span class="green">mysqladmin processlist</span> : Shows active mysql connections and queries<br />
<span class="green">mysqladmin drop databasenamehere</span> : Drops/deletes the selected database<br />
<span class="green">mysqladmin create databasenamehere</span> : Creates a mysql database</p>
<p>Restore MySQL Database Shell Command<br />
<span class="green">mysql -u username -p password databasename &lt; databasefile.sql</span> : Restores a MySQL database from databasefile.sql</p>
<p>Backup MySQL Database Shell Command<br />
<span class="green">mysqldump -u username -p password databasename &gt; databasefile.sql </span>: Backup MySQL database to databasefile.sql</p>
<p><strong>kill: </strong>terminate a system process<br />
<em>kill -9 PID</em> EG: <em>kill -9 431<br />
kill PID </em>EG: <em>kill 10550</em><br />
Use <em>top</em> or <em>ps ux </em>to get system PIDs (Process IDs)</p>
<p>EG:</p>
<table border="0">
<tbody>
<tr>
<td>PID</td>
<td>TTY</td>
<td>TIME</td>
<td>COMMAND</td>
</tr>
<tr>
<td>10550</td>
<td>pts/3</td>
<td>0:01</td>
<td>/bin/csh</td>
</tr>
<tr>
<td>10574</td>
<td>pts/4</td>
<td>0:02</td>
<td>/bin/csh</td>
</tr>
<tr>
<td>10590</td>
<td>pts/4</td>
<td>0:09</td>
<td>APP</td>
</tr>
</tbody>
</table>
<p>Each line represents one process, with a process being loosely defined as a running instance of a program. The column headed PID (process ID) shows the assigned process numbers of the processes. The heading COMMAND shows the location of the executed process.</p>
<p><strong>Putting commands together</strong><br />
Often you will find you need to use different commands on the same line. Here are some examples. Note that the | character is called a pipe, it takes date from one program and pipes it to another.<br />
<em>&gt;</em> means create a new file, overwriting any content already there.<br />
<em>&gt;&gt;</em> means tp append data to a file, creating a newone if it doesn not already exist.<br />
<em>&lt;</em> send input from a file back into a command.</p>
<p><em>grep User /usr/local/apache/conf/httpd.conf |more<br />
</em>This will dump all lines that match User from the httpd.conf, then print the results to your screen one page at a time.</p>
<p><em>last -a &gt; /root/lastlogins.tmp</em><br />
This will print all the current login history to a file called lastlogins.tmp in /root/</p>
<p><em>tail -10000 /var/log/exim_mainlog |grep domain.com |more<br />
</em>This will grab the last 10,000 lines from /var/log/exim_mainlog, find all occurances of domain.com (the period represents &#8216;anything&#8217;,<br />
&#8211; comment it out with a so it will be interpretted literally), then send it to your screen page by page.</p>
<p><em>netstat -an |grep :80 |wc -l<br />
</em>Show how many active connections there are to apache (httpd runs on port 80)</p>
<p><em>mysqladmin processlist |wc -l<br />
</em>Show how many current open connections there are to mysql</p>
<p>I take from <a href="http://www.webhostgear.com/35.html">here</a></p>

	Tags: <a href="http://www.alonon.net/tag/command/" title="command" rel="tag">command</a>, <a href="http://www.alonon.net/tag/shell/" title="shell" rel="tag">shell</a>, <a href="http://www.alonon.net/tag/ssh/" title="ssh" rel="tag">ssh</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.alonon.net/user-groups-and-users-in-ubuntu/" title="User groups and Users in Ubuntu (March 16, 2010)">User groups and Users in Ubuntu</a> (0)</li>
	<li><a href="http://www.alonon.net/sending-email-in-ssh/" title="Sending e-mail in ssh (March 4, 2010)">Sending e-mail in ssh</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.alonon.net/ssh-shell-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
