February 11th, 2005
My colleague John Page this morning introduced me to the pgrep and pkill commands, as a useful replacement for grepping the output of ps.
I'd never heard of either command (probably because they're not in my copy of UNIX Complete - probably because it's from 1999).
Using pkill allows me to replace the following, from a shell script that stops or starts a program called lmgrd:
kill `ps -ef | grep "lmgrd -c" | grep -v grep | awk '{print $2}'`
with this:
pkill lmgrd
Check out the man page for pgrep and pkill (or read it online at http://linux.about.com/library/cmd/blcmdl1_pgrep.htm)
Potentially similar posts
February 2nd, 2005
To add a path to your PATH variable edit your shell initialization file(s) as follows.
C shell (csh)
To add your home directory (~) to your PATH, add the following to the .cshrc file in your home directory:
set path = ($path ~)
Bourne shell (bash)
To add your home directory (~) to your PATH, add the following to the .bashrc file in your home directory:
PATH="$PATH:~"; export PATH
Read the rest of this entry »
Potentially similar posts
January 13th, 2005
Provided you can log on as root, you can search the passwd file to find out whether a user account with a particular name already exists.
For example, to check whether there's a user called alistair, run the following command:
cat /etc/passwd | grep "^alistair"
Note: This will also find users called "alistair1", "alistair2" etc. If you grep for just "alistair", you will find users like "thisalistair" and thatalistair".
Search the group file in the same way to check for existing groups. For example:
cat /etc/group | grep "^adminusers"
Potentially similar posts
January 4th, 2005
My brain is very efficient at freeing up space by deleting old data that hasn't been accessed for a while - i.e. if I don't use it I forget it.
A case in point is how to find out how much space you have left on a Linux machine.
The answer, of course, is to use the df command. For example:
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda3 73G 3.0G 66G 5% /
/dev/hda1 244M 8.7M 222M 4% /boot
none 157M 0 157M 0% /dev/shm
/dev/hdb1 7.8G 183M 7.2G 3% /home
The -h flag here outputs the results in human-readable format - i.e. it appends M for megabytes and G for gigabytes, rather than printing everything in kilobytes.
Read the rest of this entry »
Potentially similar posts
December 6th, 2004
This command will show a list of people who have edited a file:
cvs log <filename> | grep author | awk '{print $5}' | sort -u
Replace <filename> with a real value.
Thanks to Sandy Dunlop for this tip.
Potentially similar posts