Raj Patel's Weblog

Home  |  News  | Links | Information | Pictures | Archive  

 

Collection of Unix Guru Universe Tips

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 1991 - June 14, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


TRUE64 SENDING JOBS

I use this script in
tru64 unix -Alpha
servers to send jobs to
all printers.

#!/bin/ksh
# this script is sending
# the required printing
# job to all printers
# already configured in
# your system,

cat /etc/printcap|grep "|" |cut -f 1 -d "|" | while read line anything
do
echo " sending file $1 to printer $line "
echo " lpr -P$line " $1
sleep 1
echo " to stop printing, press ctrl+c"
clear
lpr -P$line $1
done


This tip generously supported by: shadia@dohms.gov.ae

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 1993 - June 16, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


LARGES FILES MORE FLAVORS

Recently a single line
script was posted to UGU
to list the largest files
in a filesystem in order
of descending size.
The script worked as posted
on AIX but required tweaking
for SCO OSR5 and UW7.
Here 'tis for your
edification and enjoyment:

OSR5:
find $1 -type f -size +2048 -xdev -exec ls -s {} | /bin/sort -brut " "

UW7:
find $1 -type f -size +2048 -xdev -exec ls -s {} + | /bin/sort -nr

I placed the script in
/usr/local/bin and removed
the pipe to "more" in the
published version to allow
redirection to a file. I
also arbitrarily added the
"-size +2048" to the find
command to limit the list
to files of 1 Mb or larger;
you may modify or remove as
desired.

Thank you,
Lucky Leavell

 


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 1994 - June 17, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


AUTOMATIC LOGIN TO REMOTE HOSTS

Consider two hosts.
host1.domain.com
host2.domain.com

>From hosts(user:deepak),
you wish to logon to
host1(user:paul).

Paul would create a .rhosts
file in his directory

chmod 744 .rhosts

(No write permission for
others) The first line
would contain
host1.domain.com deepak

Now, deepak should be able
to logon to host2.domain.com
as user paul by using rlogin.

Deepak will type
e.g
rlogin hosts.domain.com -l paul

And he should be in.

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 1995 - June 18, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


FTP AUTOMATED TRANSFERS

To add to the earlier tip
on automated transfer using
FTP, you can define a macro
by name 'init' which will
automate the whole transfer.

Defining the macro.

In the .netrc file after the
definition for the machine
name,add the following
definition.

macdef init
bin
hash
cd <directory>
!cd <directory>
put/get <filename>
bye

The line begining with macdef
starts the definition of a
macro.All the sub sequent
lines upto a blank line (or
end of file) are part of
the macro.

Now if you type ftp
<machine name> at the prompt,
the whole ftp will happen
automatically.

These macros can also be
defined in any other name in
which case,you will have to
type the macro name at the
ftp prompt for its statements
to get executed.


This tip generously supported by: subha@hitechclub.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 1996 - June 19, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


AWK THE STATS


AWK script for getting
statistics.

The script gives the
statistics of the default
shell set for the users.

i.e. Number of users using
csh,ksh or sh

$cat stat_demo.awk
#start here
BEGIN{
FS=":"
#seperator is set to :
}
{
#$7, is 7 field in passwd file
stat_array[$7]=stat_array[$7]+1;
}
END{
print "Login-Shell Count" ;
for (i in stat_array) print i, stat_array[i]
#Displays statistics
}
#end here


To use this , Just say

awk -f stat_demo.awk /etc/passwd

or

cat /etc/passwd | awk stat_demo.awk

This tip generously supported by: dkotian1@rediffmail.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 1997 - June 20, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


STAT FILES

Not supported on all flavors.

To see inode contents (file
size, allocated blocks,
file type, user, group, file
mode, last accessed, last
modified etc) of a file:

$ stat file1 file2 fileN


This tip generously supported by: sachin_m_joshi@yahoo.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 1998 - June 21, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


ECHO LINES TO A BLANK


To echo all lines in a
file upto the first blank
line use the following:

awk '$0 ~ /^$/ {exit;} {print $0;}' <file_name>

The awk script can be used
for printing lines upto the
first occurence of any
pattern.

Just substitute ^$ with
the pattern.

I wrote this script to parse
http server headers.

This tip generously supported by: anand@anandraman.net

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 1999 - June 22, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


