Presenting at North Carolina Oracle User Group This Friday

For anyone in the area of Raleigh, North Carolina this week I will be presenting at the North Carolina Oracle User Group’s fall meeting. I will be giving a presentation on Oracle Shell Scripting which includes several tips and scripts from my book by the same title.

Don Burleson will also be presenting on Oracle 11g new features. The meeting runs from 12:30 to 4:30 this Friday, October 5th. More details are available on the NCOUG site.

oracle, dba, database, database administrator, 11g, unix, linux

Search pages in Firefox with just one key

So here’s a nice little Firefox easter egg for vi users:

In Firefox (at least version 2.0.0.6 on the PC, I haven’t confirmed this on others) you can search for text by simply typing a slash (/). As long as you’re not in a text entry box the / character will open up the find dialog box just like control-f would.

For those of you who don’t understand the significance of this, in the popular UNIX command line text editor vi you search for text by typing /string to find. This is typical of how vi works: powerful, simple commands which are rarely obvious.

vi, unix, linux, firefox, web, internet

Built-in shell scripting variables

UNIX and Linux shells provide an abundance of useful built-in information that can be referenced in globally available variables. In order to see the information provided in a shell, the set command can be run as demonstrated below.

Here’s a partial output of the set command:

$ set
BASH=/bin/bash
BASH_VERSINFO=([0]="2" [1]="05b" [2]="0" [3]="1" [4]="release" [5]="i386-redhat-linux-gnu")
BASH_VERSION='2.05b.0(1)-release'
GROUPS=()
G_BROKEN_FILENAMES=1
HISTFILE=/home/tclark/.bash_history
HISTFILESIZE=1000
HISTSIZE=1000
HOME=/home/tclark
HOSTNAME=appsvr.mytec.com
OSTYPE=linux-gnu
PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/tclark/bin
...
PS1='[\u@\h \W]\$ '
PS2='> '
PS4='+ '
PWD=/home/tclark
SHELL=/bin/bash
SHLVL=1
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SSH_CLIENT='206.107.231.178 1379 22'
SSH_CONNECTION='206.107.231.178 1379 192.168.15.105 22'
SSH_TTY=/dev/pts/0
SUPPORTED=en_US.UTF-8:en_US:en
TERM=vt100
UID=503
USER=tclark
_=clear

The contents of a shell variable can be displayed by using the echo command and prefacing the variable name with a dollar sign as demonstrated below. Shell variables are referenced using all capital letters.

$ echo $TERM
vt100
$ echo $USER
tclark
$ echo $HOSTNAME ... $LOGNAME
appsvr.mytec.com ... tclark

There are also some special built-in variables that can be useful when creating shell scripts. Some of them are listed in the table below.

Built-in Variable Description
$# The total number of arguments passed to a shell script on the command line.
$* All arguments passed to the shell script.
$0 The command (script) invoked on the command line.
$1 – $9 The first through ninth arguments passed to the shell script from the command line.

These variables are provided by the shell and the names should not be used for other variables.

Easy Linux CommandsFor more tips like this check out my book Easy Linux Commands, only $19.95 from Rampant TechPress.

Buy it now!


linux, unix, system administration, sysadmin

Command aliases in Linux and UNIX

Aliases can be used to perform complex commands but are set in the shell like environmental variables.

If you find yourself frequently using a fairly complicated command like the one below and want to be able to run it without typing the whole thing you can use the alias command to set up a shortcut.

$ alias alert=’tail -200 /u01/installed/software/mypgm/alert.log|more’

Now you can execute this whole command simply by typing alert. Many of the features of shell scripting are available in aliases including the pipe (|) used to send the output of one command to the input of another.

If you would like to have an alias automatically set up every time you enter a shell you can add the alias definition to your .profile file (or whatever file your default shell executes at login.)

A small set of well written aliases can save you a lot of keystrokes, just be careful not to make aliases with the same name as commands you use unless you want the alias to replace that command when you type it.

Easy Linux CommandsFor more tips like this check out my book Easy Linux Commands, only $19.95 from Rampant TechPress.

Buy it now!


linux, unix, system administration, sysadmin

Viewing strings of text in binary files on Linux and UNIX

If a user encounters a binary file and does not know what it is used for or where it came from, they may gain some insight into its origins and use by searching for character strings within the file. If the cat command is used to view a binary file, the user will get a screen full of garbage that will more often than not change the display characteristics. Instead, the strings command should be used, as demonstrated in the following examples:

Find All Strings in the Binary File

$ strings echo
/lib/ld-linux.so.2
libc.so.6
stdout
getopt_long
__fpending
getenv
...
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%s (%s) %s
Written by %s.
%s %s
memory exhausted

Again the above output has been abbreviated to save space, but you can see that there is some useful information here. Just knowing that “This is free software” and that it is copyrighted by the Free Software Foundation can give you some great insight on where this came from and why it might be there.

Finding Occurrences of a String in a Binary File

Here we show how the output of the strings command can be piped into the grep command to look for specific words within a binary file.

$ strings echo|grep GLIBC
GLIBC_2.3
GLIBC_2.1.3
GLIBC_2.1
GLIBC_2.0
GLIBC_2.2

This shows how grep can be used to limit the output of a command to only lines that contain certain text.

Easy Linux CommandsFor more tips like this check out my book Easy Linux Commands, only $19.95 from Rampant TechPress.

Buy it now!


unix, linux, text, search, find