Recent Edits
Shell Programming Beginners Class Lesson 2 - Variables
<p>This is the second installment of Shell Programming Beginners Class. <a href="http://bashcurescancer.com/shell_programming_beginners_class_lesson_1_motivation.html">The...
» complete change<p>This is the second installment of Shell Programming Beginners Class. <a href="http://bashcurescancer.com/shell_programming_beginners_class_lesson_1_motivation.html">The first installment was on motivation.</a></p>
<p>Variables are the heart of programming. They allow you to do something with a value which you do not know. In practical terms lets say we have a program or script which takes one integer value (Ex: 1, 2, 3, 4, …) and simply adds 1 to that value. You give it 5, it gives you 6. Not very useful. However, in that program you are going to have to call whatever number the user gives you something. When writing the program you obvivously do not know what value the user is going to enter. They may not even enter an integer. Lets assume they will indeed give you an integer, for now. Whatever you call the number which the user gives you is the name of the VARIABLE.</p>
<p>Lets say I call the user inputed value IN_INT, then my variable name would be IN_INT. In BASH when I wanted to use the value of that variable (Ex: 6 ) then I would prefix the variable name with a dollar sign, $.</p>
<p>Here is our sample program: (All your programs must start with #!/bin/bash and must be executable, chmod 744 filename.)<br />
<code><br />
# cat addOne.sh<br />
#!/bin/bash<br />
echo "Type an integer and press enter: "<br />
read IN_INT<br />
echo "You entered $IN_INT to the program."<br />
echo "Here is your output master: " `expr $IN_INT + 1`</code></p>
<p>I will run the script:<br />
<code><br />
# ./addOne.sh<br />
Type an integer and press enter: 6<br />
You entered 6 to the program.<br />
Here is your output master: 7</code></p>
<p>Following along? If not send me an email: <a href="http://spamdefeator.com"><img border="0" width="180" src="http://spamdefeator.com/u/5d0" alt="SpamDefeator" height="15" /></a>.</p>
<p>In BASH variables can be numbers or strings. Example:<br />
<code><br />
# STR1="this is a string."<br />
# echo $STR1<br />
this is a string. </code><code></code><code># STR2=THIS_IS_A_STRING_WITH_NO_SPACES<br />
# echo $STR2<br />
THIS_IS_A_STRING_WITH_NO_SPACES</code><code># INT1=21<br />
# echo $INT1<br />
21</p>
<p>You can also assign the output of a command to a variable with the ` or backtick character:<br />
<code><br />
# pwd<br />
/root<br />
# CWD=`pwd`<br />
# echo $CWD<br />
/root</code></p>
<p></code>You can perform mathematic operations on variables in a few different ways. The simplest is the expr command. expr allows you to add, substract, multiply, divide, find remainders, test values against other values, and a whole range of other things. I used expr above to add one to a number. Read the manual page of <a href="http://bashcurescancer.com/man/cmd/expr">expr</a> if would like to learn more.</p>
<p>If you would like to learn more please read the next article in this series <a href="http://bashcurescancer.com/shell_programming_beginners_class_lesson_3_essential_commands.html">Shell Programming Beginners Class Lesson 3 - Essential Commands</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BashCuresCancer?a=rdHElCrv"><img src="http://feeds.feedburner.com/~f/BashCuresCancer?i=rdHElCrv" border="0"></img></a>
</div>
OpenBSD 4 Installed in 20 Minutes
<p>After reading a post on <a target="_new" href="http://commandline.org.uk/2006/my-hairy-five-minutes-with-openbsd/">Command...
» complete change<p>After reading a post on <a target="_new" href="http://commandline.org.uk/2006/my-hairy-five-minutes-with-openbsd/">Command Line Warriors</a> I decided to try the OpenBSD 4.0 installation. My third attempt was successful. The first one I spent trying to figure out their fdisk utility and finally had to quit and give it a fresh go. The second worked fine but I needed another go in order to get clean screen shots as I made a few mistakes.</p>
<p><em>Note: Using the steps below will destroy any data on your disk. Use a spare.</em></p>
<p><em>Note: If you would like to read it or run into problems, here is the the <a href="http://bashcurescancer.com/media/openbsd-4.0-install/INSTALL.i386">official documentation for OpenBSD 4.0 on a i386</a>.</em></p>
<ol>
<li>Getting the installation ISO. Find an <a href="http://www.openbsd.org/ftp.html">OpenBSD mirror</a> to download the installation environment. The file is<br />
called cd40.iso.</li>
<li>It will start booting in a few seconds (or I believe you can press enter).<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/A-boot-install-cd.png" alt="Install cd boot prompt" height="356" title="Install cd boot prompt" class="screenshot" /></li>
<li>(I)nstall, (U)pgrade, or just get a (S)hell.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/B-install-uprgrade-shell.png" alt="(I)nstall, (U)pgrade, or just get a (S)hell" height="356" title="Choose I" class="screenshot" /></li>
<li>Terminal type. I used the default.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/C-terminal-type.png" alt="Terminal type, press enter" height="356" title="Terminal type, press enter" class="screenshot" /></li>
<li>Set keymap.<br />
<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/D-key-mapping.png" alt="Choose us for US keymapping" height="356" title="Choose us for US keymapping" class="screenshot" /></li>
<li>Are you sure? Yes.<br />
<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/E-are-you-sure.png" alt="Are you sure?" height="356" title="Are you sure?" class="screenshot" /></li>
<li>Which disk? I only had one so I pressed enter. Do you want to use the entire disk? Yes. This creates a whole disk<br />
OpenBSD “slice” which you will make into partitions in the next step.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/F-choose-disk-confirm.png" alt="Which disk? Use default" height="356" title="Which disk? Use default" class="screenshot" /></li>
<li>This is the tricky part. It puts you into an odd fdisk (for non BSD users). <strong>The options are NOT the same as Linux or Windows fdisk</strong>. The p command prints the current drive configuration. Basically you DO NOT want to delete the c partition. Its the whole disk slice which was created in the step above.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/G-print-disk.png" alt="Press p to print the configuration" height="356" title="Press p to print the configuration" class="screenshot" /></li>
<li>Delete everything but the c partition with the d command.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/H-delete-partition.png" height="356" class="screenshot" /></li>
<li>Create a new partition with the a command. It will then ask you for the name, offset, size, type, and mount point. Leave the name and offset as the default. You need to leave some space for swap so I used 3GB of my 4GB disk. You can use M to specify Megabytes. Thus 3GB is 3000M. It then conveniently assumes you want the BSD filesystem type. Choose / as your mount point. Now we have to create the swap partition. Its more of the same. Just press a and use the defaults. I am running this through VMWare so I chose a large swap partition.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/I-creating-root-swap-part.png" alt="Creating the root and swap partitions" height="356" title="Creating the root and swap partitions" class="screenshot" /></li>
<li>Once the disks are setup press q to quit and then confirm.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/J-writing-new-disk.png" alt="Press q to quit and then confirm" height="356" title="Press q to quit and then confirm" class="screenshot" /></li>
<li>The next screen is the network options. I chose thirdtry as my hostname and dhcp as my method of obtaining my ipaddress otherwise I just used the defaults.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/K-setup-ipv4.png" alt="Network options, I chose dhcp" height="356" title="Choose dhcp" class="screenshot" /></li>
<li>Enter the root password and confirm<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/L-root-password.png" alt="Choose a root password" height="356" title="Choose a root password" class="screenshot" /></li>
<li>If your following these instructions choose http as the location of the sets and then type yes to display the list of known http servers:<br />
<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/M-install-method.png" alt="Choose http and yes to display a list of servers" height="356" title="Choose http" class="screenshot" /></li>
<li>Your in <a href="http://bashcurescancer.com/man/cmd/more">more</a> so press the space bar to see the next page. The US servers are at the bottom.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/N-select-http-server-p1.png" alt="Find a mirror near you" height="356" title="Pick a mirror near you" class="screenshot" /></li>
<li>Choose a mirror near your location and accept the default server directory.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/O-select-http-server-p2.png" alt="Choose a mirror and accept the default server directory" height="356" title="Choose a mirror" class="screenshot" /></li>
<li>Are you ready? Yes.<br />
<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/P-intall-sets.png" alt="Are you ready to install OpenBSD 4.0?" height="356" title="Are you ready?" class="screenshot" /></li>
<li><strong>Installing!<br />
</strong><img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/Q-installing.png" alt="OpenBSD is installing" height="356" title="Instaling...." class="screenshot" /></li>
<li>Once the download is complete it will ask you again for the location of the sets. <strong>This is for extra packages such as X</strong>. I chose the default of done and did not install any extra packages.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/R-location-of-sets.png" alt="Location of sets again, this is for extra packages. Press enter" height="356" title="Press enter" class="screenshot" /></li>
<li>Choose the the defaults except for timezone.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/S-misc-settings.png" alt="Choose the the defaults except for timezone" height="356" title="Choose the the defaults" class="screenshot" /></li>
<li>Can it really be installed?<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/T-installed-question-mark.png" alt="Is it really installed" height="356" title="Really?" class="screenshot" /></li>
<li>Type halt and then reboot.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/U-reboot.png" alt="Type halt and then reboot" height="356" title="Reboot" class="screenshot" /></li>
<li><strong>Congratulations you have just installed OpenBSD!</strong><img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/V-booted.png" alt="Congratulations OpenBSD has been installed" height="356" title="Congratulations" class="screenshot" /></li>
</ol>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BashCuresCancer?a=9l83hNQU"><img src="http://feeds.feedburner.com/~f/BashCuresCancer?i=9l83hNQU" border="0"></img></a>
</div>
Shell Programming Beginners Class Lesson 3 - Essential Commands
<p>Knowing commands is essential to using the command line. It is even more so when programming the command line.<br />
However,...
» complete change<p>Knowing commands is essential to using the command line. It is even more so when programming the command line.<br />
However, you don’t have to know them yet! I can teach you the basics and then you can learn as you go. The most important thing you can possibly get from this article is the next sentence. UNIX/Linux systems have the ENTIRE user manual in neat organized sections relating to the specific command you want to know about. Its called the man pages or manual pages. Just type “man” and then any command. Example “man find”.</p>
<p><em>This is the third installment of Shell Programming Beginners Class. If your reading this article first and would prefer to start from the beginning you can do so here: <a href="http://bashcurescancer.com/shell_programming_beginners_class_lesson_1_motivation.html">motivation</a> or if you would simply like to read the previous article, it is available here: <a href="http://bashcurescancer.com/shell_programming_beginners_class_lesson_2_variables.html">variables</a>.</em></p>
<p>Commands in UNIX/Linux, Windows, and Mac OS all follow the same format. That is “command [options] [arguments]”. Technically options are arguments but who cares. Example “find /home/brock -name ‘ECON1001*’” or “rmdir test_directory”.</p>
<p>Enough already, here is the list in no particular order:</p>
<ol>
<li>cd: change to a different directory</li>
<li><a href="http://bashcurescancer.com/man/cmd/cp">cp</a>: copy files and directories</li>
<li><a href="http://bashcurescancer.com/man/cmd/more">more</a>: used for viewing a file one page a time</li>
<li><a href="http://bashcurescancer.com/man/cmd/less">less</a>: less is more (less is better than ^more^)</li>
<li><a href="http://bashcurescancer.com/man/cmd/mv">mv</a>: mv or <strong>rename</strong> files and directories</li>
<li><a href="http://bashcurescancer.com/man/cmd/vi">vi</a>: a text editor</li>
<li><a href="http://bashcurescancer.com/man/cmd/rmdir">rmdir</a>: remove empty directories</li>
<li><a href="http://bashcurescancer.com/man/cmd/rm">rm</a>: remove files and directories</li>
</ol>
<p>Most of the commands should be self explanatory. cd changes from one directory to another, cp copies things, rm removes<br />
things, and rmdir removes empty directories. Your probably not sure why we have rm and rmdir or possibly what less, more, and vi are.</p>
<p>rmdir exists basically as the “correct” or “safe” way to deal with deleting files and directories. The command line does not have a trash bin. When its gone its gone. Thus typically rm has the -i option enabled by default which asks your to confirm EVERY SINGLE TIME you want to delete a file. Then your supposed to remove all the files in a directory and then and only then delete it with rmdir. So what does everyone do when they want to delete something? “rm -rf”.</p>
<p>rm -rf is joking called the nuclear option in some very dorky circles. It deletes recursive and does not prompt. Running “rm -rf /” will bring your system down and delete everything on your hard disk.</p>
<p>When using the command line you typically have a small window where you type in your commands. As you type in commands<br />
the output scrolls to the top of the window and then eventually disappears after you have scrolled all the way up. Thus<br />
the need for more and less. They allow you to view a file one page a time. Less is more, than more.</p>
<p>vi is the windows notepad of UNIX/Linux although its very hard to learn for new people. If you have the command “nano”<br />
or “pico” available (just type it in) and are getting distressed with vi, give them a try. I’d rather have you never learn<br />
vi than to never learn the command line because of vi.</p>
<p>If you have no idea what I am talking about, here is a few sample commands being executed. When the user types “vi file”<br />
they would see a screen which you will not see below. But after closing vi they would return to seeing what we see below. The user copies a file, edits the new file, and then removes the old one. Looks like some cheating is going on.</p>
<pre>
# cp econ1101-brad.doc econ1101-jessica.doc
# vi econ1101-jessica.doc
# rm econ1101-brad.doc</pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BashCuresCancer?a=wUkKA5K6"><img src="http://feeds.feedburner.com/~f/BashCuresCancer?i=wUkKA5K6" border="0"></img></a>
</div>
10 Linux commands you’ve never used
<p>It takes years maybe decades to master the commands available to you at the Linux shell prompt. Here are 10 that<br />...
» complete change<p>It takes years maybe decades to master the commands available to you at the Linux shell prompt. Here are 10 that<br />
you will have never heard of or used. They are in no particular order. My favorite is mkfifo.</p>
<ol>
<li><a href="http://bashcurescancer.com/man/cmd/pgrep">pgrep</a>, instead of:<br />
<code><br />
# ps -ef | egrep '^root ' | awk '{print $2}'<br />
1<br />
2<br />
3<br />
4<br />
5<br />
20<br />
21<br />
38<br />
39<br />
...<br />
</code>You can do this:<code><br />
# pgrep -u root<br />
1<br />
2<br />
3<br />
4<br />
5<br />
20<br />
21<br />
38<br />
39<br />
...<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/pstree">pstree</a>, list the processes in a tree format. This can be VERY useful when working with WebSphere or other heavy duty applications.<br />
<code><br />
# pstree<br />
init-+-acpid<br />
|-atd<br />
|-crond<br />
|-cups-config-dae<br />
|-cupsd<br />
|-dbus-daemon-1<br />
|-dhclient<br />
|-events/0-+-aio/0<br />
| |-kacpid<br />
| |-kauditd<br />
| |-kblockd/0<br />
| |-khelper<br />
| |-kmirrord<br />
| `-2*[pdflush]<br />
|-gpm<br />
|-hald<br />
|-khubd<br />
|-2*[kjournald]<br />
|-klogd<br />
|-kseriod<br />
|-ksoftirqd/0<br />
|-kswapd0<br />
|-login---bash<br />
|-5*[mingetty]<br />
|-portmap<br />
|-rpc.idmapd<br />
|-rpc.statd<br />
|-2*[sendmail]<br />
|-smartd<br />
|-sshd---sshd---bash---pstree<br />
|-syslogd<br />
|-udevd<br />
|-vsftpd<br />
|-xfs<br />
`-xinetd<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/bc">bc</a> is an arbitrary precision calculator language. Which is great. I found it useful in that it can perform square root operations in shell scripts. <a href="http://bashcurescancer.com/man/cmd/expr">expr</a> does not support square roots.<br />
<code><br />
# ./sqrt<br />
Usage: sqrt number<br />
# ./sqrt 64<br />
8<br />
# ./sqrt 132112<br />
363<br />
# ./sqrt 1321121321<br />
36347<br />
</code>Here is the script:<code><br />
# cat sqrt<br />
#!/bin/bash<br />
if [ $# -ne 1 ]<br />
then<br />
echo 'Usage: sqrt number'<br />
exit 1<br />
else<br />
echo -e "sqrt($1)\nquit\n" | bc -q -i<br />
fi<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/split">split</a>, have a large file that you need to split into smaller chucks? A mysqldump maybe? split is your command. Below I split a 250MB file into 2 megabyte chunks all starting with the prefix LF_.<br />
<code><br />
# ls -lh largefile<br />
-rw-r--r-- 1 root root 251M Feb 19 10:27 largefile<br />
# split -b 2m largefile LF_<br />
# ls -lh LF_* | head -n 5<br />
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_aa<br />
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_ab<br />
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_ac<br />
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_ad<br />
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_ae<br />
# ls -lh LF_* | wc -l<br />
126<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/nl">nl</a> numbers lines. I had a script doing this for me for years until I found out about nl.<br />
<code><br />
# head wireless.h<br />
/*<br />
* This file define a set of standard wireless extensions<br />
*<br />
* Version : 20 17.2.06<br />
*<br />
* Authors : Jean Tourrilhes - HPL<br />
* Copyright (c) 1997-2006 Jean Tourrilhes, All Rights Reserved.<br />
*/#ifndef _LINUX_WIRELESS_H<br />
# nl wireless.h | head<br />
1 /*<br />
2 * This file define a set of standard wireless extensions<br />
3 *<br />
4 * Version : 20 17.2.06<br />
5 *<br />
6 * Authors : Jean Tourrilhes - HPL<br />
7 * Copyright (c) 1997-2006 Jean Tourrilhes, All Rights Reserved.<br />
8 */9 #ifndef _LINUX_WIRELESS_H</p>
<p></code></li>
<li><a href="http://bashcurescancer.com/man/cmd/mkfifo">mkfifo</a> is the coolest one. Sure you know how to create a pipeline piping the output of grep to less or maybe even perl. But do you know how to make two commands communicate through a named pipe?First let me create the pipe and start writing to it:
<p><img width="640" src="http://bashcurescancer.com/media/10-linux-commands-youve-never-used/mkfifo-write-to-pipe.png" alt="mkfifo pipe; tail file > pipe" height="357" title="Making the pipe and writing to it" class="screenshot" /></p>
<p>Then read from it:</p>
<p><img width="642" src="http://bashcurescancer.com/media/10-linux-commands-youve-never-used/read-from-pipe.png" alt="cat pipe" height="360" title="Reading from the pipe" class="screenshot" /></li>
<li><a href="http://bashcurescancer.com/man/cmd/ldd">ldd</a>, want to know which Linux thread library java is linked to?<br />
<code><br />
# ldd /usr/java/jre1.5.0_11/bin/java<br />
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x00bd4000)<br />
libdl.so.2 => /lib/libdl.so.2 (0x00b87000)<br />
libc.so.6 => /lib/tls/libc.so.6 (0x00a5a000)<br />
/lib/ld-linux.so.2 (0x00a3c000)<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/col">col</a>, want to save man pages as plain text?<br />
<code><br />
# PAGER=cat<br />
# man less | col -b > less.txt<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/xmlwf">xmlwf</a>, need to know if a XML document is well formed? (A configuration file maybe..)<br />
<code><br />
# curl -s 'http://bashcurescancer.com' > bcc.html<br />
# xmlwf bcc.html<br />
# perl -i -pe 's@<br/>@<br>@g' bcc.html<br />
# xmlwf bcc.html<br />
bcc.html:104:2: mismatched tag<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/lsof">lsof</a> lists open files. You can do all kinds of cool things with this. Like find which ports are open:<br />
<code><br />
# lsof | grep TCP<br />
portmap 2587 rpc 4u IPv4 5544 TCP *:sunrpc (LISTEN)<br />
rpc.statd 2606 root 6u IPv4 5585 TCP *:668 (LISTEN)<br />
sshd 2788 root 3u IPv6 5991 TCP *:ssh (LISTEN)<br />
sendmail 2843 root 4u IPv4 6160 TCP badhd:smtp (LISTEN)<br />
vsftpd 9337 root 3u IPv4 34949 TCP *:ftp (LISTEN)<br />
cupsd 16459 root 0u IPv4 41061 TCP badhd:ipp (LISTEN)<br />
sshd 16892 root 3u IPv6 61003 TCP badhd.mshome.net:ssh->kontiki.mshome.net:4661 (ESTABLISHED)<br />
</code>Note: <a href="http://www.openbsd101.com/">OpenBSD 101</a> pointed out that “lsof -i TCP” a better way to obtain this same information. Thanks!Or find the number of open files a user has. Very important for running big applications like Oracle, DB2, or WebSphere:</p>
<p><code><br />
# lsof | grep ' root ' | awk '{print $NF}' | sort | uniq | wc -l<br />
179<br />
</code></p>
<p>Note: an anonymous commenter pointed out that you can replace sort | uniq with “sort -u”. This is true, I forgot about the -u flag. Thanks!</li>
</ol>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BashCuresCancer?a=4dDEJWTZ"><img src="http://feeds.feedburner.com/~f/BashCuresCancer?i=4dDEJWTZ" border="0"></img></a>
</div>
Improve this Script and Win $100USD
<p>After publishing <a href="http://bashcurescancer.com/10-linux-commands-youve-never-used.html">10 Linux commands you’ve...
» complete change<p>After publishing <a href="http://bashcurescancer.com/10-linux-commands-youve-never-used.html">10 Linux commands you’ve never used</a> I was the benefactor of much feedback as to how I could have used the commands better. Which is great, I certainly do not have all the answers and I love to see the way others do things.</p>
<p>To that end I offering $100USD to the best improvement to this script, <a href="http://bashcurescancer.com/media/scripting_comp_02242007/httpClient.sh">httpClient.sh</a>. I have always wanted a pure BASH http client and thus I put this together last night. Its not perfect, some things are screaming to be fixed. In addition some other features should be added.</p>
<p>The rules:</p>
<ol>
<li>Your work MUST be original.</li>
<li>Your work MUST be derived from the script above.</li>
<li>It CAN NOT use netcat (nc).</li>
<li>It MUST be submitted to me via email to this address: <img border="0" width="180" src="http://spamdefeator.com/u/5d0" alt="SpamDefeator" height="15" />.</li>
<li>The script must contain, as comments, your name, email, and website (if you have one).</li>
<li>It MUST be submitted by March 7th at midnight CST.</li>
<li>Also NOTE that BASH must be compiled with networking support to use the script. I believe most distributions do this, Debian apparently does not.</li>
</ol>
<p>I will judge based on the following in no particular order. There is no need to fix them all, the winner may just fix one, in a really cool way:</p>
<ul>
<li>I would like to see it <a href="http://bashcurescancer.com/exit_status.html">exit with an error status</a> when the server responds with an error.<br />
Meaningful exit status?</li>
<li>Handling white space better.</li>
<li>Storing the headers in an array.</li>
<li>Following the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">HTTP 1.1 RFC</a> more. (HEAD with meaningful exit codes?)</li>
<li>Adding an option to save headers to a file.</li>
<li>Sometimes is printed after the HTML, not sure why.</li>
<li>f19 is printed before the HTML when grabbing google, not sure why.</li>
<li>User agent</li>
<li>I had to institute a timeout on read otherwise it took 3-5 seconds to timeout. I’d like this handled better.</li>
<li>I am not sure what happens when you download binary data or large files.</li>
<li>Better ways of handling things, novel practices, clean code, and of course my opinion.</li>
</ul>
<p><span style="font-weight: bold; font-size: 125%">Chris FA Johnson won with this version of <a href="http://bashcurescancer.com/media/scripting_comp_02242007/ChrisFAJohnsonHttpClient.sh">httpClient.sh</a>! Congratulations Chris! </span></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BashCuresCancer?a=SmSy5Mlq"><img src="http://feeds.feedburner.com/~f/BashCuresCancer?i=SmSy5Mlq" border="0"></img></a>
</div>
<p>Regarding named pipes, <a target="_new" href="http://quantum0726.blogspot.com/">Jayson</a> asks “How is this any...
» complete change<p>Regarding named pipes, <a target="_new" href="http://quantum0726.blogspot.com/">Jayson</a> asks “How is this any different than just redirecting the output from head to a file<br />
and then using head to read the file again? Isn’t a text file fifo anyway?”</p>
<p>In some sense its no different than using a file. However named pipes are much much more than simply using a file to store output. Thanks goes to William for pointing out <a target="_new" href="http://wooledge.org/mywiki/BashFAQ">Greg’s BASH Faq</a> where he eloquently explains:</p>
<blockquote><p>“Named Pipes, also known as FIFOs (”First In First Out”) are well suited for inter-process communication. The advantage over using files as a means of communication is, that processes are synchronized by pipes: <strong>a process writing to a pipe blocks if there is no reader, and a process reading from a pipe blocks if there is no writer.</strong>“</p></blockquote>
<p><a target="_new" href="http://wooledge.org/mywiki/BashFAQ#head-0dcb04b046bf27b407ac100f4aac0f2b6528181b">He has a great example here.</a> Named pipes are useful in some cases in shell programming. However, they are exceedingly useful when used in full fledged programming languages. Lets say you have a process that manages the execution of other processes. Starts and stops them as needed. You can use pipes to communicate with those processes. A great example is<br />
using pipes to read and log the standard input/output of those processes.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BashCuresCancer?a=UiIlHRVi"><img src="http://feeds.feedburner.com/~f/BashCuresCancer?i=UiIlHRVi" border="0"></img></a>
</div>
Merging Split Files
<p>Jesus asks: <strong>I have a question about the split Command… How can I “come back” to “largefile”...
» complete change<p>Jesus asks: <strong>I have a question about the split Command… How can I “come back” to “largefile” from 126 small files?</strong>It sounds like the <a href="http://bashcurescancer.com/man/cmd/split">split</a> command was used? If so, then you can use a for loop with file concatenation. First, I will split the files for my example:</p>
<pre>
$ ls -l big.log
-rw-rw-r-- 1 brock brock 175743061 Oct 11 22:08 big.log
$ expr 175743061 \/ 126
1394786
$ split -b 1394786 big.log
$ ls -1 x*
xaa
xab
...
xew</pre>
<p>Split creates its output files in decreasing alphabetic order. Thus when you list them in the shell they are in the order in which<br />
they were split. As such, you can simply use cat to merge the files. (Thanks to Paul and Davidov for pointing out my for loop was superfluous.)</p>
<pre>
$ cat x* >merged.big.log
$ ls -l *.log
-rw-rw-r-- 1 brock brock 175743061 Oct 12 22:08 big.log
-rw-rw-r-- 1 brock brock 175743061 Oct 12 01:11 merged.big.log
$ diff merged.big.log big.log
$ md5sum *.log
47de08911534957c1768968743468307 big.log
47de08911534957c1768968743468307 merged.big.log</pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BashCuresCancer?a=mUsoydNI"><img src="http://feeds.feedburner.com/~f/BashCuresCancer?i=mUsoydNI" border="0"></img></a>
</div>
Shell Programming Beginners Class Lesson 2 - Variables
<p>This is the second installment of Shell Programming Beginners Class. <a href="http://bashcurescancer.com/shell_programming_beginners_class_lesson_1_motivation.html">The...
» complete change<p>This is the second installment of Shell Programming Beginners Class. <a href="http://bashcurescancer.com/shell_programming_beginners_class_lesson_1_motivation.html">The first installment was on motivation.</a></p>
<p>Variables are the heart of programming. They allow you to do something with a value which you do not know. In practical terms lets say we have a program or script which takes one integer value (Ex: 1, 2, 3, 4, …) and simply adds 1 to that value. You give it 5, it gives you 6. Not very useful. However, in that program you are going to have to call whatever number the user gives you something. When writing the program you obvivously do not know what value the user is going to enter. They may not even enter an integer. Lets assume they will indeed give you an integer, for now. Whatever you call the number which the user gives you is the name of the VARIABLE.</p>
<p>Lets say I call the user inputed value IN_INT, then my variable name would be IN_INT. In BASH when I wanted to use the value of that variable (Ex: 6 ) then I would prefix the variable name with a dollar sign, $.</p>
<p>Here is our sample program: (All your programs must start with #!/bin/bash and must be executable, chmod 744 filename.)<br />
<code><br />
# cat addOne.sh<br />
#!/bin/bash<br />
echo "Type an integer and press enter: "<br />
read IN_INT<br />
echo "You entered $IN_INT to the program."<br />
echo "Here is your output master: " `expr $IN_INT + 1`</code></p>
<p>I will run the script:<br />
<code><br />
# ./addOne.sh<br />
Type an integer and press enter: 6<br />
You entered 6 to the program.<br />
Here is your output master: 7</code></p>
<p>Following along? If not send me an email: <a href="http://spamdefeator.com"><img border="0" width="180" src="http://spamdefeator.com/u/5d0" alt="SpamDefeator" height="15" /></a>.</p>
<p>In BASH variables can be numbers or strings. Example:<br />
<code><br />
# STR1="this is a string."<br />
# echo $STR1<br />
this is a string. </code><code></code><code># STR2=THIS_IS_A_STRING_WITH_NO_SPACES<br />
# echo $STR2<br />
THIS_IS_A_STRING_WITH_NO_SPACES</code><code># INT1=21<br />
# echo $INT1<br />
21</p>
<p>You can also assign the output of a command to a variable with the ` or backtick character:<br />
<code><br />
# pwd<br />
/root<br />
# CWD=`pwd`<br />
# echo $CWD<br />
/root</code></p>
<p></code>You can perform mathematic operations on variables in a few different ways. The simplest is the expr command. expr allows you to add, substract, multiply, divide, find remainders, test values against other values, and a whole range of other things. I used expr above to add one to a number. Read the manual page of <a href="http://bashcurescancer.com/man/cmd/expr">expr</a> if would like to learn more.</p>
<p>If you would like to learn more please read the next article in this series <a href="http://bashcurescancer.com/shell_programming_beginners_class_lesson_3_essential_commands.html">Shell Programming Beginners Class Lesson 3 - Essential Commands</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BashCuresCancer?a=rdHElCrv"><img src="http://feeds.feedburner.com/~f/BashCuresCancer?i=rdHElCrv" border="0"></img></a>
</div>
OpenBSD 4 Installed in 20 Minutes
<p>After reading a post on <a target="_new" href="http://commandline.org.uk/2006/my-hairy-five-minutes-with-openbsd/">Command...
» complete change<p>After reading a post on <a target="_new" href="http://commandline.org.uk/2006/my-hairy-five-minutes-with-openbsd/">Command Line Warriors</a> I decided to try the OpenBSD 4.0 installation. My third attempt was successful. The first one I spent trying to figure out their fdisk utility and finally had to quit and give it a fresh go. The second worked fine but I needed another go in order to get clean screen shots as I made a few mistakes.</p>
<p><em>Note: Using the steps below will destroy any data on your disk. Use a spare.</em></p>
<p><em>Note: If you would like to read it or run into problems, here is the the <a href="http://bashcurescancer.com/media/openbsd-4.0-install/INSTALL.i386">official documentation for OpenBSD 4.0 on a i386</a>.</em></p>
<ol>
<li>Getting the installation ISO. Find an <a href="http://www.openbsd.org/ftp.html">OpenBSD mirror</a> to download the installation environment. The file is<br />
called cd40.iso.</li>
<li>It will start booting in a few seconds (or I believe you can press enter).<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/A-boot-install-cd.png" alt="Install cd boot prompt" height="356" title="Install cd boot prompt" class="screenshot" /></li>
<li>(I)nstall, (U)pgrade, or just get a (S)hell.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/B-install-uprgrade-shell.png" alt="(I)nstall, (U)pgrade, or just get a (S)hell" height="356" title="Choose I" class="screenshot" /></li>
<li>Terminal type. I used the default.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/C-terminal-type.png" alt="Terminal type, press enter" height="356" title="Terminal type, press enter" class="screenshot" /></li>
<li>Set keymap.<br />
<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/D-key-mapping.png" alt="Choose us for US keymapping" height="356" title="Choose us for US keymapping" class="screenshot" /></li>
<li>Are you sure? Yes.<br />
<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/E-are-you-sure.png" alt="Are you sure?" height="356" title="Are you sure?" class="screenshot" /></li>
<li>Which disk? I only had one so I pressed enter. Do you want to use the entire disk? Yes. This creates a whole disk<br />
OpenBSD “slice” which you will make into partitions in the next step.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/F-choose-disk-confirm.png" alt="Which disk? Use default" height="356" title="Which disk? Use default" class="screenshot" /></li>
<li>This is the tricky part. It puts you into an odd fdisk (for non BSD users). <strong>The options are NOT the same as Linux or Windows fdisk</strong>. The p command prints the current drive configuration. Basically you DO NOT want to delete the c partition. Its the whole disk slice which was created in the step above.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/G-print-disk.png" alt="Press p to print the configuration" height="356" title="Press p to print the configuration" class="screenshot" /></li>
<li>Delete everything but the c partition with the d command.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/H-delete-partition.png" height="356" class="screenshot" /></li>
<li>Create a new partition with the a command. It will then ask you for the name, offset, size, type, and mount point. Leave the name and offset as the default. You need to leave some space for swap so I used 3GB of my 4GB disk. You can use M to specify Megabytes. Thus 3GB is 3000M. It then conveniently assumes you want the BSD filesystem type. Choose / as your mount point. Now we have to create the swap partition. Its more of the same. Just press a and use the defaults. I am running this through VMWare so I chose a large swap partition.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/I-creating-root-swap-part.png" alt="Creating the root and swap partitions" height="356" title="Creating the root and swap partitions" class="screenshot" /></li>
<li>Once the disks are setup press q to quit and then confirm.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/J-writing-new-disk.png" alt="Press q to quit and then confirm" height="356" title="Press q to quit and then confirm" class="screenshot" /></li>
<li>The next screen is the network options. I chose thirdtry as my hostname and dhcp as my method of obtaining my ipaddress otherwise I just used the defaults.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/K-setup-ipv4.png" alt="Network options, I chose dhcp" height="356" title="Choose dhcp" class="screenshot" /></li>
<li>Enter the root password and confirm<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/L-root-password.png" alt="Choose a root password" height="356" title="Choose a root password" class="screenshot" /></li>
<li>If your following these instructions choose http as the location of the sets and then type yes to display the list of known http servers:<br />
<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/M-install-method.png" alt="Choose http and yes to display a list of servers" height="356" title="Choose http" class="screenshot" /></li>
<li>Your in <a href="http://bashcurescancer.com/man/cmd/more">more</a> so press the space bar to see the next page. The US servers are at the bottom.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/N-select-http-server-p1.png" alt="Find a mirror near you" height="356" title="Pick a mirror near you" class="screenshot" /></li>
<li>Choose a mirror near your location and accept the default server directory.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/O-select-http-server-p2.png" alt="Choose a mirror and accept the default server directory" height="356" title="Choose a mirror" class="screenshot" /></li>
<li>Are you ready? Yes.<br />
<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/P-intall-sets.png" alt="Are you ready to install OpenBSD 4.0?" height="356" title="Are you ready?" class="screenshot" /></li>
<li><strong>Installing!<br />
</strong><img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/Q-installing.png" alt="OpenBSD is installing" height="356" title="Instaling...." class="screenshot" /></li>
<li>Once the download is complete it will ask you again for the location of the sets. <strong>This is for extra packages such as X</strong>. I chose the default of done and did not install any extra packages.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/R-location-of-sets.png" alt="Location of sets again, this is for extra packages. Press enter" height="356" title="Press enter" class="screenshot" /></li>
<li>Choose the the defaults except for timezone.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/S-misc-settings.png" alt="Choose the the defaults except for timezone" height="356" title="Choose the the defaults" class="screenshot" /></li>
<li>Can it really be installed?<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/T-installed-question-mark.png" alt="Is it really installed" height="356" title="Really?" class="screenshot" /></li>
<li>Type halt and then reboot.<img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/U-reboot.png" alt="Type halt and then reboot" height="356" title="Reboot" class="screenshot" /></li>
<li><strong>Congratulations you have just installed OpenBSD!</strong><img width="640" src="http://bashcurescancer.com/media/openbsd-4.0-install/V-booted.png" alt="Congratulations OpenBSD has been installed" height="356" title="Congratulations" class="screenshot" /></li>
</ol>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BashCuresCancer?a=9l83hNQU"><img src="http://feeds.feedburner.com/~f/BashCuresCancer?i=9l83hNQU" border="0"></img></a>
</div>
Shell Programming Beginners Class Lesson 3 - Essential Commands
<p>Knowing commands is essential to using the command line. It is even more so when programming the command line.<br />
However,...
» complete change<p>Knowing commands is essential to using the command line. It is even more so when programming the command line.<br />
However, you don’t have to know them yet! I can teach you the basics and then you can learn as you go. The most important thing you can possibly get from this article is the next sentence. UNIX/Linux systems have the ENTIRE user manual in neat organized sections relating to the specific command you want to know about. Its called the man pages or manual pages. Just type “man” and then any command. Example “man find”.</p>
<p><em>This is the third installment of Shell Programming Beginners Class. If your reading this article first and would prefer to start from the beginning you can do so here: <a href="http://bashcurescancer.com/shell_programming_beginners_class_lesson_1_motivation.html">motivation</a> or if you would simply like to read the previous article, it is available here: <a href="http://bashcurescancer.com/shell_programming_beginners_class_lesson_2_variables.html">variables</a>.</em></p>
<p>Commands in UNIX/Linux, Windows, and Mac OS all follow the same format. That is “command [options] [arguments]”. Technically options are arguments but who cares. Example “find /home/brock -name ‘ECON1001*’” or “rmdir test_directory”.</p>
<p>Enough already, here is the list in no particular order:</p>
<ol>
<li>cd: change to a different directory</li>
<li><a href="http://bashcurescancer.com/man/cmd/cp">cp</a>: copy files and directories</li>
<li><a href="http://bashcurescancer.com/man/cmd/more">more</a>: used for viewing a file one page a time</li>
<li><a href="http://bashcurescancer.com/man/cmd/less">less</a>: less is more (less is better than ^more^)</li>
<li><a href="http://bashcurescancer.com/man/cmd/mv">mv</a>: mv or <strong>rename</strong> files and directories</li>
<li><a href="http://bashcurescancer.com/man/cmd/vi">vi</a>: a text editor</li>
<li><a href="http://bashcurescancer.com/man/cmd/rmdir">rmdir</a>: remove empty directories</li>
<li><a href="http://bashcurescancer.com/man/cmd/rm">rm</a>: remove files and directories</li>
</ol>
<p>Most of the commands should be self explanatory. cd changes from one directory to another, cp copies things, rm removes<br />
things, and rmdir removes empty directories. Your probably not sure why we have rm and rmdir or possibly what less, more, and vi are.</p>
<p>rmdir exists basically as the “correct” or “safe” way to deal with deleting files and directories. The command line does not have a trash bin. When its gone its gone. Thus typically rm has the -i option enabled by default which asks your to confirm EVERY SINGLE TIME you want to delete a file. Then your supposed to remove all the files in a directory and then and only then delete it with rmdir. So what does everyone do when they want to delete something? “rm -rf”.</p>
<p>rm -rf is joking called the nuclear option in some very dorky circles. It deletes recursive and does not prompt. Running “rm -rf /” will bring your system down and delete everything on your hard disk.</p>
<p>When using the command line you typically have a small window where you type in your commands. As you type in commands<br />
the output scrolls to the top of the window and then eventually disappears after you have scrolled all the way up. Thus<br />
the need for more and less. They allow you to view a file one page a time. Less is more, than more.</p>
<p>vi is the windows notepad of UNIX/Linux although its very hard to learn for new people. If you have the command “nano”<br />
or “pico” available (just type it in) and are getting distressed with vi, give them a try. I’d rather have you never learn<br />
vi than to never learn the command line because of vi.</p>
<p>If you have no idea what I am talking about, here is a few sample commands being executed. When the user types “vi file”<br />
they would see a screen which you will not see below. But after closing vi they would return to seeing what we see below. The user copies a file, edits the new file, and then removes the old one. Looks like some cheating is going on.</p>
<pre>
# cp econ1101-brad.doc econ1101-jessica.doc
# vi econ1101-jessica.doc
# rm econ1101-brad.doc</pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BashCuresCancer?a=wUkKA5K6"><img src="http://feeds.feedburner.com/~f/BashCuresCancer?i=wUkKA5K6" border="0"></img></a>
</div>
10 Linux commands you’ve never used
<p>It takes years maybe decades to master the commands available to you at the Linux shell prompt. Here are 10 that<br />...
» complete change<p>It takes years maybe decades to master the commands available to you at the Linux shell prompt. Here are 10 that<br />
you will have never heard of or used. They are in no particular order. My favorite is mkfifo.</p>
<ol>
<li><a href="http://bashcurescancer.com/man/cmd/pgrep">pgrep</a>, instead of:<br />
<code><br />
# ps -ef | egrep '^root ' | awk '{print $2}'<br />
1<br />
2<br />
3<br />
4<br />
5<br />
20<br />
21<br />
38<br />
39<br />
...<br />
</code>You can do this:<code><br />
# pgrep -u root<br />
1<br />
2<br />
3<br />
4<br />
5<br />
20<br />
21<br />
38<br />
39<br />
...<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/pstree">pstree</a>, list the processes in a tree format. This can be VERY useful when working with WebSphere or other heavy duty applications.<br />
<code><br />
# pstree<br />
init-+-acpid<br />
|-atd<br />
|-crond<br />
|-cups-config-dae<br />
|-cupsd<br />
|-dbus-daemon-1<br />
|-dhclient<br />
|-events/0-+-aio/0<br />
| |-kacpid<br />
| |-kauditd<br />
| |-kblockd/0<br />
| |-khelper<br />
| |-kmirrord<br />
| `-2*[pdflush]<br />
|-gpm<br />
|-hald<br />
|-khubd<br />
|-2*[kjournald]<br />
|-klogd<br />
|-kseriod<br />
|-ksoftirqd/0<br />
|-kswapd0<br />
|-login---bash<br />
|-5*[mingetty]<br />
|-portmap<br />
|-rpc.idmapd<br />
|-rpc.statd<br />
|-2*[sendmail]<br />
|-smartd<br />
|-sshd---sshd---bash---pstree<br />
|-syslogd<br />
|-udevd<br />
|-vsftpd<br />
|-xfs<br />
`-xinetd<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/bc">bc</a> is an arbitrary precision calculator language. Which is great. I found it useful in that it can perform square root operations in shell scripts. <a href="http://bashcurescancer.com/man/cmd/expr">expr</a> does not support square roots.<br />
<code><br />
# ./sqrt<br />
Usage: sqrt number<br />
# ./sqrt 64<br />
8<br />
# ./sqrt 132112<br />
363<br />
# ./sqrt 1321121321<br />
36347<br />
</code>Here is the script:<code><br />
# cat sqrt<br />
#!/bin/bash<br />
if [ $# -ne 1 ]<br />
then<br />
echo 'Usage: sqrt number'<br />
exit 1<br />
else<br />
echo -e "sqrt($1)\nquit\n" | bc -q -i<br />
fi<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/split">split</a>, have a large file that you need to split into smaller chucks? A mysqldump maybe? split is your command. Below I split a 250MB file into 2 megabyte chunks all starting with the prefix LF_.<br />
<code><br />
# ls -lh largefile<br />
-rw-r--r-- 1 root root 251M Feb 19 10:27 largefile<br />
# split -b 2m largefile LF_<br />
# ls -lh LF_* | head -n 5<br />
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_aa<br />
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_ab<br />
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_ac<br />
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_ad<br />
-rw-r--r-- 1 root root 2.0M Feb 19 10:29 LF_ae<br />
# ls -lh LF_* | wc -l<br />
126<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/nl">nl</a> numbers lines. I had a script doing this for me for years until I found out about nl.<br />
<code><br />
# head wireless.h<br />
/*<br />
* This file define a set of standard wireless extensions<br />
*<br />
* Version : 20 17.2.06<br />
*<br />
* Authors : Jean Tourrilhes - HPL<br />
* Copyright (c) 1997-2006 Jean Tourrilhes, All Rights Reserved.<br />
*/#ifndef _LINUX_WIRELESS_H<br />
# nl wireless.h | head<br />
1 /*<br />
2 * This file define a set of standard wireless extensions<br />
3 *<br />
4 * Version : 20 17.2.06<br />
5 *<br />
6 * Authors : Jean Tourrilhes - HPL<br />
7 * Copyright (c) 1997-2006 Jean Tourrilhes, All Rights Reserved.<br />
8 */9 #ifndef _LINUX_WIRELESS_H</p>
<p></code></li>
<li><a href="http://bashcurescancer.com/man/cmd/mkfifo">mkfifo</a> is the coolest one. Sure you know how to create a pipeline piping the output of grep to less or maybe even perl. But do you know how to make two commands communicate through a named pipe?First let me create the pipe and start writing to it:
<p><img width="640" src="http://bashcurescancer.com/media/10-linux-commands-youve-never-used/mkfifo-write-to-pipe.png" alt="mkfifo pipe; tail file > pipe" height="357" title="Making the pipe and writing to it" class="screenshot" /></p>
<p>Then read from it:</p>
<p><img width="642" src="http://bashcurescancer.com/media/10-linux-commands-youve-never-used/read-from-pipe.png" alt="cat pipe" height="360" title="Reading from the pipe" class="screenshot" /></li>
<li><a href="http://bashcurescancer.com/man/cmd/ldd">ldd</a>, want to know which Linux thread library java is linked to?<br />
<code><br />
# ldd /usr/java/jre1.5.0_11/bin/java<br />
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x00bd4000)<br />
libdl.so.2 => /lib/libdl.so.2 (0x00b87000)<br />
libc.so.6 => /lib/tls/libc.so.6 (0x00a5a000)<br />
/lib/ld-linux.so.2 (0x00a3c000)<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/col">col</a>, want to save man pages as plain text?<br />
<code><br />
# PAGER=cat<br />
# man less | col -b > less.txt<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/xmlwf">xmlwf</a>, need to know if a XML document is well formed? (A configuration file maybe..)<br />
<code><br />
# curl -s 'http://bashcurescancer.com' > bcc.html<br />
# xmlwf bcc.html<br />
# perl -i -pe 's@<br/>@<br>@g' bcc.html<br />
# xmlwf bcc.html<br />
bcc.html:104:2: mismatched tag<br />
</code></li>
<li><a href="http://bashcurescancer.com/man/cmd/lsof">lsof</a> lists open files. You can do all kinds of cool things with this. Like find which ports are open:<br />
<code><br />
# lsof | grep TCP<br />
portmap 2587 rpc 4u IPv4 5544 TCP *:sunrpc (LISTEN)<br />
rpc.statd 2606 root 6u IPv4 5585 TCP *:668 (LISTEN)<br />
sshd 2788 root 3u IPv6 5991 TCP *:ssh (LISTEN)<br />
sendmail 2843 root 4u IPv4 6160 TCP badhd:smtp (LISTEN)<br />
vsftpd 9337 root 3u IPv4 34949 TCP *:ftp (LISTEN)<br />
cupsd 16459 root 0u IPv4 41061 TCP badhd:ipp (LISTEN)<br />
sshd 16892 root 3u IPv6 61003 TCP badhd.mshome.net:ssh->kontiki.mshome.net:4661 (ESTABLISHED)<br />
</code>Note: <a href="http://www.openbsd101.com/">OpenBSD 101</a> pointed out that “lsof -i TCP” a better way to obtain this same information. Thanks!Or find the number of open files a user has. Very important for running big applications like Oracle, DB2, or WebSphere:</p>
<p><code><br />
# lsof | grep ' root ' | awk '{print $NF}' | sort | uniq | wc -l<br />
179<br />
</code></p>
<p>Note: an anonymous commenter pointed out that you can replace sort | uniq with “sort -u”. This is true, I forgot about the -u flag. Thanks!</li>
</ol>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BashCuresCancer?a=4dDEJWTZ"><img src="http://feeds.feedburner.com/~f/BashCuresCancer?i=4dDEJWTZ" border="0"></img></a>
</div>