WHY MV IS SLOW

mv command across filesystems
is slower on large files

WHY?

mv would be slow if you are
moving files across filesystem.

The inode number changes only
when a file is moved across
file system.

A new inode number means a new
file is physically created on
disk.

It remains unchanged, if it
is within the same filesystem.
One can verify by using
ls -il command on that file.

mv uses rename() system call.
if it fails, it uses copy routine
(basicailly reads from a file and
writes in another file).

mv command across filesystem is
more of a copy then mv.


This tip generously supported by: dkotian1@rediffmail.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2000 - June 23, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


MAX FILES UNDER LINUX

Maximum number of files
that one process can
have open at one time can
be find out by using:

getconf OPEN_MAX

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2001 - June 24, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


FINDING MAC ADDRESS ON HP

If you want to know the
MAC or eathernet address of
your lan card on an HP-UX
machine, then type:

lanscan

This will give you the mac
addresses of all the lan
cards installed on the
machine.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2002 - June 25, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


HANGING TIME ON HPUX

How can we change the
time zone on a HP-UX
machine ??

Answer : -Edit the entry
in /etc/src.sh and
/etc/src.csh, and
reboot


This tip generously supported by: anil_sedha@mumbai.tcs.co.in

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2003 - June 26, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


FINDING PCI DEVICES

Want to get information
on PCI devices on your
Linux or FreeBSD machine?

On Linux use:

/sbin/lspci (-v is verbose)

On FreeBSD use:

pciconf -l

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2004 - June 27, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


ELIMINATING MULTIPLE SPACES

Here is a simple script which
helps in eliminating multiple
spaces when one wants to
extract a particular column
in a set of records from a
file.

Here is an example to prove
the same:

ps -u $LOGNAME | tr -s " " : | cut -d: -f<column #>

The above script line can be
used to extract a column from
the output of a ps command for
a particular user ($LOGNAME).

This tip generously supported by: arunkv@lucent.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2005 - June 28, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


Tru64 STTY DEC

On Tru64 Unix (at least on 4.0F),
some non-root-user drop an error
message on the root's Mail
account when cronjobs used

su - foo -c /usr/bin/bar

Even some Compaq technicians could
not tell that this results from
terminal settings in the .profile,
which are invalid on non-interactive
terminals. The error messages
(2 in fact) looks like this:

stty: tcgetattr: not a typewriter
Not a terminal.

The solution is to wrap commands
like "stty dec" and "tset -I -Q"
with a check on terminal capabilities:

if tty -s
then
stty dec
tset -I -Q
fi


This tip generously supported by: nils@poppendiek.de

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2006 - June 29, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


FILE SYSTEM CAPACITY ALERT

#!/bin/sh
# This script can be used to
# warn the users that
# the file system is getting full
#
# Script needs adjusted for your
# needs. Below is set to monitor
# all the file systems mounted and report to
# RECEIVER
#
# Usage: as a cron entry for best use.


RECEIVER=nachiappan.ramanathan@aig.com

for fs in `df -k|awk '{print $1}'|sed -n "3,14 p"`
do
x=`df -kl | grep $fs | awk '{ print $5 }'`
y=50%

if [ $x -gt $y ]
then
message="File System `df -k |grep $fs |awk '{print $6\",
\"$5}'` Full!!!"
echo $subject
echo $message | mailx -s "`hostname` - File System Full
Warning !!!" $RECEIVER
fi
done

This tip generously supported by:
Nachiappan.Ramanathan@aig.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2007 - June 30, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


HP-UX REMOVE UNUSED SPACE

To remove unused s/w and free
disk space in hp-ux use the
command:

freedisk [-a n] [-v]

Note: See man page for this
before executing this..

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2008 - July 1, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


PROGRESS STATUS IN XTERM TITLEBAR

Sometimes it is handy to be able
to show some information in the
xterms title bar, for example
if you download a set of large
files (thereby producing lots
of meaningless information on
the terminal) and you want to
know which file is actually
beeing downloaded.

For this purpose, I hacked a few
lines of shell code that would
put any information into the
xterms title bar. I called the
script ttshow.

#!/bin/sh
if [ -z $DISPLAY ]; then
echo "ESC]0; $* ^G"
fi

