Search This Blog

Thursday, November 29, 2007

Eclipse +Serial communication ( adding terminal)

Downloading (597 KB)

Installation for Windows

RXTX installation procedure if you want to run RXTX enabled programs ==

If you just want to run RXTX enabled programs, follow this procedure.

Identify your Java Runtime Environment's folder. For version 1.6.0, this usually is

c:\Program Files\Java\jre1.6.0_01\

  • Copy rxtxParallel.dll to c:\Program Files\Java\jre1.6.0_01\bin\
  • Copy rxtxSerial.dll to c:\Program Files\Java\jre1.6.0_01\bin\
  • Copy RXTXcomm.jar to c:\Program Files\Java\jre1.6.0_01\lib\ext\

RXTX installation procedure if you want to develop or compile RXTX enabled programs

If you want to develop and compile RXTX enabled programs, for example with the NetBeans IDE, follow this procedure.

Identify your Java Development Kit's folder. For version 1.6.0, this usually is

c:\Program Files\Java\jdk1.6.0_01\

  • Copy rxtxParallel.dll to c:\Program Files\Java\jdk1.6.0_01\jre\bin\
  • Copy rxtxSerial.dll to c:\Program Files\Java\jdk1.6.0_01\jre\bin\
  • Copy RXTXcomm.jar to c:\Program Files\Java\jdk1.6.0_01\jre\lib\ext\

Note that there is an additional \jre\ subfolder in this path!

Powered by ScribeFire.

Wednesday, November 28, 2007

OpenOCD Quick Reference Card

OpenOCD Quick Reference Card

OpenOCD Homepage:

Current OpenOCD revision: 128


Configuration Commands

telnet port Listen for telnet connections on port.

gdb port Listen for GDB connections on port, port+1, . . .(target 1, target 2, . . . )

User Commands

shutdown Shut server down.

exit Exit telnet. Leaves server running.

help Print available commands.


The interpreter commands may be used to define variables used within other subsystems like JTAG.

var [’del’|([size1] [sizeN])] Allocate, display or delete

variable. Allocation has to define the size for all num fields elements.

field [value| ’flip’ ] Display or modify variable field.

script Execute commands from file.


Configuration Commands

target Target type is arm7tdmi, arm9tdmi, arm720t, arm920t, arm926ejs,arm966e; endianness is either big or little; reset mode is one of reset halt, reset run,reset init, run and halt, run and init. Do not use reset halt orreset init on LPC2 or STR7.

target arm7tdmi [variant] variant is one ofarm7tdmi r4, arm7tdmi-s r4,

target arm9tdmi [variant] variant is one of arm920t, arm922t and

daemon startup <’reset’|’attach’> Describes what to do with target on
daemon startup.

target script event is either post halt or pre resume.

run and halt time Delay in msec between reset and debug request.

working area [backup|nobackup]

User Commands

