What's New!

Chat with

How to Defend
Your Computer 

The Guides
to (mostly) 
Harmless Hacking

Happy Hacker 
Digests (old stuff) 

Hacker Links 


Meet the 
Happy Hacksters 

Help for 



It Sucks 
to Be Me!

How to Commit
Computer Crime (not)! 

What Is a 
Hacker, Anyhow? 

Have a 
Great Life! 

News from the 
Hacker War Front

Shell Programming,continued...

Shell Scripts on the Fly

 In a rush? Do you always do things perfectly? If so, try the "cat" command to create shell scripts.

 Here's an example of a useful one. Type in:

cat > list
ls -alF|more

 Then hold down the control key while hitting the letter "d." This will automatically end the "cat" command while saving the commands "ls -alF|more" and "w|more" in the file "list." Then make it executable with the command: "chmod 700 list." (If chmod 700 doesn't work on your system, try the alternative ways to make it executable in 4) above.)

 Now, whenever you want to see everything you could ever want to see about your files, followed by a list of info on whoever else is also logged into shell accounts at the Unix box you use, just type in the command "list."
This will give you something like:

total 127
drwx-----x  8 cpm          1536 Dec 28 14:37 .
drwxr-xr-x985 root        17920 Dec 26 17:56 ..
-rw-------  1 cpm             0 Aug 27 08:07 .addressbook
-rw-------  1 cpm          2285 Aug 27 08:07 .addressbook.lu
lrwxrwxrwx  1 cpm             9 Oct 27 15:35 .bash_history -> /dev/null
-rw-r--r--  1 cpm          1856 Oct  8 09:47 .cshrc


3:01pm  up 5 days,  6:48,  9 users,  load average: 1.87, 1.30, 1.08
User     tty       login@  idle   JCPU   PCPU  what
phill    ttyp0     2:39pm     1     11         -csh
flattman ttyp1     2:27pm            4      4  tf
kjherman ttyp2     1:13pm  1:43                telnet ftp.fubar.com
cpm      ttyp4     1:08pm           13         w
johnp    ttyp5    Sat 6pm     1   1:29      7  -tcsh
kjherman ttyp6     1:15pm  1:43                telnet fubar.com
kjherman ttyp8     1:16pm  1:43                /bin/csh /usr/local/bin/cmenu
momshop  ttyp9     2:50pm    10                /usr/local/bin/pine
swit     ttypa     9:56am  4:20     41         -csh
joy      ttypc     3:00pm            2      1  -csh

Newbie note: What does all that stuff mean? Sorry, this is an advanced GTMHH, so all I'm going to tell you is to give the commands "man ls" and "man who" to find out all this stuff.
OK, OK, I'm sorry, here's a little more help. The "|" means "pipe." When you have two commands on either side of a pipe command, this makes the output of the command on the left hand side of the "|" pipe into the command on the right hand side. So "w|more" tells your computer to do the command "w" and pipe its output to the command "more." Then "more" displays the output on your monitor one screen at a time, waiting for you to hit the space bar before displaying the next screen.
What does "lrwxrwxrwx  1 cpm             9 Oct 27 15:35 .bash_history ->
/dev/null" mean? "l" means it is a linked file. The first set of rwx's mean I (the owner of the account) may read, write, and execute this file. The second rwx means my group may also read, write and execute. The last set means anyone in the world may read, write and execute this file. But since it's empty, and will always stay empty, too bad, kode kiddies.

Evil genius tip: In case you saw that supposed bash history file of mine some haxors were making phun of on some email lists, here's two ways you can tell it was faked and they were seriously deficient in Unix knowledge.
a) See that funny notation above, "bash_history -> dev/null? My
.bash_history has been linked to dev/null (dev/null means "device null" which is a fancy way of saying everything goes to bit heaven never to be seen again) since Oct. 9, 1997 -- long before some sooper genius emailed around that fake file!
 Here's how you can make your bash history disappear. Simply give the command "ln -s /dev/null ~/.bash_history."
b) If you have the bash shell, and haven't linked it yet to dev/null, get into it and use the "talk" command to chat with someone for awhile. Then give the command "more .bash_history." You will see that unlike that supposed bash history file of mine, the stuff you type in during a "talk" session does not appear in the .bash_history file. The guy who faked it didn't know this! Either that, or he did know, and put that in to trick the people who would read it and flame me into revealing their ignorance. The guys who got caught by this trick tried to get out of their embarrassing spot by claiming that a buffer overflow could make the contents of a talk session turn up in a bash history file. Yeah, and yesterday they saw Elvis Presley at a grocery story, too.

 How about more fun ways to make shell scripts?

More shell programming --->>

Carolyn's most
popular book,
in 4th edition now!
For advanced
hacker studies,
read Carolyn's
Google Groups
Subscribe to Happy Hacker
Visit this group


Return to the index of Guides to (mostly) Harmless Hacking!

 © 2013 Happy Hacker All rights reserved.