In this little script, the
string ESC has to be replaced
by one real escape character
(ascii 0x1b), the string "^G"
has to be replaced by a bel
character (ascii 0x07).

Now I can make my scripts like
this:

for file in in `cat filenames`; do
ttshow "downloading $file"
wget $file
done

..and it will tell me on the
first glance what it's doing.

For more information about
this, unpack the X distribution
and search for the file
ctlseqs.ms - this file belongs
to the xterm distribution and
contains all the escape
sequences xterm knows about.


This tip generously supported
by: ulinzen+ugu@sendmail.com

 


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2009 - July 2, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


AVOID PERMISION DENIED

To avoid 'Permission Denied'
messages when using the
'find' command:

in ksh :-
find <dir> -name '<file>' -print 2 > /dev/null

in csh :-
(find <dir> -name '<file>' -print >/dev/tty) >& /dev/null

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2010 - July 3, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


SHELL OUTPUT INTO VI

In VI editor you can get
the output of any shell
command command inserted
into the file you are
editing by using:

:r!<command>

For example:

:r!who -r

inserts the ouput of the
command "who -r" to the
file currently being
edited.

This can be effectively used
to copy the contents of a
file to the file currently
being edited

ie,

:r!cat /etc/passwd

inserts all the contents of
the the /etc/passwd to the
file currently being edited.

This tip supported by: Prem Kumar S <sprem@wipro.co.in>

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2011 - July 4, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


TAR ONLY THE FILES

To tar only files (not
subdirectories) in the
current directory use
this command:

$ tar cvf files.tar ./`ls -l | grep -v '^d' | awk '{ print $9 }'`

This tip generously supported by: rrs@assc.com.ve

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2012 - July 5, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


SOLARIS CHANGING SEASONS

During a session, sometimes
we have a need to change the
system time for our session
only. We have used it to
simulate time based testing.

export TZ=ESThhEDT

The EST set your time to Eastern
Standard Time and EDT is Eastern
Daylight Time.

hh is the number of hours you
wish to change.

Example: Currently the system
date is Tue Jun 19 13:38:03 EDT 2001

and you wish to set it to
yesterday at the same time.
You would substitute a positive
29 for hh.

export TZ=EST29EDT

Now the shell time is:
Mon Jun 18 13:38:50 EDT 2001

WHY 29 and not 24? The main
UNIX clock is set from GMT not
EST therefore you have to add
5 hours to your backward
calculations to get the same
exact time since EST is
GMT - 5 hours.

Use negitive numbers to set
the clock into the future.

Also if you need to set the
minutes and seconds it is
hh:mm:ss. These are all the
number of hours, minutes and
seconds from GMT that you wish
to set.

This is for Solaris 2.6, your
mileage may vary.

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2013 - July 6, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


REMOVE JUST THE FILES

To removal only the files
(not subdirectories) in
the current directory, use
the following command:

rm `ls -l | grep -v '^d' | awk '{ print $9 }'`


This tip generously supported by: rrs@assc.com.ve


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2014 - July 7, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


GETTING RID OF ^M

How to get rid of ^M
in text files .

tr -d '^M' <inputfile >outputfile

But how to get this
'^M' in the command
line:

Keep CTRL pressed
and then press v and m

This tip generously supported by: sojan@psidata.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2015 - July 8, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


VI LINE NUMBERS


Ever want line numbers
while editing a file:

:set number

We can see the line numbers...

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2016 - July 9, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


VI MAN PAGES

Try saving a man page to
a file for viewing with vi.

You will see a whole bunch
of control characters.

How can you save a man page
in a form readable by vi?

$ man ls | col -b > readable_file.txt


This tip generously supported by: kmehta@legato.com

 


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2017 - July 10, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


TEXT FILE CASE REVERSAL


Ever want to reverse the entire case
of a text file:

o reverse the case of a text file:
tr 'a-zA-Z' 'A-Za-z' < inputfile


This tip generously supported by: vikram.kalsi@seepz.tcs.co.in

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2018 - July 11, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


STRING STRIPPING

Remove all ^M and other control
characters from file ABC

strings ABC > ABC-good


This tip generously supported by:
brillj@constellation.navy.mil

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2019 - July 12, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


KEEPING PEOPLE OUT

If you want to keep people
of your server, but want them
to access their pop mail on
the same box set up the following
line in the password file:

