Thursday, April 16, 2009

Begginner's Shell Notes

I wrote this forever ago and some of it is totally wrong. Don't read this or you'll get MORE STUPIDER

The following table contains a quick reference for commonly used shell commands. You should Also See Advanced Shell Commands for other helpful topics.

Desired Effect Command
Beep echo $'\a'
Copy From Remote Server scp @:
Spawn a new command without losing command line control &
Copy to Remote Server scp @:
Delete a File rm
Grep in Files with a Certain Name Patten find -name *.env | xargs grep "value"
Grep Recursively grep -R
Grep with a Regular Expression grep -E "bluh|muh|zuh" *
Install RPM rpm -Uvh
Kill a Proccess kill -9
Make a Symbolic Link ln -s
Present Working Directory pwd
Repeat a Command at Regular Intervals watch --interval= ""
Search Previous Commands ctrl+r (or history | grep )
Set Rights chmod [GXMMS:uga][GXMMS:+-][GXMMS:rwx]
Switch Users su
Tar tar cvzf
Untar tar -xvf
Uninstall RPM rpm -e
View Directories ls -d */
View Files with Timestamps, etc. ls -l
View Files with Timestamps, sorted by date ls -lrt
View Info which
View Mounts df -k
View Processes ps -aux
View Rights ls -al
View What RPMs You Have Installed rpm -qa | grep
Watch End of File for Specific Output tail -F | grep
Wildcard *
Wildcard (Digit) ?

In addition to these commands, it's also good to have scripts to automate searching over multpile servers, performing routine checks, etc.

Here's a sample grepping script for Sun2:

echo grepping for $1 in logs 0-9 on all servers
for i in 1 2 3 4 5 6;
do
ssh lsdev@gx-mmsc00$i grep $1 /var/lsurf/log/gx-mmsc/mmsc-server.log.?;
echo $'\a'
done;

It's also handy to have scripts that simply type out your ssh commands for you.

echo connecting to ssh shell01.sun2.lightsurf.net...
ssh shell01.sun2.lightsurf.net

Here's an example of another script from the Daily Health Checks section:

echo
echo -------------------------
echo -
echo - DAILY HEALTH CHECK
echo -
echo -------------------------
echo
echo files in /gx/msgs/retry:
ls -l /gx/msgs/retry/
echo
echo Number of files in /gx/dist/sart:
ls -l /gx/dist/sart/ | wc -l
echo
echo Files over 2 megs in /gx/dist/sart:
find /gx/dist/sart ( -path './proc' -prune ) -o ( -size +2000000c -exec ls -l {} \; )
echo
echo Files in /lsurf/local_file_storage:
ls -l /lsurf/local_file_storage/
echo

If you place your scripts in your ~/bin directory, you can run them from the commandline no matter where you are on that machine.


No comments:

Post a Comment