targets [num] Display list of configured targets,or make target num the current target.reg [#|name] [value|’force’] Display or modify registers.

poll [’on’|’off’] Print information about the current target state. If the target is in debug mode, architecture specific information
about the current state are printed. Enable or disable continuous polling with optional parameter.
wait halt Wait for target halt halt Halt target


Resume the target at
the current position or at


Single-step at the
current position or at

reset [’run’|’halt’|’init’|’run and
halt’| ’run and init’]
the target in a few variations.
soft reset halt Halt
the target and do a soft reset.

md[whb] [count]
Display count words (32 bit),
half-words (16 bit) or bytes at address.
If count is omitted, one element is

mw[whb] Write
value at theword, half-word or byte
location address.

bp [hw] Set
a breakpoint of length bytes at address.

rbp Remove breakpoint at address.

Set a watchpoint of length bytes
at address.

rwp Remove a watchpoint at address.

load binary
Load binary file into target
memory (RAM) at address.

dump binary Dump target memory of size bytes at address

ARM v4/5

armv4 5 reg Display all banked ARM core

armv4 5 core mode [’arm’|’thumb’] Display thecurrent core state, or
switch between Arm and Thumb state.

armv4 5 disassemble [’thumb’] Disassemble instructions


The commands are cp15, virt2phys, mdw phys, mdh phys, mdb
, mww phys, mwh phys, mwb

See ARM7/9 for a short description.

ARM 7/9

arm7 9 write xpsr Write the program status register.
spsr selects between the current program status register (0) and the saved
program status register (1) of the current mode.

arm7 9 write xpsr im8 <8bit> Same as write xpsr, but use the
immediate operand opcode.

arm7 9 write core reg Write core register num of mode with value.

arm7 9 sw bkpts Enable or disable the use of
software breakpoints.

arm7 9 force hw bkpts Force the use of hardware breakpoints.

arm7 9 dbgrq Use EmbeddedICE dbgrq instead of
breakpoint for target halt requests (safe for all except ARM7TDMI

arm7 9 fast memory access Use fast but potentially unsafe memory accesses
instead of slow accesses. Assumes a sufficiently high clock speed.

arm7 9 dcc downloads use DCC downloads for larger memory writes.


arm920t cp15 [value] Display/modify CP15 register

arm920t cp15i
[value] [address]
cp15 (interpreted access)
arm920t cache info Display information about target caches.

arm920t virt2phys Translate
virtual to physical address.

arm920t md[whb]
phys [count]
memory word, half word, byte

arm920t mw[whb]
write memory word,
half word, byte

arm920t read cache display I/D
cache content

arm920t read mmu display I/D
mmu content


arm926ejs ... XXX To Do ARM966E

arm966e cp15 [value] Display/modify

CP15 register


Configuration Commands

interface name is one of parport,amt jtagaccel, ft2232, ep93xx


Describes the devices that form the JTAG daisy chain, with the first device
being the one closest to TDO.

jtag nsrst delay ms milliseconds delay between going nSRST inactive and
following JTAG operations.

jtag ntrst delay ms milliseconds delay between going nTRST inactive and
following JTAG operations.

reset config
[combination] [trst-type] [srst-type]
is one of none, trst
only, srst only or trst and srst.
Combination is one of srst pulls trst, trst pulls srst, combined,
trst-type is one oftrst open drain, trst push
srst-type is one of srst push pull, srst open
User &
Config Commands

jtag speed Select JTAG Speed ft2232: 6 MHz / (value+1) parport:
maximum speed /value
: 8 / 2**value

Note: Max. JTAG-Clock _ 1

6 × CPU-Clock!


parport port – Either I/O port address

(e.g. 0x378) or the number of the

/dev/parport device.

parport cable name is one of wiggler, old amt wiggler, chameleon, dlc5 (Xilinx
cable III), triton.

Amt jtagaccel

parport port see previous description.


ft2232 device desc USB device description. Use usbview or similar tool to get this string.

ft2232 layout Layout name is one of jtagkey, usbjtag, signalyzer, olimex-jtag, m5960, evb

ft2232 vid pid Vendor-ID vid and product-ID pid of
the FTDI device.

User Commands

scan chain
Print scan chain

endstate Finish JTAG operations in tap state.

jtag reset
Toggle reset lines.

runtest Move to Run-Test/Idle and execute num cycles. statemove Move to current endstate or tap state.

[devN] [instrN]
IR scan.

drscan [devN] [varN] Execute DR scan.


flash banks
Display list of
configured flash banks

flash info
Display information and
list of

blocks of
flash bank

flash probe
Probe flash bank num if it

matches the
configured bank.

flash erase check Check erase
state of flash sectors in bank

flash protect check Check protect
state of flash sectors in bank

flash erase Erase sectors at bank num, starting at sector first up to

and including last. Sector numbering starts at 0.

flash write Write binfile (in binary
format!) to bank num at offset bytes
from start of bank.

flash protect <’on’|’off’>

Enable (on) or disable (off)
protection of flash

sectors first to last of flash bank num.

flash bank [driver options...] Configure a flash bank at address base of size bytes with
a bus of
bus width bits formed by chips of chip width bits size using driver lpc2000, cfi, at91sam7, str7x,

flash bank lpc2000 0 0[’calc
The internal
flash of LPC2000 devices doesn’t require

chip- and buswidth to be defined.

lpc variant specifies the supported IAP commands

of the device (lpc2000 v1:2104—5—6, 2114—9,

2124—9, 2194, 2212—4, 2292—4; lpc2000 v2:

213x, 214x, 2101—2—3). The flash
bank is part

of target# which runs at cclk kHz.
Calc checksum

inserts a valid checksum into the
exception vector

when this area is flashed.

For LPC2138 and LPC2148 devices, the
size argument

has to reflect the user-accessible
size, i.e.

0x7d000 (500kB), not 0x80000

flash bank at91sam7 0 0 0 0

flash bank str7x 0 0

variant is one of STR71x,

STR73x or STR75x.

flash bank str9x 0 0 0

The str9 needs the flash controller
to be configured

prior to Flash programming:

str9x flash config b0size b1size


Example: str9x flash config 4 2 0 0x80000

This will setup the BBSR, NBBSR,

NBBADR registers respectively.

flash bank cfi

at91sam7 gpnvm set|clear set or

clear at91sam7 gpnvm bit

lpc2000 part id print part id of lpc2000

flash bank num


xsvf Program Xilinx Coolrunner




Commandline Options

$ openocd --help

Open On-Chip Debugger

(c) 2005 by Dominic Rath

--help | -h display this help

--file | -f use configuration file

--debug | -d set debug level

--log_output | -l redirect log
output to file

--interface | -i use jtag interface

Sample Configuration

[see $(SRCDIR)/doc/configs/*.cfg]

Some GDB commands

(gdb) target remote localhost:3333

(gdb) monitor arm7 9 force hw bkpts

force hardware breakpoints

More information

- Get current version with

svn co

- OpenOCD Forum at Spark Fun


- OpenFacts


- Mailing List “openocd-development”


- Yagarto ARM toolchain (Windows)

- Amontec JTAGkey[-Tiny], sdk4arm


QuickRef written by

Date: 2007-02-03

Download this QuickRef from

Winxp key extractor from CD without installing

you can check out the links on the page although. I haven't found the solution yet. please reply if you know..

there are plenty of crap on the net which just doesn't work . or assumes the system is installed and you want to extract the key from the registry.

Powered by ScribeFire.

WinXP CDKey Extractor

Magical Jelly Bean Keyfinder

This is a small free ware utility that retrieves your Product Key (cd key) used to install windows from your registry. It has the options to copy the key to clipboard, save it to a text file, or print it for safekeeping. It works on Windows 95, 98, ME, NT4, 2000, XP, Server 2003, Office 97, and Office XP.

This version (v1.41) is a quick update to make it work with Windows Server 2003.

You can download it from THERE (251kb) or visit the author's website for more download links:

Note: This tool does not seem to be able retrieve the Office 2003 CD Key. However, a new version of this tool - v1.5B3 - does have the capability of seeing the Office 2003 CD Key, and also enables you to directly change the existing CD Key to another one.

You can download v1.5B3 from THERE or from HERE (254kb)

Note that this tool is NOT a cracking tool, and it does NOT generate a serial for you. All it does is to extract your existing CD Key.

CD Key Reader

CD Key Reader is another small tool that can find and display registration information for Microsoft tools and software that is installed on your computer (i.e. Windows, Office and so on).

You can download it from the author's website (43kb):

BTW, there are quite a few other tools that do the same trick. If you know of a good one please add a coment to to the post.

Ref :

; -----
; Windows XP CD-KEY Extractor (ASM) by Napalm
; Original C++ Version by Smith
; -----
; Please remember this would look simpler without the comments

[BITS 32]
%include ""

; Imports
iextern lstrlen, 4
iextern GetStdHandle, 4
iextern WriteFile, 20
iextern RegOpenKeyExA, 20
iextern RegQueryValueExA, 24
iextern RegCloseKey, 4
iextern Sleep, 4
iextern GetAsyncKeyState, 4
iextern ExitProcess, 4

; Constants
%define REG_BINARY 3
%define KEY_READ 0x20019
%define VK_ESCAPE 27
%define FALSE 0
%define TRUE 1
%define HKEY_LOCAL_MACHINE 0x80000002
%define MAX_DATASIZE 164

section .data
szTitle db "Windows XP CD-KEY Extractor (ASM) by Napalm",10,"Original C++ Version by Smith",10,10,0
szError db "Unable to retrieve cd key!",10, 0
szQuit db "Press escape to quit...",0
szKeyChars db "BCDFGHJKMPQRTVWXY2346789",0
szRegKey db "SOFTWARE\MICROSOFT\Windows NT\CurrentVersion",0
szRegValue db "DigitalProductId",0

section .bss
lpRawData resb MAX_DATASIZE
szFinalKey resb 32

section .text
global _start
icall OutputString, szTitle
icall GetWindowsCDKey, szFinalKey, TRUE
test eax, eax
jz .ShowError
icall OutputString, szFinalKey
jmp .ShowQuit
icall OutputString, szError
icall OutputString, szQuit
icall Sleep, 10
icall GetAsyncKeyState, VK_ESCAPE
test eax, eax
jz .WaitForKey
icall ExitProcess, 0

lpszBuffer equ 8
bUseFormat equ 12
enter 0, 12
hKey equ 4
bStatus equ 8
dwDataLen equ 12

; Set Return Error State
mov dword [ebp-bStatus], FALSE

; Open Registry Key
lea ebx, [ebp-hKey]
test eax, eax
jnz .ErrorRet

; Get Registry Value
lea ebx, [ebp-dwDataLen]
mov dword [ebx], MAX_DATASIZE
xor ecx, ecx
icall RegQueryValueExA, dword [ebp-hKey], szRegValue, ecx, ecx, lpRawData, ebx
test eax, eax
jnz .ErrorRet

; Close Registry Key
icall RegCloseKey, dword [ebp-hKey]

; Get Encrypted Key
mov edi, lpRawData
mov esi, edi
add esi, 52
mov ecx, 15
rep movsb

; Decrypt Key
mov ecx, 24; Set Loop1 counter "i"
mov edi, dword [ebp+lpszBuffer]; Note: The key is decrypted backwards;)
add edi, ecx ; EDI now points to the End of the resulting key
xor edx, edx ; Zero EDX
cmp edx, dword [ebp+bUseFormat]
jz .StartDecrypt; Jump if bUseFormat is 0(FALSE)
add edi, 4 ; Add 4 so there is room for the dashes
inc edi
mov byte [edi], 10; Add line return to end of key
dec edi
push ecx ; Preseve ECX for Loop1 (Loop counter)
mov ecx, 14 ; Set Loop2 counter "c"
mov esi, lpRawData; Set source pointer to lpRawData
;nCur = 0
mov ebx, 0; EBX is "nCur" in original C++ file
; nCur = nCur * 256
shl ebx, 8
; nCur ^= lpRawData[c]
xor edx, edx; Clear edx since we only set DL in next line
mov dl, byte [esi+ecx]; Set DL to source input char
xor ebx, edx
; lpRawData[c] = nCur / 24;
xor edx, edx; Division in ASM in simple yet looks complicated
mov eax, ebx; Pseudo: EAX:EDX DIV SRC = EAX:EDX (EAX=Quotient, EDX=Remainder)
mov ebx, 24
div ebx; So this is: EAX / 24
mov byte [esi+ecx], al; Put Quotient back into lpRawData
; nCur %= 24
mov ebx, edx; Put Remainder into EBX "nCur"
dec ecx
cmp ecx, -1
jne .DecryptLoop2; Continue loop while ECX greater than -1
pop ecx ; Restore Loop1 counter
; *lpszResult-- = "BCDFGHJKMPQRTVWXY2346789"[nCur];
mov esi, szKeyChars; Set source pointer to KeyChars
mov al, byte [esi+ebx]; Get key char for EBX "nCur"
mov byte [edi], al; Set resulting char in final key string
dec edi ; Remove 1 from the pointer
; Next we split the following C++ line up
; if(((i % 5) == 0) && (i > 0) && bUseFormat) *lpszResult-- = '-';
xor edx, edx
; && bUseFormat
cmp edx, dword [ebp+bUseFormat]
jz .NoDashes; Jump if bUseFormat is 0(FALSE)
; && (i > 0)
cmp ecx, edx
jz .NoDashes; Jump if ECX "i" is Zero
; ((i % 5) == 0)
mov eax, ecx; Set EAX to ECX
mov ebx, 5
div ebx ; We divide EAX "i" by EBX "5"
xor eax, eax; Set EAX to Zero
cmp edx, eax
jnz .NoDashes; Jump if EDX(Quotient) is Zero
; *lpszResult-- = '-';
mov byte [edi], '-'
dec edi
dec ecx
cmp ecx, -1
jne .DecryptLoop1
; bStatus = TRUE;
mov dword [ebp-bStatus], TRUE

mov eax, [ebp-bStatus]
ret 8

lpszString equ 8
enter 0, 0
icall lstrlen, dword [ebp+lpszString]
push eax
icall GetStdHandle, STD_OUTPUT_HANDLE
pop ebx
xor ecx, ecx
icall WriteFile, eax, dword [ebp+lpszString], ebx, ecx, ecx
ret 4
Ref :

Tuesday, November 27, 2007

UML tools a review : Best UML tool for personal or comercial use. (Free)

Recently i was looking for a UML tool. for personal use, I evaluated some tool's like argo UML ,Poseidon for UML, UML Studio 8 , UMLet (also avilable as eclipse plugin) and so on. i was totally frustrated to see that non of this work properly. one or more issues came up with all of them.

argo uml:

  1. Problems with sequence diagrams
  2. once you start a sequence diagram then you can not add in between two events ( which you usually require for expansion)
  3. copy and paste is not supported ( you can only copy a diagram as a image)
  4. you have to register to tigress to tell them what bugs are there
  5. registration is required for any feature request

the community edition is suppose to be free but when i installed it. it asked for registration. so, i just un-installed it.

UML Studio 8:

the free version looks attractive but in the sequence diagram
  1. self message is not allowed.
  2. studio crashes quite often. even if you leave the message in between. that's it.. one more crash !!
UMLet :

Eclipse plug-in , requires to much effort to learn. and the effort is not worth it.

( Productivity is quite low using this tool)... one has to invest to much time to learn it. Instead to use the tool and get his work done or implementing ideas.

there are many other tools as well which i evaluated an wasted my bandwidth any time. which was not worth it.

Hope this saves your time and effort.



The best free tool which i found was Star UML ( 24MB) available at

it is excellent and very easy to use , on top of it this tool is open source.

Powered by ScribeFire.

Thursday, November 22, 2007

VBA macro Excel

How to Open Visual Code for the recorded Macro?

As I mentioned earlier Macro actually using visual basic programming language to perform given task. In order for you create more complicated macro it will be more better for you to understand the basic programming language which is VB. This learning process will be more easier after you record the macro immediately check the VB code. Record ---then Check the VB code. After several time now you will understand What code to be use for the specific task given. There are many ways to open our visual basic editor:
1st Method:

1) Click visual basic symbol at the toolbar
2) Another window open
3) Click at Module1
4) Immediately you can see the VB code.

2nd Method

1) Go to Tools>Macro>Macros..
2) Pop up menu ask you to choose macro
3) Choose your macro
4) If you desired to run the macro just click run
5) But this time you need to check VB code click edit
6) Now immediately you can see the code representing your task

I just wanted you guys to familiarize on how to open the VB code..That All
Practice, practice...& practice. O.k

Make sure you are fully understand how to check VB code immediately after record certain macro.

This is VB code editor look like.

How to edit recorded macro? Pls wait for me..Tks

How to run macro in Microsoft Excel from different workbook?

The steps are the same, the only thing you must open your workbook with macro inside and minimize. Now open your new workbook and follow the previous step:
  • Go to >Tools>Macro>Macros
  • Choose your Macro

All macro will be listed down if you select Macros in: All open Workbooks
  • Click at your desired macro and click run
  • End.
Re-cap :
Now you are willing to :
  1. record macro.
  2. Run macro.
  3. Run macro from different workbook.

Our Next Chapter will be more interesting because involved code editing:

How to edit recorded macro? Pls wait for me..Tks

How ro run macro in Microsoft Excel?

Before you can run your recorded macro you have to change your security level to medium:
  • Go to > Tools > security

  • Tick medium Security level

  • Click O.K
  • End.
Now your security level is medium and you can run the macro immediately.

I assume that your previous workbook still open which is inside your sheet 1, range A1:C10 consist of <Geniusideas> word.

Now go to sheet 2 and follow these steps:

  • Go to > Tools > macro > Macros….

  • Choose your Macro (If you have many type of macro recorded previously).

  • Click “Run”
  • End.

Now you have same result as sheet 1 but this time in sheet 2.
Pls try and try again with different step until you are familiar with it.

If you close and save your excel file, every time you open the file the macro must be enable before you can start using.

Our Next Chapter:

How to run macro in Microsoft Excel from different workbook? Pls wait for me..Tks

How to record macro in Microsoft excel?

Now open your Microsoft excel and create new file and normally by default three worksheets is inside.

  • Go to > Tools > macro > Record new macro…..
  • Rename your macro.
    Example : ToCreateMacroForTesting (make sure no space)
  • Stop button appeared and now you can start recording.

Try these steps:
1 – Select sheet 1
2 – Select range A1 : C10
3 – Type < GeniusIdeas >
4 – Press “Ctrl” button then Follow by “Enter”

  • Press Stop Button.
  • Select Range A1.
  • End.

Now your sheet 1, range A1:C10 consist of <Geniusideas> words,
Meaning you already have macro recorded inside your excel file that can be use anytime without repeating the above process but we can get same result.

To Start Recording :

1) Go to Tools >Macro >Record New Macro

Rename Your Macro :

1) By default it will appear macro1,2,3...follow sequence but it is good for you differenciate inbetween one another.(Example : Tosortfortesting) No space O.K...

To Stop Recording :

1) Press STOP Button.


2) Go to Tools >Macro >Stop Recording

Our Next Chapter will cover:
How to run macro in Microsoft excel? Pls wait for me..Tks

How to create macro in Microsoft excel ?

We can create macro in microsoft excel in two ways :
  • Write your own script using visual basic language.
  • Record your task step by step.
The easy way is to record the macro step by step and do the editing according to your requirement. Meaning to be more flexible and powerful you have to understand visual basic language(no need to be master) just to do editing after each recording process. You don't have to worry about the complexity of the language because you can learn along the recording process itself.
Example : when you do the recording immediately after the process you can analyze and change the script.

Our Next topic :

How to record Macro in microsoft excel? Pls be patience and wait for me..Tks

What Microsoft Excel Macro can do for you ?

I love so much about macro eventhough my knowledge about Visual Basic programming language was not very good and no formal training. Most of the skill that I learned are from Microsoft Excel help, internet, books and my Colleague Mr Raymund Lawrence Danker.

At my workplace I am handling a lot of data's and I found my subordinate having difficulties to do the sorting, segregating and arranging those data, some more thier skill and knowledge about excel totally zero at that time, since then I decided to learn more about Microsoft Excel macro. Now I am using the macro for :
  • To sort the unwanted data after being download from oracle system
  • To arrange the data accordingly
  • To format the data meet our requirement
  • To arrange multiple sheets of data into a single sheet
  • To rearrange data from one format to another format
  • To compare data with multiple sheet
  • To format the data for standard printing size..More and more
All the above task can be done with a single click and all my subordinate and Colleague happy about it because they don't have to do it in hard way.
Their productivity now is up to more than 1000% , I think..
Now you can imagine What microsoft excel macro can do to you?
Next topic:

1) How to create macro in excel ? Pls be patience..OK
wait for me..

What is Macro in Microsoft Excel ?

If you are Microsoft excel user for sure you are interested in this topic because by using Macro you can :
  • Perform a task repeatedly(You can perform same task again and again with single click).
  • The task perform automatically(You can sit down and see your task being perform).
Very interesting...?

Now take a look at the defination :
A macro is a series of commands and functions that are stored in a Microsoft Visual Basic module and can be run whenever you need to perform the task.
For example :
If you often enter long text strings in cells, you can create a macro to format those cells so that the text wraps automatically.

a) function:
A prewritten formula that takes a value or values, performs an operation, and returns a value or values. Use functions to simplify and shorten formulas on a worksheet, especially those that perform lengthy or complex calculations.

b) module:
A collection of declarations, statements, and procedures stored together as one named unit. There are two types of modules: standard modules and class modules.

Visual Basic :
High level programming language evolved from the earlier DOS version called BASIC. BASIC means Beginners' All-purpose Symbolic Instruction Code. It is a fairly easy programming language to learn. The codes look a bit like English Language. Different software companies produced different version of BASIC, such as Microsoft QBASIC, QUICKBASIC, GWBASIC ,IBM BASICA and so on.

If you do not know anything about Visual Basic, don't worry about that because in Microsoft excel we don't have to write, we can record the step with with formula and trick.
Let Move On....

Tuesday, November 13, 2007

The ARRL Handbook for Radio Communications 2007

Must have book for Practical Radio Frequency Designers.

Publisher: American Radio Relay League (ARRL)
Number Of Pages: 1091
Publication Date: 2006-10
Sales Rank: 59867
ISBN / ASIN: 0872599760
EAN: 9780872599765
Binding: Paperback
Manufacturer: American Radio Relay League (ARRL)
Studio: American Radio Relay League (ARRL)
Average Rating: 4.5

Learn UNIX in 10 minutes

Basic UNIX Command Line (shell) navigation


File and directory paths in UNIX use the forward slash "/"
to separate directory names in a path.


/ "root" directory
/usr directory usr (sub-directory of / "root" directory)
/usr/STRIM100 STRIM100 is a subdirectory of /usr

Moving around the file system:

pwd Show the "present working directory", or current directory.
cd Change current directory to your HOME directory.
cd /usr/STRIM100 Change current directory to /usr/STRIM100.
cd INIT Change current directory to INIT which is a sub-directory of the current
cd .. Change current directory to the parent directory of the current directory.
cd $STRMWORK Change current directory to the directory defined by the environment
variable 'STRMWORK'.

Listing directory contents:

ls list a directory
ls -l list a directory in long ( detailed ) format

for example:
$ ls -l
drwxr-xr-x 4 cliff user 1024 Jun 18 09:40 WAITRON_EARNINGS
-rw-r--r-- 1 cliff user 767392 Jun 6 14:28 scanlib.tar.gz
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
| | | | | | | | | | |
| | | | | owner group size date time name
| | | | number of links to file or directory contents
| | | permissions for world
| | permissions for members of group
| permissions for owner of file: r = read, w = write, x = execute -=no permission
type of file: - = normal file, d=directory, l = symbolic link, and others...

ls -a List the current directory including hidden files. Hidden files start with "."
ls -ld * List all the file and directory names in the current directory. Without the "d"
option, ls would list the contents of any sub-directory of the current. With the "d"

option, ls just lists them like regular files.

Changing file permissions and attributes

chmod 755 file Changes the permissions of file to be rwx for the owner, and rx for
the group and the world. (7 = rwx = 111 binary. 5 = r-x = 101 binary)
chgrp user file Makes file belong to the group user.
chown cliff file Makes cliff the owner of file.
chown -R cliff dir Makes cliff the owner of dir and everything in its directory tree.

You must be the owner of the file/directory or be root before you can do any of these things.

Moving, renaming, and copying files:

cp file1 file2 copy a file
mv file1 renamed file1 move or rename a file
rm file1 [file2 ...] remove or delete a file
rm -r dir1 [dir2...] recursivly remove a directory and its contents BE CAREFUL!
mkdir dir1 [dir2...] make a directory
rmdir dir1 [dir2...] remove an empty directory

Viewing and editing files:

cat filename Dump a file to the screen in ascii.
more filename Progressively dump a file to the screen: ENTER = one line down
SPACEBAR = page down q=quit
less filename Like more, but you can use Page-Up too. Not on all systems.
vi filename Edit a file using the vi editor. All UNIX systems will have vi in some form.
emacs filename Edit a file using the emacs editor. Not all systems will have emacs.
head filename Show the first few lines of a file.
head -n filename Show the first n lines of a file.
tail filename Show the last few lines of a file.
tail -n filename Show the last n lines of a file.


The behavior of the command line interface will differ slightly depending
on the shell program that is being used.

Depending on the shell used, some extra behaviors can be quite nifty.

You can find out what shell you are using by the command:

printenv SHELL

Of course you can create a file with a list of shell commands and execute it like
a program to perform a task. This is called a shell script. This is in fact the
primary purpose of most shells, not the interactive command line behavior.

Environment variables

You can teach your shell to remember things for later using environment variables.
For example under bash:

export CASROOT=/usr/local/CAS3.0 Defines the variable CASROOT with the value

cd $CASROOT Changes your present working directory to the value of CASROOT

export LD_LIBRARY_PATH=$CASROOT/Linux/lib Defines the variable LD_LIBRARY_PATH with the
value of CASROOT with /Linux/lib appended, or

printenv CASROOT Will print out the value of CASROOT, or /usr/local/CAS3.0

echo $CASROOT Does exactly the same thing

env | grep CASROOT A roundabout way to get the same information.

Interactive History

A feature of bash and tcsh (and sometimes others) you can use
the up-arrow keys to access your previous commands, edit
them, and re-execute them.

Filename Completion

A feature of bash and tcsh (and possibly others) you can use the
TAB key to complete a partially typed filename. For example if you
have a file called constantine-monks-and-willy-wonka.txt in your
directory and want to edit it you can type 'vi const', hit the TAB key,
and the shell will fill in the rest of the name for you (provided the
completion is unique).

Bash is the way cool shell.

Bash will even complete the name of commands and environment variables.
And if there are multiple completions, if you hit TAB twice bash will show
you all the completions. Bash is the default user shell for most Linux systems.


grep string filename > newfile
Redirects the output of the above grep command to a file 'newfile'.
grep string filename >> existfile
Appends the output of the grep command to the end of 'existfile'.

The redirection directives, > and >> can be used on the output of most commands
to direct their output to a file.


The pipe symbol "|" is used to direct the output of one command to the input
of another.

For example:

ls -l | more This commands takes the output of the long format directory list command
"ls -l" and pipes it through the more command (also known as a filter).
In this case a very long list of files can be viewed a page at a time.

Command Substitution

You can use the output of one command as an input to another command in another way
called command substitution. Command substitution is invoked when by enclosing the
substituted command in backwards single quotes. For example:

cat `find . -name aaa.txt`

which will cat ( dump to the screen ) all the files named aaa.txt that exist in the current
directory or in any subdirectory tree.

Searching for strings in files: The grep command

grep string filename prints all the lines in a file that contain the string

Searching for files : The find command

find search_path -name filename

find . -name aaa.txt Finds all the files named aaa.txt in the current directory or
any subdirectory tree.
find / -name vimrc Find all the files named 'vimrc' anywhere on the system.
find /usr/local/games -name "*xpilot*"
Find all files whose names contain the string 'xpilot' which
exist within the '/usr/local/games' directory tree.

Reading and writing tapes, backups, and archives: The tar command

The tar command stands for "tape archive". It is the "standard" way to read
and write archives (collections of files and whole directory trees).

Often you will find archives of stuff with names like stuff.tar, or stuff.tar.gz. This
is stuff in a tar archive, and stuff in a tar archive which has been compressed using the
gzip compression program respectivly.

Chances are that if someone gives you a tape written on a UNIX system, it will be in tar format,
and you will use tar (and your tape drive) to read it.

Likewise, if you want to write a tape to give to someone else, you should probably use
tar as well.

Tar examples:

tar xv Extracts (x) files from the default tape drive while listing (v = verbose)
the file names to the screen.
tar tv Lists the files from the default tape device without extracting them.
tar cv file1 file2
Write files 'file1' and 'file2' to the default tape device.
tar cvf archive.tar file1 [file2...]
Create a tar archive as a file "archive.tar" containing file1,
tar xvf archive.tar extract from the archive file
tar cvfz archive.tar.gz dname
Create a gzip compressed tar archive containing everything in the directory
'dname'. This does not work with all versions of tar.
tar xvfz archive.tar.gz
Extract a gzip compressed tar archive. Does not work with all versions of tar.
tar cvfI archive.tar.bz2 dname
Create a bz2 compressed tar archive. Does not work with all versions of tar

File compression: compress, gzip, and bzip2

The standard UNIX compression commands are compress and uncompress. Compressed files have
a suffix .Z added to their name. For example:

compress part.igs Creates a compressed file part.igs.Z

uncompress part.igs Uncompresseis part.igs from the compressed file part.igs.Z.
Note the .Z is not required.

Another common compression utility is gzip (and gunzip). These are the GNU compress and
uncompress utilities. gzip usually gives better compression than standard compress,
but may not be installed on all systems. The suffix for gzipped files is .gz

gzip part.igs Creates a compressed file part.igs.gz
gunzip part.igs Extracts the original file from part.igs.gz

The bzip2 utility has (in general) even better compression than gzip, but at the cost of longer
times to compress and uncompress the files. It is not as common a utility as gzip, but is
becoming more generally available.

bzip2 part.igs Create a compressed Iges file part.igs.bz2
bunzip2 part.igs.bz2 Uncompress the compressed iges file.

Looking for help: The man command

Most of the commands have a manual page which give sometimes useful, often more or less
detailed, sometimes cryptic and unfathomable discriptions of their usage. Some say they
are called man pages because they are only for real men.


man ls Shows the manual page for the ls command

Basics of the vi editor

Opening a file
vi filename

Creating text

i Insert before current cursor position
I Insert at beginning of current line
a Insert (append) after current cursor position
A Append to end of line
r Replace 1 character
R Replace mode
Terminate insertion or overwrite mode

Deletion of text

x Delete single character
dd Delete current line and put in buffer
ndd Delete n lines (n is a number) and put them in buffer
J Attaches the next line to the end of the current line (deletes carriage return).


u Undo last command

cut and paste
yy Yank current line into buffer
nyy Yank n lines into buffer
p Put the contents of the buffer after the current line
P Put the contents of the buffer before the current line

cursor positioning
^d Page down
^u Page up
:n Position cursor at line n
:$ Position cursor at end of file
^g Display current line number
h,j,k,l Left,Down,Up, and Right respectivly. Your arrow keys should also work if
if your keyboard mappings are anywhere near sane.

string substitution

:n1,n2:s/string1/string2/[g] Substitute string2 for string1 on lines
n1 to n2. If g is included (global),
all instances of string1 on each line
are substituted. If g is not included,
only the first instance per line is

^ matches start of line
. matches any single character
$ matches end of line

These and other "special characters" (like the forward slash) can be "escaped" with \
i.e to match the string "/usr/STRIM100/SOFT" say "\/usr\/STRIM100\/SOFT"


:1,$:s/dog/cat/g Substitute 'cat' for 'dog', every instance
for the entire file - lines 1 to $ (end of file)

:23,25:/frog/bird/ Substitute 'bird' for 'frog' on lines
23 through 25. Only the first instance
on each line is substituted.

Saving and quitting and other ex commands

These commands are all prefixed bu touching the colon ( and entered in the lower left corner
of the window. You cannot enter a ex command when you are in an edit mode. Touch to exit from
an editing mode.

:w Write the current file.
:w new.file Write the file to the name 'new.file'.
:w! existing.file Overwrite an existing file with the file currently being edited.
:wq Write the file and quit.
:q Quit.
:q! Quit with no changes.

:e filename Open the file 'filename' for editing.

:set number Turns on line numbering
:set nonumber Turns off line numbering

Preface This is something that I have given out to students (CAD user training) of mine for several years. The purpose is to have on one page the basics to get started using the UNIX command line (so that they don't call me asking what to do the first time someone gives them a tape or something). This document is copyrighted but freely redistributable under the terms of the GFDL