Collection of Unix Guru Universe Tips
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2100 - October 1, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
EDIT A LOST FILE
Forget where you put your files?
Rather than specifying an absolute pathname,
use command substitution instead.
Instead of:
% vi /usr/local/bin/foo
Try:
% vi `which foo`
NOTE: files must be in your path for "which" to find
them.
This tip generously supported by: thockin@ais.net
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2101 - October 2, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
EXTRACT CORRUPTED TAR FILE
In many case if there is a corrupted tar file,
the following command can be used in an attempt
to extract the file:
% cat [tar-filename] | tar -xvf -
NOTE: Where "-" is the STDOUT
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2102 - October 3, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
MORE AND VI OR MORE VI
To edit a file after looking at it with "more"
Press the letter "v" key and you will be placed
in a vi session.
Quitting the vi session will bring you back
to viewing the file with the "more" command
This will not work with piping a file to "more".
This works:
$ more /etc/hosts
This does not:
$ cat /etc/hosts | more
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2103 - October 4, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
CRYPT AN ASCII FILE
An ascii file can be easily encrypted and
decrypted.
To encrypt simply pipe the STDOUT of
the file to "crypt" and redirect it to
a new file name. Enter a passowrd when
prompted with "Enter key".
$ cat foo | crypt > foo.e
Enter key:
To unencrypt simply pipe the STDOUT of
the encrypted file to "crpyt" and
redirect it to a new file name. Enter
a passowrd when prompted with
"Enter key".
$ cat foo.e | crypt > foo.new
Enter key:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2104 - October 5, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
REWIND A TAPE FAST
What's the fastest way to rewind a tape without
using "mt" or other tape software?
From a bourne or korn shell, Just type:
$ < /dev/[tapedevice]
$ < /dev/rst8
and watch it rewind...
This tip generously supported by: ulli@ucrc.org
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2105 - October 6, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
MULTIPLE SYSTEM FILE UPDATES
This Tip will show one of the ways to update
multiple systems with one script unattended:
There are a variety of ways to accomplish this,
but this one requires NO update to the remote
systems except for the files you wish to update
(i.e. - no update to .rhosts or hosts.equiv
type files). I use an ftp macro as follows:
------------------------------- CUT HERE ---------------------------
#!/bin/ksh
#
# program: update-all-workstations
# purpose: To ensure that all workstations have the same update
of
# specific programs.
#
# notes: We run a ping command also to see if host is alive
# before we try to do the updates.
#
hosts=`ypcat hosts | grep col[d-f] | awk '{print $2}'`
for host in $hosts
do
alive=`ping -v $host 1 | awk '{print $3}'`
if [ $alive = "alive" ];
then
echo $host >> live-hosts
else
echo $host >> dead-hosts
fi
done
# This next sequence is totally unneeded if all workstations have
a .rhosts
# file that allows the server (or system running this script) root
access.
# If .rhosts is used, eliminate the prompting for the password and
the
# building of the .netrc file.
#
# This next line assumes that ALL workstations have the same password
# If this is not the case, then administration becomes somewhat
more
# cumbersome. Move the following 2 lines down to below the next
do
statement
# if the password differs from workstation to workstation.
echo "Please enter the root password for the workstations:\c"
read password
for host in `cat live-hosts`
do
echo "machine $host login root password $password" >
$HOME/.netrc
chmod 600 $HOME/.netrc
echo "macdef init" >> $HOME/.netrc
echo "prompt" >> $HOME/.netrc
echo "binary" >> $HOME/.netrc
echo "put /tmp/myfiles.tar /tmp/myfiles.tar" >>
$HOME/.netrc
echo "close" >> $HOME/.netrc
echo "quit" >> $HOME/.netrc
echo "\n\n" >> $HOME/.netrc
# these next few steps may seem redundant, but they are necessary.
# if you are using a .netrc file, it must be whacked after the ftp
and
# before the rexec command
rm $HOME/.netrc
echo "machine $host login root password $password" >
$HOME/.netrc
chmod 600 $HOME/.netrc
rexec $host "cd /usr/local; tar xvf /tmp/myfiles.tar"
done
# End of this script
#################################################################
Now, if you are using .rhosts files, the whole process becomes
much
simpler.
Lets examine a script would look like if we are using .rhosts files
on
each
workstation to allow the server or UNIX admin workstation to have
root
access.
---------------------------- CUT HERE -----------------------------
#!/bin/ksh
#
# program: update-using-rhosts
# purpose: To ensure that all workstations have the same update
of
# specific programs.
#
# notes: We run a ping command also to see if host is alive
# before we try to do the updates.
#
hosts=`ypcat hosts | grep col[d-f] | awk '{print $2}'`
for host in $hosts
do
alive=`ping -v $host 1 | awk '{print $3}'`
if [ $alive = "alive" ];
then
echo $host >> live-hosts
else
echo $host >> dead-hosts
fi
done
for host in `cat live-hosts`
do
# first we do a tar archive to standard out, then pipe to rsh to
the
# host, make # sure we are in the root directory, then tar extract
from
# standard in
tar cvf - ./usr/local/bin | rsh $host "cd /; tar xvf -"
done
# End of this script
Obviously the second method is easier, but obviously it depends
on your
site characteristics on which you would use.
If you need assistance with these types of scripts, I will assist
you,
but keep in mind, I accept no responsibility for anything that
happens to you or your site due to the use of these scripts.
Only an experienced admin should attempt to use these scripts, and
you should always have the appropriate safety precautions in
place.
James A. (Jamie) Dennis jdennis@netset.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2106 - October 7, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
CLEANUP DOS FILES
If you deal with DOS files and the "^M" character
always appears at the end of the line, here are
two ways to get rid of them.
If you edit the DOS text file with the "vi"
editor in UNIX, use the following from the
"vi" command line:
:%s/^V^M//g
From a Unix shell use the command:
% sed 's/^V^M//g' foo > foo.new
NOTE: ^V is control V and ^M is control M or Enter
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2107 - October 8, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
SUSPEND YOURSELF
Do you hate always having to type: /bin/su root
Do you wish you only had to do it once?
Well, here is a way to "suspend" root and bring it back.
Use the "suspend" and "fg" commands to switch
from root to login ID, and back to root:
foo 15% /bin/su
Password:
foo 1#
foo 2# suspend
stopped
foo 16% fg
/bin/su
foo 3#
And that's it.....
Set and alias in root's .cshrc or .profile to shorten
the word "suspend" if that is too much to type.
alias sus 'suspend'
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2109 - October 10, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
SPLIT FILES FOR FLOPPIES
To split a file up for floppies:
# split -b 1400000
The filenames will be xaa, xbb, etc.
To restore them:
# cat x* > original_filename
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2110 - October 11, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
NULL IT FAST
Here is the fastest way to truncate a file to zero
bytes in a bourne or korn shell.
$ > /var/log/messages
This is a good method, if the file has to be truncated,
but is opened by another process. For example, if you
want to truncate /var/log/messages, which is held
open by syslogd...
This tip generously supported by: ulli@ucrc.org
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2111 - October 12, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
HOW TO KILL YOUSELF FAST!
Here is a Tip on how to kill yourself fast.
% kill -9 -1
This could also be used to kill another user:
# su - johndoe -c 'kill -9 -1'
NOTE: UGU does not recommend Admins
going on a killing spree, but only when it is
necessary.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2112 - October 13, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
GENERATE RANGES OF NUMBERS
Sometimes it is necessary to generate a range of
numbers for further use within a command pipe or
shell script. This can be done with some simple
sh-code:
------------------------ CUT HERE ------------------
#! /bin/sh
# range - Generate of numbers.
lo=$1
hi=$2
while [ $lo -le $hi ]
do
echo -n $lo " "
lo=`expr $lo + 1`
done
------------------------ CUT HERE ------------------
It can now be used a way like:
for i in `range 69 4711`; do <some code>; done
This tip generously supported by: ulli@ucrc.org
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2113 - October 14, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
A REFRESHING X
If your X display gets messed up somehow,
run a program called "xrefresh" in your
X11R6 bin directory, it will clean up
the display so you don't need to kill X.
This tip generously supported by: kev@zebradale.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2114 - October 15, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
QUICK UNALIAS
If you have aliased a command to somehting and want to quickly
unalias it, preceed the name with a backslash, '\', and it
will have the original meaning. For example, if you have 'rm'
aliased to 'rm -i' and want to remove one entire directory without
being prompted for each file, you would do:
$ \rm -fr dirname
where 'dirname' is the directory you want to trash.
This tip generously supported by: khamsi@kmrmail.kmr.ll.mit.edu
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2115 - October 16, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
BACKUP CRITICAL SYSTEM FILES
Before modifying critical system files, make a backup copy
using the date as an extension:
$ cp /etc/hosts /etc/hosts.971006
If you keep a number of these they provide a potentially
valuable archive as well as a means of finding out any
changes that have been made and when.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2116 - October 17, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ABBREVIATE IN VI
Using .exrc file
Abbreviate in vi...
As well as using map in your .exrc file, you can use the command:
ab
For example:
ab xmas Christmas
So whenever you type xmas - Christmas will be displayed.
Handy for writing the /etc/motd file (maint - maintenance etc).
You can also use the standard set commands - for example:
set number (handy for programmers)
set redraw
set warn (flashes screen instead of using the bell)
This tip generously supported by: mbatchelor@enterprise.net
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2117 - October 18, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
MULTI-SYSADMIN MONITORING
To can see what someone logged in as root is running,
if root's shell uses .sh_history ( ksh, for example ) do:
# tail -f /.sh_history
This is good in multi-Sysadm environments when you want to
get an idea of what another admin is doing to fix something.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2118 - October 19, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
SET REMOTE DISPLAY QUICKLY
If the environment and home directory structure
are centralized, then build a set of alias tables
for setting the display for all remote machines
that may get logged into remotely or administrate
remotely. In the long run it will save time.
alias 'setwad setenv DISPLAY wad:0'
alias 'setspot setenv DISPLAY spot:0'
alias 'settrash setenv DISPLAY trash:0'
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2119 - October 20, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
SHARING STDIN/STDOUT ON 2 TERMINALS
Ever wanted the standard input and standard output
to be shared on two terminals?
Try the following short script,
------------------- CUT HERE -------------------------
[ $# -lt 2 ] && echo "Usage: $0 program ttytodupon"
&& exit 2
mytty=`tty`
prog=$1
othertty=$2
sh -c "$prog|tee -a $mytty" 1>$othertty 2>&1
0>$othertty
------------------- CUT HERE -------------------------
This tip generously supported by: ian@kiwiplan.co.nz
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2120 - October 21, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
SEPARATE SHELL COMMAND HISTORY FILES
In any X based desktop when the number of pseudo terminal
windows are more then one, the common shell history
file (KSH) becomes a nuisance. Here is a way to have
separate, safe and limited shell command history files.
Put the following code in your shell RC file.
--------------------------------CODE
START------------------------------------
# Form a unique name for the shell history file using the tty output
and
# set the shell variable HISTFILE to point to that
# This solves the problem of mutiple shells using the same history
file
# and causing the confusion....
histf=`tty | awk 'BEGIN {FS="/"; nm=".shist_"}
{ for (i=1; i<=NF; i++) nm
= nm
$i;} END { print nm;} '`
export HISTFILE=$histf
\rm -f $histf
echo History file is $histf...
--------------------------------CODE
END------------------------------------
This tip generously supported by: atulk@informix.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2121 - October 22, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-------- REMOVE THE DASHES
Have you ever accidentally created a file beginning with '-'?
It happens often by mistake and from the first look it seems
like you can't delete the file (rm thinks the initial - is an
option, and doesn't recognize the file).
The simple, quick way around this is the -- option to rm.
Say you had the file ---hey in the current directory:
$ ls ---hey
/bin/ls: unrecognized option `---hey'
Try `/bin/ls --help' for more information.
$ ls|grep hey
---hey
$ rm ---hey
rm: unrecognized option `---hey'
Try `rm --help' for more information.
$ rm -- ---hey
( ls also has an -- option: )
$ ls -- ---hey
/bin/ls: ---hey: No such file or directory
$
This tip generously supported by: root@analog.org
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2122 - October 23, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ALTERNATIVE TO CP
Define the following alias:
tar cvf - . | ( cd \!* ; tar xvf - )
or as an alias:
alias cpbytar 'tar cvf - . | ( cd \!* ; tar xvf - )'
(The alias definition above is for CSH)
To do a recursive copy of a directory to another location,
preserving the PERMISSIONS and OWNERSHIP of the files.
"cd" to the source location and invoke the following alias
cpbytar <destination_directory>
This tip generously supported by: bhavin@informix.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2123 - October 24, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
KILL X
Quick way to close your X login session (for SysV)
for PID in `ps -u$USER | grep "fv[wm]" | awk '{print
$1}'`; do kill -9
$PID; done
Or throw it into a shell script:
--- cut here ---
#!/bin/sh
for PID in `ps -u$USER | grep "fv[wm]" | awk '{print
$1}'`; do
kill -9 -$PID
done
--- cut here ---
(the [] conceal the grep from ps, which would mean it would
kill itself before doing anything useful. as written up,
it looks for fvwm's process, which is the window manager I
use; rewrite it as needed i.e. for Motif - mwm,
Open Look - olwm, etc.)
Write this up in a shell script contained in your $PATH
or alias it and you're cooking with gas.
This tip generously supported by: klaus@imprint.uwaterloo.ca
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2124 - October 25, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
CREATE YOUR OWN GROUP ALIASES
If you want to create an alias for a group of people with
similar interests, on your workstation (Say a SUN
workstation), then include the following line at the end
of the file /etc/aliases and run the command /bin/newaliases
unixtips: bhavin@foobar.com, atulk@foobar.com, virajpikle@mail.com
Now, an e-mail sent to
alias_name@workstation_name.foobar.com
will be bounced to the addresses listed above in the
/etc/aliases file.
In other words, if my workstation name is "soorya",
an e-mail sent to
unixtips@soorya.foobar.com
will be bounced to
bhavin@foobar.com,
atulk@foobar.com, and
virajpikle@mail.com
This tip generously supported by: bhavin@informix.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2125 - October 26, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
MONITORING ROOT IN THE PASSWORD FILE
One of the popularly known method of breaking into a Unix host
is by inserting a uid value 0 in the /etc/passwd file which could
be done in many ways including backdoors for later accesses .
The script below displays warning messages on the console if
such changes a detacted. Simply place the script in the crontab
and run as frequent as you wish.
------------------------------CUT
HERE-----------------------------------------
for id in `awk 'FS=":" {if(($3 == 0 && $1 !=
"root" )) print $1}'
/etc/passwd`
do
cat << the_end >/dev/console
+----------------------------------------------------------------
|
| `date "+Detacted On Date :%D Time :%r"`
| Break-in ALERT! Login ID `echo ${id}` has uid 0
|
+----------------------------------------------------------------
the_end
done
------------------------------CUT
HERE-----------------------------------------
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2126 - October 27, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
AWK QUICK COLUMNS
Most of the time when you use awk from the command line,
you're doing something simple like this:
ps -ef | grep netscape | awk '{print $2}'
To save typing, use this script when you only want to
use awk to print out one or more columns:
------------------- CUT HERE ---------------------------
#!/bin/ksh
# awkc - print out one or more columns
p=\$$( echo $1 | sed 's/,/,\$/g' )
shift
eval "awk '{ print $p }'" $*
# eof
------------------- CUT HERE ---------------------------
Now you can do things like:
ps -ef | awkc 2,1
or
awkc 1,2,3 /var/adm/messages*
This tip generously supported by: kbeer@dbna.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2127 - October 28, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
SPEED UP INTERACTION TIME
One way to speed up the interaction time of
a shell (that does not hash its commands)
that you may overlook is to modify your path.
The order of the directories in your path
should rely on the number of commands you use
most. So /usr/bin or /bin would probably be first.
Very large directorys that are mounted over
the network should be later in the list. If
there are some directories in your path you only
use for one or two commands consider making an
alias or shell script (if your shell doesn't
support aliases) which calls the program with its
full path name.
Watch out when sourcing files, especially when
your root. It could modify your path and make
you run something detrimental to your system.
Getting into the habit of using full pathnames
is the key here.
This tip generously supported by: kevin@ti.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2129 - October 30, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Public Relations
One of the best things an admin can do
is to have good public relations with
the user community.
Don't just be there when problems arise.
Go out to the user community when things are
working. High visibility is the key.
If the users see you around and there are no
problems they will believe that you care to
take the time for them.
Try not to let the users always go come to you.
Go to those users that you never here from
The perfect users, the ones that leave you
alone. Often the don't have an understanding
of what you can do for them.
I know many will say, "I don't have time!"
Just a calm walk through a department is
really all it takes, sometimes you never
have to stop.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2130 - October 31, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
REGEXP MATCHING IN AWK
If you ever find yourself typing "command | grep pattern |
awk '{print $3}'
you can shorten this by using the regexp matching in awk, like this:
command | awk '/pattern/{print $3}'
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2131 - November 1, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
NFS HANG FIX ON HP-UX
In an NFS environment (Hp-UX based), sometimes no user is
able to log-in when home directories are mounted using automounter).
As user validation occurs, the user .profile is executed but no
shell
prompt appears unless the user presses CTRL-C.
The Solution to this is to kill the portmap & inetd and restart
the two daemons. The problem will then be sorted out.
This tip generously supported by: sgogia@hss.hns.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2132 - November 2, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
KILLING ALL USER PROCESSES
The common method for killing all of a users processes
usually involves grepping the users name from 'ps', then
using awk to get the process id's and submitting them
to 'kill -9'.
Sys V
ex: kill -9 $(ps -fuusername | awk '{ print $2 }' )
BSDish
ex: kill -9 $(ps -aux |grep username | awk '{ print $2 }' )
The problems with doing this way are that it is slow, and
more importantly, it doesn't always kill all of the processes
on the first try.
There is a way to do this that always kills all of the users
processes the first time, and is very fast:
su - username -c 'kill -9 -1'
This tip generously supported by: jkstill@teleport.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2133 - November 3, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
GLOBAL SYSTEM PATH SETTINGS
Cross-Platform System Administration Tip
If you want to set a system path that will apply to all users,
regardless of which shell they use, edit the following file:
For Solaris: /etc/default/login
For HP-UX: /etc/PATH
For AIX: /etc/environment
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2134 - November 4, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
I SEE YOU WITH FUSER
In System V, you can use the following command to see who is accessing
a particular file system:
fuser <file system>
For example, to see who is accessing the /cdrom directory:
fuser /cdrom
This command is useful if you wish to unmount a file system but
the system
is unable to do so because it is being used.
This tip generously supported by: anthony-leong@usa.net
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2135 - November 5, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
SHELL SCRIPTING A SQLPLUS SCRIPT
Here is a tip on how to run sqlplus scripts within a shell script.
It is an example of how to pass database values into shell variables
and to make shell scripts more dynamic. This maybe elementary to
some
folks but hope it helps others.....Here is the syntax:
#!/bin/sh
dummyvar=`sqlplus -s username/password <<end
set pagesize 0 feedback off ver off heading off echo off
select sysdate from dual;
exit;
end`
echo "system date is " $dummyvar
#end of shell script
This will retrieve the system date from Oracle but you get the
idea
that you can expand the select script to get whatever you want from
the database and place it in a shell variable where you can make
decisions on it.
This tip generously supported by: riosm@abcbs.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2136 - November 6, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PERFORMANCE OF CROND TASKS
A good tip for getting better performance in crond tasks
is choosing a better time for launching them.
If the process that we want to launch needs few time,
but can overload the system easily, you can launch
the task in hours that the work is busy and -and HERE
is the tip- in strange minutes. That's why lots of
people launch their crons at midnight, but
nobody uses to do it at 00:13, in example.
That tip can obtain his best in hourly-launched
tasks. If that kind of tasks are launched all at
the same time, the system will overload without
any use. You can delay that kind of tasks (one
at 13th minute, other at 17th minute,other at
27th minute...) and obtain better performance
without work. That will avoid overloading caused
by launching several tasks at the same time.
The best is that administration tasks do
not overlap, but this is not always possible.
If you can do it, it's better you do it.
Using nice is also a good idea.
But the best is making a log of the uptime during
a week. You can be surprise, because all the staff
of a department of a firm use to do the coffee-break
at the same time; it's the perfect time for making
some administrative tasks. :-)
But do not clear the forbidden extensions -the famous
find /home -name core -exec \{\} \; and other stuff
like tmps, ~s and so on- of the system
at work time, or you will have a queue of staff people
very, very angry knocking at your door.
This tip generously supported by: irbis@activanet.es
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2137 - November 7, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
TCSH AND RMSTAR
tcsh has a nice built in variable:
set rmstar
Whenever you type the command:
% rm *
The shell will ask you to confirm, this prevents you from deleting
all your files accidentally.
Add "set rmstar" in you .cshrc file for your own benefit.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2138 - November 8, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
HIDE THOSE FILES
If you want to have some hidden directories on your server (warez
etc.)
then make a directory with permission 111.
% chmod 111 foo/
All the contents will become hidden:
% cd foo
% ls -al
Cannot access directory .: Permission denied
The directory will have to opened back up (755) in order to see
or access
the files or the directory. To remove the directory and its contents,
it
will also need to have the permissions opened.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2139 - November 9, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
CTRL-D ANOTHER USE
Many Unix Admins use the C shell as their interactive shell.
An often used feature of Csh is file completion - initiated
with 'set filec'. It allows the Csh user to type in partial
file names, and then press escape to get them completed where
possible. A little known side effect of this is that
Control-D (^D) will now generate file listings in the middle of
command lines.
Example 1: (where @ is a space)
host > @^D
Lists the current directory
Example 2:
host >ln -s /usr/^D
Lists the /usr directory
host >tar cvf /dev/nrtape /usr/m^D
Lists all m* files in the /usr directory
In each case, after the listing, you get a new command line and
are
placed at the last point of edit.
Very handy if you you know what you wanted to do but forgot what
you
wanted to do it with!
This tip generously supported by: mikal.dunn@halliburton.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2140 - November 10, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Suppose we want to check whether the web server is running or
not, but we don't have any browsers ( lynx, IE, Netscape ...),
then there is a simple way of doing that. Just telnet to that
machine on the http port ( port no 80 in general).
% telnet <ip addr> <port no>
And then, say "get /" (without quotes). If the webserver
is running,
it displays the HTML script of the homepage or basic info and closes
the
connection to the remote host.
% telnet yahoo.com 80
Trying 204.71.200.245...
Connected to yahoo.com.
Escape character is '^]'.
get /
HTTP/1.0 302 RD
Location: http://www.yahoo.com/
Connection closed by foreign host.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2141 - November 11, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
REPETITIVE TASKS WITH XARGS
Save yourself a lot of typing when you have to perform repetitive
commands on a list of files. Put the list of files in a text file
with one file per line ie: find . -name version.C > filename
Then have xargs build a command line for each file in the list as
follows:
cat filename |xargs -n 1 cp anotherfile
This will copy anotherfile over all the files listed in
filename one at a time until the end of filename is reached.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2143 - November 13, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PING THE HOST TABLE
Here is a quick way to ping all the hosts in your host table.
NOTE: Just make sure that there are no blank lines in it, and
verify the ping command on your system exist after one ping. Your
mileage may differ slightly.
$ grep -v "#" /etc/hosts | awk '{print $1}' | while read
host
> do
> ping -c 1 $host
> done
Or script it:
#!/bin/sh
grep -v "#" /etc/hosts | awk '{print $1}' | while read
host
do
ping -c 1 $host
done
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2144 - November 14, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
POWER OF BACKQUOTES
Backquotes are the most powerful things in Unix. More than one
Unix commands can be run simultaneously on the prompt.
In csh,
% find . -name "*.txt" -print
gives the path & names of the files with extension ".txt"
in
current directory and its subdirectories. If you want to open
these files in vi together then
% vi `find . -name "*.txt" -print`
Similarly,
% find . -name "*.txt" -print
<listing of all txt files. in current directory/sub-dirs>
% vi `!!`
this will open all those files in vi listed by find command.
This tip generously supported by: dhruvm@duettech.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2145 - November 15, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
FORGET THE CRONTAB MAN
For some reason many admins forget the field order of the
crontab file and alway reference the man pages over-and-over.
Make your life easy. Just put the field definitions in
your crontab file and comment (#) the lines out so the
crontab file ignores it.
#minute (0-59),
#| hour (0-23),
#| | day of the month (1-31),
#| | | month of the year (1-12),
#| | | | day of the week (0-6 with 0=Sunday).
#| | | | | commands
0 2 * * 0,4 /etc/cron.d/logchecker
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2146 - November 16, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
FULL OF FILESYSTEM INODES
We recently had a problem where a file system had 100% inode usage.
Unfortunately there isn't an easy way to search for directories
with
a lot of files in them (1 file = 1 inode). And if the files are
small,
you can't rely on du to help you out.
Here is a find command that will print all the directories in the
current filesystem, with the number of files (inodes) in that directory.
find . -xdev -type d -exec /bin/echo -n {} \; -exec sh -c "ls
{} | wc -l"
\;
This tip generously supported by: rickb@cmhcsys.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2147 - November 17, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
EXTRACT THAT LAST FIELD
You can use 'cut' to extract the last field of a line if you know
how many fields there are, eg:
field=`cut -d: -f8 file`
But if you don't know the maximum number of fields or the number
of fields per line are not consistent, awk can come to the rescue.
awk has the inbuilt variable NF for the number of fields. By using
this variable we can use it to extract the last field by using:
field=`awk -F: '{print $NF}'`
or you can use calculations to retrieve any field relative to the
last
field.
For example to retrieve the second last field, use:
field=`awk -F: '{print $(NF-1)}'`
This tip generously supported by: peters@ginini.com.au
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2149 - November 19, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
FINDING A STRING
How to find a string somewhere on the system. Many times we are
called to search for a string, but we have no idea where it may
be lurking. Judicious use of the find and grep commands will
make you a hero with your co-workers.
# find . -type f -exec grep "string or options" /dev/null
{} \;
Normally using only:
# find . -type f -exec grep "string/options" {} \;
Produces the target string, but you will have no clue as to where
it is located, making this almost as frustrating as using windoze!
Remember when grep'ing against multiple files the filename will
be
listed before the match.
$ grep there *
foo:I found the target here
bar:You are there
In our find command we use /dev/null as a file to search against,
since
we know the search will always fail if the string is found in "{}"
there
filename is printed. To borrow from a famous quote:
"Pretty tricky sis!"
This tip generously supported by: james_b_horwath@glic.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2150 - November 20, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
GET THE 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...
This tip generously supported by: leopard@midwinter.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2151 - November 21, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
GREP TEXT NOT BINARY
In some directories such as /etc you have a mix of file types.
You may want to grep out a string from one of the files but
don't want to worry about the binaries, data, etc. To accomplish
this, searching only text files do this:
grep <string> `file * | egrep 'script|text' | awk -F: '{print
$1}'`
This tip generously supported by: Richard.place-eds@eds.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2152 - November 22, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
WHERE ARE THOSE PARENTHESES?
Do you ever lose your way in multiple levels of parentheses
or braces? If you program in Perl or C, you know what I
mean. Let the vi "%" command help you. Move the cursor
to
a parenthesis or brace and type %. vi will move the
cursor to the corresponding character. Hit % again and vi
will return to the original parenthesis or brace.
For extra power, issue "/{" to find the first open brace.
Hit "%" twice to find the corresponding brace and return.
Hit "n" to find the next open brace. This allows you to
zip through the file checking your program structure.
It makes you feel sorry for Windows-based editors!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2153 - November 23, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
CARROTS ARE GOOD FOR YOU
Most often when we try to execute a command at the shell we do
some mistakes like missing out a char or misspelling it.
Here is a easy way of correcting the mistake without having
to type the entire command again!.
In the below command "name" has been misspelled as "naem"
$ find . -naem "*.txt" -print
find: invalid predicate `-naem'
The above command would be valid if we replace "em" (in
naem)
to "me"( to have name ). Use carrots to make this change
$ ^em^me^
find . -name "*.txt" -print
This technique works well with bash and csh.
This tip generously supported by: desikann@future.futsoft.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2154 - November 24, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
FIND AND EDIT IN ONE
Have You Ever found a need to find a file for a particular pattern
and then
edit the same ??
Here is an easiest way....
At the UNIX prompt,
Just type:
vi `find . -name "*" -exec grep -l "pattern"
{} \; -print`
Where "pattern" is the string to be searched.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2155 - November 25, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
VERIFY AFTER VACATIONS
Be sure to check all vital systems and
processes once returning froma vacation.
Don't ignore your log files or backup
reports. You may have alot of email
from automated jobs. READ ALL OF THEM!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2156 - November 26, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
VERIFY AFTER VACATIONS
Be sure to check all vital systems and
processes once returning froma vacation.
Don't ignore your log files or backup
reports. You may have alot of email
from automated jobs. READ ALL OF THEM!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2157 - November 27, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
TRUSS THE PID.....
To check the system calls and signals
coming into and going out of a
process use /usr/bin/truss.
i.e. truss pid
This tip generously supported by: bareddy_sm@yahoo.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2158 - November 28, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
LEAKING MEMORY?
Do you want to know the list
of memory leak detecting tools:
http://www.cs.colorado.edu/homes/zorn/public_html/MallocDebug.html
This tip generously supported by: M.Nithyanandham@blr.spcnl.co.in
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2159 - November 29, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
EDITING OF LARGE FILES
Ever failed to open a very large
file for editing in vi. Just try
this tip:
Suppose you want to make changes
in top 500 lines of a 100 line file
abc.txt.
tail +500 abc.txt > tail.txt
head -500 abc.txt > head.txt
Edit file head.txt by opening in
a vi editor.
Now append file tail.txt to
head.txt by:
cat tail.txt >> head.txt
mv head.txt > abc.txt
rm head.txt tail.txt
This tip generously supported by: akash@cadence.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2160 - November 30, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
HOW MUCH SOLARIS MEMORY?
To determine the amount of main memory on Solaris:
1) /usr/platform/sun4u/sbin/prtdiag
2) wsinfo
3) '/usr/sbin/prtconf | grep -i memory'
This tip generously supported by: M.Nithyanandham@blr.spcnl.co.in
|