babba:rtnRkIgCy4l4T:830:10:Babba Booie:/home/babba:/bin/nologin


Then create a script called
/bin/nologin that contains:

#! /bin/sh
echo "Sorry, but your account is only allowed POP access to this host."
exit 1

when a person attempts to log into
their defined shell it will run
the /bin/noling script, display
the message, and exit them from
the system

Have Fun

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2021 - July 14, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


To grab all hidden files

A safe way of grabbing all "hidden"
files is to use '.??*' rather than
'.*' since this will only match 3
or more characters. Admittedly,
this will miss any hidden files
that are only a single character
after the ., but it will always
miss '.' & '..', which is probably
more important...

We can use .[a-zA-Z0-9]* to grab
all hidden files other
than . and .. we will not get
hidden files which dont have any
alphanumeric character following
the first '.' - can someone tell
how to go about this


This tip generously supported by: muraliaj@synopsys.com

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2022 - July 15, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


PRINTING WITH NO SPACE

Sometimes there isn't enough space
in the spooling directory to print
a large file. This isn't the case
so much anymore since disk drives
are so large now.

If the file fills up the spooling
directory use and you are using
BSD "lpr" then you can pass it
the -s option.

This will create a symlink to the
file instead of coping it.

"lp" creates a symlink by default.
You can use the -c options to
force it to copy the file instead,
if needed.

Some flavors differ, check yours.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2023 - July 16, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


ONE STEP AT A TIME WITH !!

For example using C shell I want
to edit a handful of files that
contain the string "ProcessInput"
in my current directory.

Step 1:
Find the files which uses "ProcessInput"

% grep "ProcessInput" *.c
a.c:ProcessInput ( int a )
b.c:Description : ProcessInput is used to process the input
given by the user
b.c:Call ProcessInput to perform ...
c.c:val = ProcessInput(2) ;
c.c:val = ProcessInput(3) ;

Step 2:
Extract the filenames on the left.
$!! | awk -F: '{print $1}'
a.c
b.c
b.c
c.c
c.c

step 3:
Remove the duplicates
!! | sort -u

Step 4:
Now edit it !
vi `!!`

which runs vi `grep "ProcessInput" *.c | awk -F: '{print $1}'
| sort -u`


This tip generously supported by: desikann@future.futsoft.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2024 - July 17, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


BE A GURU - RTFM

The best way, is to learn
to be the best Unix Guru is
take the time to RTFM. Do
not always depend on someone
else to be there with the
knowledge.

DON'T BE LAZY!

By the Way, for those that
don't know by now.

RTFM = READ THE F^CKING MANUAL


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2025 - July 18, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


BOURNE SHELL PSEUDO HASH TABLES

The best way to explain this
is with an example:

You may want to write a simple
script that launches an xterm
window with different color
options. Pseudo hash tables in
bourne shell.

$ xwindow MidnightBlue

An easy way to this is by first
listing the supported colors in
the script (pseudo hash table):

DarkSlateGrey="#2f4f4f"
DimGrey="#696969"
MidnightBlue="#191970"
NavyBlue="#000080"

Next, simply grab the hex color
code by using the following
command:

BGColor=`eval echo $"$(echo $1)"`

"$(echo $1)" evaluates to "MidnightBlue" and
`eval echo $MidnightBlue evaluates to "#191970".

Simply launch the xterm window
using $BGColor as the background
color:

xterm -bg="$BGColor" &

This method for extracting pseudo hash
values may be used for NIS map files,
file date stamps, GUI colors, etc.


This tip generously supported by: Jasper.Silvis@PHL.Boeing.com


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2026 - July 19, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


Rename files script

If you want to rename files
in a directory then you can
use the following perl
script....

#!/usr/bin/perl
# rename: renames files according to the expr given on the command line.
# The expr will usually be a 's' or 'y' command, but can be any valid
# perl command if it makes sense. Takes a list of files to work on or
# defaults to '*' in the current directory.
# e.g.
# rename 's/\.flip$/.flop/' # rename *.flip to *.flop
# rename s/flip/flop/ # rename *flip* to *flop*
# rename 's/^s\.(.*)/$1.X/' # switch sccs filenames around
# rename 's/$/.orig/' */*.[ch] # add .orig to your source files in */
# rename 'y/A-Z/a-z/' # lowercase all filenames in .
# rename 'y/A-Z/a-z/ if -B' # same, but just binaries!
# rename chop *~ # restore all ~ backup files

use Getopt::Std;
my ($subst, $name);

if (!&getopts("nfq") || $#ARGV == -1) {
die "Usage: rename [-fnq] <perl expression> [file file...]
-f : Force the new filename even if it exists already
-n : Just print what would happen, but don't do the command
-q : Don't print the files as they are renamed
e.g. : rename 's/\.c/.c.old/' *
rename -q 'y/A-Z/a-z/' *\n";
}

$subst = shift; # Get perl command to work on
@ARGV = <*> if $#ARGV < 0; # Default to complete directory

foreach $name (@ARGV) {
$_ = $name;
eval "$subst;";
die $@ if $@;
next if -e $_ && !$opt_f; # Skip if the file exists if asked to.
mext if $_ eq $name;
if ($opt_n) {
print "mv $name $_\n";
next;
}
print "mv $name $_\n" if !$opt_q;
rename($name,$_) or warn "Can't rename $name to $_, $!\n";
}

Put the script called rename in /usr/local/bin. Make sure
/usr/local/bin is in your $PATH for convenience.


This tip generously supported by: dave.ruddle@siemens.co.uk



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2027 - July 20, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


INSERTING LINES WITHIN SCRIPTS


If you want to insert a line
at the top (or anywhere for
that matter) of a file within
a shell script, use the ed editor.

EXAMPLE:

string="hello"
ed << EOF
e any_file
1i
${string}

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2028 - July 21, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


REMOVING CORES CONDITIONALLY

To find and remove core files
conditionally:

PROMPT> find ~ -name core -exec file {} \; -exec rm -i {} \;

The File will show which
executable the core file is
for and the -i option to rm
will allow you to choose
weather to delete it or not.

################# EXAMPLE ###############################
PROMPT> find ~ -name core -exec file {} \; -exec rm -i {} \;
/my/home/core: ELF 32-bit LSB core file of 'netscape-commun'
(signal 3), Intel 8
rm: remove `/my/home/core'? y


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2029 - July 22, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


BELIEVE THE VENDOR?

Don't always feel that you should
believe the vendor.

Patches, vendor recommendations,
and out-sourced hardware support
engineers are some of the leading
causes of breaking a system. There
are times when you know your systems
better then they do.

If something doesn't feel right or
doesn't feel right , don't let them
do it. Ask a lot of questions and let
them know what your experience is.

Cover yourself first, run full
backups, ask them if the have ever
done the task before. Ask them to
confirm the procedure with a back
level support person.

Many times vendors will out-source
the hardware support to third party
companies. When this happens, you
may never get the same person twice,
nor know what experience he has on
your system.

If one of the first things a support
person does is ask where a phone is,
it is almost a guarantee that he will
lack the knowledge he should have and
will need to rely on someone else for
answer. While we all have much work
to do, DON'T LEAVE this type of person
alone with your systems.

Trust no one, it is you job and
reputation on the line.


-Kirk Waingrow

The tip is supported by: kirk@ugu.com

 


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2030 - July 23, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


EXTRACT RELATIVE FROM ABSOLUTE

Ever had a tar archive which
was tarred up with an absolute
path, but you need to untar
it to a relative location?

There is an easy way to do
this using the "pax" command.
Note: Not available on all
flavors.

Firstly, copy the archive to
the relative location in
which you wish to untar it.

Then, execute the following
command:

pax -r -s ',^/,,' -f file.tar

The contents of file.tar will now
be in the $CWD.


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2031 - July 24, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


TOO MANY FILES AROUND

In case there are too many
files in a particular
directory. When the
following is executed:

$grep "ABC" *

And it fails saying with

ksh: /usr/bin/find: 0403-027 The parameter list is too long.

what would you do?

Well you can do the following:

$ls |xargs grep "ABC"

-----
Puneet Agarwal
This tip generously supported by: puneeta@delhi.tcs.co.in

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2032 - July 25, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


EFFICIENT COMMANDS

I cringe anytime I see someone code
inefficiently. Here are three of the
most common mistakes, followed by a
better way to do the same thing.

Bad: cat somefile | grep something
Better: grep something somefile
Why: You're running one program (grep) instead of two (cat and grep).

Bad: ps -ef | grep something | grep -v grep
Better: ps -ef | grep [s]omething
Why: You're running two commands (grep) instead of three (ps
and two greps).

Bad: cat /dev/null > somefile
Better: > somefile
Why: You're running a command (cat) with I/O redirection,
instead of just redirection.

Although the bad way will have the
same result, the good way is far
faster. This may seem trivial, but
the benefits will really show when
dealing with large files or loops.

Regards.

This tip generously supported by: sec@nbnet.nb.ca

 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2033 - July 26, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


CONVERT TEXT2HTML

Ever felt the need to convert a
text file to html?

Create a file named txt2html
with the following contents

# Always start the output with
#an html header

BEGIN {print "<html>"
print "<head>"

# use the name of the inputfile
# as title

print "<title>" FILENAME "</title>"
print "</head>"

# The text is formatted
# already, so use <pre>

print "<body><pre>"}

# lines consisting of a number
# of dashes (more than 1) are
# replaced by a <hr>

/^---*$/ {print "<hr align=\"left\" width=" length "0 size=1>"; next}

# lines consisting of a number of equalsigns are replaced
# by a thick <hr>

/^===*$/ {print "<hr align=\"left\" width=" length "0 size=3>"; next}

# less than and greater than
# sign must me replaced by tags.

{gsub("<","\&lt;")
gsub(">","\&gt;")

# Replace form feeds by a
# couple of empty lines

gsub("^L","<br>\&nbsp;<br>\&nbsp;<br>\&nbsp;<br>")
print}

# At the end of the output,
# we must add some closing tags.

END {print "</pre></body>"}

Make this executable
(chmod a+x txt2html) and you're
ready to start converting your test files.

txt2html something.txt > something.html


This tip generously supported by: ugu@couprie.org

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2034 - July 27, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


CSH PROMPT SETTING

In (t)csh, here is a better way to
set your prompt to always let you
know where on the system you are.
In your .cshrc file, add
or set the following line:

set prompt = "%m%/% "

This way, whenever you press return,
or a job finishes, the prompt will
always tell you where you are,
without having to change directories
first. Of extra usefulness, the '%m%'
token expands to the machine name.
If you work on a multimachine system,
knowing which machine you're on is
usually of more immediate importance
than where on the machine you are.


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2036 - July 29, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


CONVERTING UNIX MAN PAGES

(Another approach)

To convert Unix Man pages
to text format, you can make
use of one feature of 'man'
itself.

(Check out man man)

Set environment variable PAGER
to 'cat'. Then run

% man command_name > command_name.txt

eg. in csh, to see man ls in
a text file

% setenv PAGER cat
% man ls > ls.txt

NOTE: Do not forget to unsetenv
PAGER, else you will have to
pipe every man command to
'more' or (my favourite) 'less'.


This tip generously supported by: amar_san@yahoo.com


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2037 - July 30, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


APPENDING TEXT AT BOTH ENDS

If you need to append some
text to both the ends of a
string in vi, use the
following command in vi:

:/^\(.*\)/s//starttextcomeshere \1 endtextcomeshere/

If "iamworthless" is the text
at the position of the cursor
in the vi editor, the output
of the command:

:/^\(.*\)/s//DONTFEEL \1 ANYTIME/


DONTFEEL iamworthless ANYTIME

As you guessed, "DONTFEEL " and
" ANYTIME" are the strings you
would like to crush
"iamworthless" with. The "\1" is
the variable that stores the
entire pattern searched by
the "/\(.*\)/"

This tip generously supported by: hg_krishnan@yahoo.com


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 2038 - July 31, 2002

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


ANOTHER UPPER TO LOWER

Changing file Names From
UPPER TO LOWER case and
vice versa

This script can be used
to convert the file names
from upper case to lower
case and vice versa.

####################
typeset -u Lcase
for Ucase in `ls`
do
Lcase=$Ucase
mv $Ucase $Lcase
done
######################

And to convert from lower
case to upper case, just
change (typeset -u ) to
be ( typeset -l ).


This tip generously supported by: yousif_morckos@yahoo.com





Click here to send an email to the editor of this weblog.
© Copyright 2002 Raj Patel.
Last update: 8/1/02; 12:07:50 pm.


Archives Pictures Information Links News Home