Archive

Archive for January, 2010

My .02 on Apple’s anti-flash, anti-freedom movement.

January 29th, 2010 Jimmy 1 comment

As many of you iPhone consumers may know, Flash isn’t supported and will probably never be supported. The new up and coming iPad (Apple Tablet) will be running a version of the iPhone operating system and will probably have the same exact restrictions. The reason Apple doesn’t want to support Flash is because it allows third party developers to create applications for the iPhone (and soon iPad) for free. Everyone would be making little Flash-lets for the Apple devices and Apple would lose income (that’s dollars) from their app store. Read more…

Linux: (g) awk – search and replace.

January 29th, 2010 Jimmy No comments

awk or gawk (gnu awk)

Find and Replace text, database sort/validate/index

Syntax

      awk <options> 'Program' Input-File1 Input-File2 ...

      awk -f PROGRAM-FILE <options> Input-File1 Input-File2 ...

Key
 -F FS
 --field-separator FS
     Use FS for the input field separator (the value of the `FS'
     predefined variable).

 -f PROGRAM-FILE
 --file PROGRAM-FILE
     Read the `awk' program source from the file PROGRAM-FILE, instead
     of from the first command line argument.

 -mf NNN
 -mr NNN
     The `f' flag sets the maximum number of fields, and the `r' flag
     sets the maximum record size.  These options are ignored by
     `gawk', since `gawk' has no predefined limits; they are only for
     compatibility with the Bell Labs research version of Unix `awk'.

 -v VAR=VAL
 --assign VAR=VAL
     Assign the variable VAR the value VAL before program execution
     begins.

 -W traditional
 -W compat
 --traditional
 --compat
     Use compatibility mode, in which `gawk' extensions are turned off.

 -W lint
 --lint
     Give warnings about dubious or non-portable `awk' constructs.

 -W lint-old
 --lint-old
     Warn about constructs that are not available in the original
     Version 7 Unix version of `awk'.

 -W posix
 --posix
     Use POSIX compatibility mode, in which `gawk' extensions are
     turned off and additional restrictions apply.

 -W re-interval
 --re-interval
     Allow interval expressions, in regexps.

 -W source=PROGRAM-TEXT
 --source PROGRAM-TEXT
     Use PROGRAM-TEXT as `awk' program source code.  This option allows
     mixing command line source code with source code from files, and is
     particularly useful for mixing command line programs with library
     functions.

 --
     Signal the end of options.  This is useful to allow further
     arguments to the `awk' program itself to start with a `-'.  This
     is mainly for consistency with POSIX argument parsing conventions.

'Program'
     A series of patterns and actions: see below

Input-File
     If no Input-File is specified then `awk' applies the Program to
     "standard input", (piped output of some other command or the terminal.
     Typed input will continue until end-of-file (typing `Control-d')

Basic functions

The basic function of awk is to search files for lines (or other units of text) that contain a pattern. When a line matches, awk performs a specific action on that line.

The Program statement that tells `awk’ what to do; consists of a series of “rules”. Each rule specifies one pattern to search for, and one action to perform when that pattern is found.

For ease of reading, each line in an `awk’ program is normally a separate Program statement , like this:

     pattern { action }
     pattern { action }
     ...

e.g. Display lines from my_file containing the string “123″ or “abc” or “some text”:

awk '/123/ { print $0 }
     /abc/ { print $0 }
     /some text/ { print $0 }' my_file

A regular expression enclosed in slashes (`/’) is an `awk’ pattern that matches every input record whose text belongs to that set. e.g. the pattern /foo/ matches any input record containing the three characters `foo’, *anywhere* in the record.

`awk’ patterns may be one of the following:

/Regular Expression/        - Match =
Pattern && Pattern          - AND
Pattern || Pattern          - OR
! Pattern                   - NOT
Pattern ? Pattern : Pattern - If, Then, Else
Pattern1, Pattern2          - Range Start - end
BEGIN                       - Perform action BEFORE input file is read
END                         - Perform action AFTER input file is read

In addition to simple pattern matching `awk’ has a huge range of text and arithmetic Functions, Variables and Operators.

`gawk’ will ignore newlines after any of the following:

    , { ? : || && do else

Comments – start with a `#’, and continue to the end of the line:

 # This program prints a nice friendly message

Examples

This program prints the length of the longest input line:

 awk '{ if (length($0) > max) max = length($0) }
      END { print max }' data

This program prints every line that has at least one field. This is an easy way to delete blank lines from a file (or rather, to
create a new file similar to the old file but from which the blank lines have been deleted)

 awk 'NF > 0' data

This program prints seven random numbers from zero to 100, inclusive.

 awk 'BEGIN { for (i = 1; i <= 7; i++)
                print int(101 * rand()) }'

This program prints the total number of bytes used by FILES.

 ls -lg FILES | awk '{ x += $5 } ; END { print "total bytes: " x }'

This program prints a sorted list of the login names of all users.

 awk -F: '{ print $1 }' /etc/passwd | sort

This program counts lines in a file.

 awk 'END { print NR }' data

This program prints the even numbered lines in the data file. If you were to use the expression `NR % 2 == 1′ instead, it would print the odd numbered lines.

 awk 'NR % 2 == 0' data
Categories: Power Computing Tags:

Setup a telnet chat server with STChat.

January 29th, 2010 Jimmy No comments

STChat is a simple telnet chat server that runs on Linux, Windows and MAC. I’ve only tested this on Linux so i can’t speak for the other OS’s. The chat system is really simple, supports colors, multiple terminal types (vt100 etc), usernames and admin mode. Putty, Linux telnet, and Windows telnet seem to work just fine when connecting to the chat server. No special installation is needed except that you do need a Java Runtime Environment (JRE) to run the server. Simply unpack the package and run ‘java stc 2020` to start the server on port 2020. If you want to run STchat on the standard telnet port, port 23, you’ll need to run the server as root. e.g. java stc 23

STChat comes with the complete source. Some of the code is deprecated but you can simply ignore these messages at compile time. Note: Default compiled binaries are included so don’t worry about this unless you plan to modify the source code. The STChat project page is located here.

Read more…

Linux: cut – divide file into columns.

January 28th, 2010 Jimmy No comments

cut

Divide a file into several parts (columns)
Writes to standard output selected parts of each line of each input file, or standard input if no files are given or for a file name of `-’.

Syntax
     cut [OPTION]... [FILE]...

In the options below, BYTE-LIST, CHARACTER-LIST, and FIELD-LIST are one or more numbers or ranges (two numbers separated by a dash)

Bytes, characters, and fields are are numbered starting at 1 and separated by commas.
Incomplete ranges may be given: -M means 1-M  ;  N- means N through end of line or last field.

Options

-b BYTE-LIST
--bytes=BYTE-LIST
     Print only the bytes in positions listed in BYTE-LIST.  Tabs and
     backspaces are treated like any other character; they take up 1
     byte.

-c CHARACTER-LIST
--characters=CHARACTER-LIST
     Print only characters in positions listed in CHARACTER-LIST.  The
     same as `-b' for now, but internationalization will change that.
     Tabs and backspaces are treated like any other character; they
     take up 1 character.

-f FIELD-LIST
--fields=FIELD-LIST
     Print only the fields listed in FIELD-LIST.  Fields are separated
     by a TAB character by default.

-d INPUT_DELIM_BYTE
--delimiter=INPUT_DELIM_BYTE
     For `-f', fields are separated in the input by the first character
     in INPUT_DELIM_BYTE (default is TAB).

-n
     Do not split multi-byte characters (no-op for now).

-s
--only-delimited
     For `-f', do not print lines that do not contain the field
     separator character.

--output-delimiter=OUTPUT_DELIM_STRING
     For `-f', output fields are separated by OUTPUT_DELIM_STRING The
     default is to use the input delimiter.

Example

Parse out column 2 from a semicolon (;) delimited file:

$ cat myfile.txt | cut -d \; -f 2 > output.txt

CommentGator for Windows 7.

January 27th, 2010 Jimmy No comments

CommentGator for Windows 7 has been officially released. The current version has now been tested on Windows Vista and Windows 7.

Bug Fixes:

* Closing of the first tab should now work.

* JavaScript errors should now be suppressed.

* Some minor interfaces chances have been made.

Download the latest version here.

Categories: Project News Tags: ,

Zero-Fill Partitions

January 27th, 2010 Jimmy No comments

Today I released my first version of Treadstone Zero, a utility distribution that lets you easily zero-fill hard drive partitions. The system boots in less than 10 seconds (on most systems), consists of a Linux 2.6 kernel and runs totally in ram.

Check it out here.

Categories: Project News Tags:

Windows: comp – compare files

January 27th, 2010 Jimmy No comments

COMP

Compare two files (or sets of files). Display items which do not match.

Syntax
      COMP [pathname1] [pathname2] [/D] [/A] [/L] [/N=number] [/C]

Key
   pathname1 The path and filename of the first file(s)
   pathname2 The path and filename of the second file(s)
   /D        Display differences in decimal format. (default)
   /A        Display differences in ASCII characters.
   /L        Display line numbers for differences.
   /N=number Compare only the first X number of lines in the file.
   /C        do a case insensitive string comparison

Running COMP with no parameters will result in a prompt for the 2 files and any options

To compare sets of files, use wildcards in pathname1 and pathname2 parameters.

When used with the /A option COMP is similar to the FC command but it displays the individual characters that differ between the files rather than the whole line.

To compare files of different sizes, use /N= to compare only the first n lines (common portion of each file.)

COMP will normally finish with a Compare more files (Y/N) prompt
to suppress this: ECHO n|COMP <options>

Categories: Power Computing Tags:

Windows: cipher – encrypt or decrypt

January 27th, 2010 Jimmy No comments

CIPHER

Encrypt or Decrypt files and folders.
Without parameters cipher will display the encryption state of the current folder and files.
NTFS volumes only.

Syntax:

 Encrypt/Decrypt:
    CIPHER [{/e | /d}] [/s:Folder] [options] [/u[/n]] [{PathName [...]]

 New recovery agent certificate:
    CIPHER /r:PathNameWithoutExtension

 Remove data:
    CIPHER /w:PathName

 Backup Keys:
    CIPHER /x[:PathName]

options:

   /e    Encrypt the folders.
         Folders are marked so that files that are added to the folder later
         are encrypted too.

   /d    Decrypt the folders.
         Folders are marked so that files that are added to the folder later
         are encrypted too.

   /s:Folder
         Performs the operation in the folder and all subfolders.

   /a    Perform the operation for files and directories.

   /i    Continue even after errors occur.
         By default, cipher stops when it encounters an error.

   /f    Force the encryption or decryption of all specified objects.
         By default, cipher skips files that have been encrypted or decrypted already.

   /q    Quiet - Report only essential information.

   /h    Display files with hidden or system attributes.
         By default, these files are not encrypted or decrypted.

   /k    Create a new file encryption key for the user running cipher.

   /u    Update the user's file encryption key or recovery agent's key
         to the current ones in all of the encrypted files on local drives
         (that is, if the keys have been changed).
         This option only works with /n.
   /n    Prevent keys from being updated.
         Use this option to find all of the encrypted files on the local drives.
         This option only works with /u. 

  PathName
         A pattern, file, or folder.

   /r:PathNameWithoutExtension
         Generate a new recovery agent certificate and private key, and
         then write them to files with the filename PathNameWithoutExtension.

   /w:PathName
         Remove data from unused portions of a volume.
         PathName can indicate any directory on the desired volume.
         Cipher does not obtain an exclusive lock on the drive.
         This option can take a long time to complete and should only be used when necessary.

   /x[:PathName] PathNameWithoutExtension
         Identifies the certificates and private keys used by EFS for the
         currently logged on user and backs them up to a file.
         If PathName is provided, the certificate used to encrypt the files
         is backed up. Otherwise, the user's current EFS certificate and keys
         will be backed up.
         The certificates and private keys are written to a file name
         PathNameWithoutExtension plus the file extension .pfx.

Notes

It is recommended that you always encrypt both the file and the folder in which it resides, this prevents an encrypted file from becoming decrypted when it is modified.

Cipher cannot encrypt files that are marked as read-only.

Cipher will accept multiple folder names and wildcard characters. You must separate multiple parameters with at least one space.

Examples

List encrypted files in the reports folder are:

CIPHER c:\reports\*

Encrypt the Reports folder and all subfolders:

CIPHER /e /s:C:\reports

To back up the certificate and private key currently used to encrypt and decrypt EFS files to a file named c:\myefsbackup.pfx, type:

CIPHER /x c:\myefsbackup

Categories: Power Computing Tags:

Linux: screen – multiplex terminals

January 27th, 2010 Jimmy No comments

screen

Multiplex a physical terminal between several processes (typically interactive shells).

Syntax:

   Start a screen session:

       screen [ -options ] [ cmd [args] ]

   Resume a detached screen session:

      screen -r [[pid.]tty[.host]]

      screen -r sessionowner/[[pid.]tty[.host]]

Options:

   -A -[r|R]     Adapt all windows to the new display width & height.
   -c file       Read configuration file instead of .screenrc
   -d (-r)       Detach the elsewhere running screen (and reattach here).
   -dmS name     Start as daemon: Screen session in detached mode.
   -D (-r)       Detach and logout remote (and reattach here).
   -D -RR        Do whatever is needed to Reattach a screen session.
   -d -m         Start in "detached" mode. Useful for system startup scripts.
   -D -m         Start in "detached" mode, & don't fork a new process.
   -list         List our SockDir and do nothing else (-ls)
   -r            Reattach to a detached screen process.
   -R            Reattach if possible, otherwise start a new session.
   -t title      Set title. (window's name).
   -U            Tell screen to use UTF-8 encoding.
   -x            Attach to a not detached screen. (Multi display mode).
   -X            Execute cmd as a screen command in the specified session.

Interactive commands:

     Control-a ?    Display brief help
     Control-a "    List all windows for selection
     Control-a '    Prompt for a window name or number to switch to.
     Control-a 0    Select window 0
     Control-a 1    Select window 1
     ...            ...
     Control-a 9    Select window 9
     Control-a A    Accept a title name for the current window.
     Control-a b    Send a break to window
     Control-a c    Create new window running a shell
     Control-a C    Clear the screen
     Control-a d    Detach screen from this terminal.
     Control-a D D  Detach and logout.
     Control-a f    Toggle flow on, off or auto.
     Control-a F    Resize the window to the current region size.
     Control-a h    Write a hardcopy of the current window to file "hardcopy.n"
     Control-a H    Begin/end logging of the current window to file "screenlog.n"
     Control-a i    Show info about this window.
     Control-a k    Kill (Destroy) the current window.
     Control-a l    Fully refresh current window
     Control-a M    Monitor the current window for activity {toggle on/off}
     Control-a n    Switch to the Next window
     Control-a N    Show the Number and Title of window
     Control-a p    Switch to the Previous window
     Control-a q    Send a control-q to the current window(xon)
     Control-a Q    Delete all regions but the current one.(only)
     Control-a r    Toggle the current window's line-wrap setting(wrap)
     Control-a s    Send a control-s to the current window(xoff)
     Control-a w    Show a list of windows (windows)
     Control-a x    Lock this terminal (lockscreen)
     Control-a X    Kill the current region(remove)
     Control-a Z    Reset the virtual terminal to its "power-on" values
     Control-a Control-\    Kill all windows and terminate screen(quit)
     Control-a :    Enter command line mode(colon)
     Control-a [    Enter copy/scrollback mode(copy)
     Control-a ]    Write the contents of the paste buffer to stdin(paste)
     Control-a _    Monitor the current window for inactivity {toggle on/off}
     Control-a *    Show  a listing of all currently attached displays.

When screen is called, it creates a single window with a shell in it (or the specified command) and then gets out of your way so that you can use the program as you normally would.

Then, at any time, you can:

Create new (full-screen) windows with other programs in them (including more shells)

Kill existing windows

View a list of windows

Switch between windows – all windows run their programs completely independent of each other. Programs continue to run when their window is currently not visible and even when the whole screen session is detached from the user’s terminal.

The interactive commands above assume the default key bindings. You can modify screen’s settings by creating a ~/.screenrc file in your home directory. This can change the default keystrokes, bind function keys F11, F12 or even set a load of programs/windows to run as soon as you start screen.

Attaching and Detaching

Once you have screen running, switch to any of the running windows and type Control-a d. this will detach screen from this terminal. Now, go to a different machine, open a shell, ssh to the machine running screen (the one you just detached from), and type: % screen -r

This will reattach to the session. Just like magic, your session is back up and running, just like you never left it.

Exiting screen completely

Screen will exit automatically when all of its windows have been killed.

Close whatever program is running or type `Exit ‘ to exit the shell, and the window that contained it will be killed by screen. (If this window was in the foreground, the display will switch to the previous window)

When none are left, screen exits.

This page is just a summary of the options available, type man screen for more.

Categories: Power Computing Tags:

Linux: chroot – change root directory.

January 27th, 2010 Jimmy No comments

chroot

Run a command with a different root directory.

‘chroot’ runs a command with a specified root directory. On many systems, only the super-user can do this.

SYNTAX
     chroot NEWROOT [COMMAND [ARGS]...]

     chroot OPTION

Ordinarily, filenames are looked up starting at the root of the directory structure, i.e. ‘/’

‘chroot’ changes the root to the directory NEWROOT (which must exist) and then runs COMMAND with optional ARGS.

If COMMAND is not specified, the default is the value of the `SHELL’ environment variable or `/bin/sh’ if not set, invoked with the `-i’ option.

The only options are `–help’ and `–version’

Categories: Power Computing Tags: