2. Real-time performance monitoring:
However iostat by default shows only the first four disks: if you have more use -x and/or -l options :
iostat -xdnl 7 5 (e.g. if you have seven hard
disks)
extended device statistics
r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device
0.4 1.6 3.2 70.4 0.0 0.0 0.0 2.7 0 1 c0t0d0
0.2 1.6 1.6 70.4 0.0 0.0 0.0 3.0 0 1 c0t1d0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 c0t6d0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 c1t8d0
88.8 19.8 1276.8 158.4 0.0 0.6 0.0 5.7 0 51 c1t9d0
0.0 0.4 0.0 100.8 0.0 0.0 0.0 17.4 0 1 c1t10d0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 c1t11d0
crontab -l to see your crontab
crontab -e to edit it (NB but first do EDITOR=vi (or EDITOR=emacs) ; export EDITOR )
Remember fields are : minute hour day month day_of_week (0=Sun)
0-59 0-23 1-31 1-12 0-6
e.g. run a script only on Tuesdays to Fridays, at 10:12 am, 3:12pm, 4:12pm and 5:12pm
12 10,15-17 * * 2-5/home/oracle/bin/script
find things you can’t remember the exact name of :
find /usr/lib -name "*socket*"
find big files (more than 20000 blocks, ie about 10MB )
find . -size +20000
find files or directories modified in last day
find . -mtime -1
find files not accessed (read) in 45 days
find /tmp -atime +45
Add -ls to the end of any of the above commands to see a full ls -l listing of the files found.
You can combine multiple options , e.g look for which big files have filled up a filesystem recently
find . -size +20000 -mtime -1 -ls
Or combine options using an "OR" syntax, e.g. find files which were modified either less than 1 week ago or more than 2 weeks ago
find . \( -mtime +14 -o -mtime -7 \) -ls
You can send the ouput of find to another command : the xargs command is ideal for this: e.g. interactively delete all core files under your $HOME
find ~ -type f -name core |xargs rm -i
or look for a particular word in all your .c files:
find . -name "*.c" |xargs grep -l libsocket
-n sorts by number instead of alphabetically
e.g. cd /export/home; du -sk * | sort -nr lists who is using most space in their home directory
other useful Unix commands for you to check out:
The basic vi commands:
| i | insert before current character | a | append after current char |
| I | insert at beginning of line | A | append after end of line |
| x | delete current character | X | backspace-delete (deletes char to left) |
| dd | delete current line | 22dd | delete 22 lines | u | undo the last thing you did |
| p | paste those 22 lines below the current line | ||
| 12yy | copy 12 lines into the ‘clipboard’ for later pasting | ||
| <Esc> | to get out of editing (insert/append) mode | ||
| :wq | to save ('write') and quit (:q! to quit without writing) |
vi moving-around Timesavers:
using h,j,k,l to move left,down,up and right is quicker than using the arrow keys (once you get used to it!).
| w | move one word forward | b | move back a word | e | go to end of word |
| Ctl-F | move Forward a whole page | Ctl-B | move Back a page | ||
| 0 | (zero) go to beginning of line | $ | go to end of line | ||
| :242 | go to line 242 | Ctl-G | see what line you are on | ||
vi modifying things:
| cw | change word | 3cw | change 3 words | C | change to end-of-line |
| dw | delete word | D | delete to end-of-line | ||
| cc | replace current line with what you type next | ||||
| r | replace one character | R | endless replace (like over-typing) | ||
| o | open/add a new line below the current one | O | open new line above current one | ||
| xp | swap two characters (e.g. when you make a typo) | ||||
| /bob | search forward for 'bob' | n | repeat previous search | ? | search backwards |
Probably the handiest vi command:
. (dot) -repeat your last command
useful extra vi commands:
~ swap case of current character (capitalize or lower-case)
Ctl-L re-draw the screen (e.g when something from a background process writes to your screen and messes up your vi window)
:set nu show line numbers (:set nonu to remove line numbers)
:set list show hidden characters, line endings etc. (: set nolist)
Global replace:
:%s/old/new/g (% means all lines)
or :g/old/s//new/g
or :%s/old/new/gc (c is to confirm each replacement, type ‘y’ to accept)
What you may not know is that whether someone can delete that file is not determined by the file permissions,
but by the permissions of the directory the file is in :
bash$ ls -al
total 598
drwxrwxr-x 3 robins devteam 512 Mar 8 12:02 .
drwxr-xr-x 24 root wheel 1024 Mar 8 12:02 ..
-rwxr-xr-- 1 robins devteam 180 Mar 8 13:50 instbb
In this case the directory (.) is group writeable, which means anyone in the group devteam can delete the file
instbb. Although they can’t modify it, they could copy it to a new file in that directory, modify it, then delete
the original and rename the new file as instbb. So the file isn’t as secure as it may appear..
Solaris provides a mechanism for getting hostnames and usernames etc from several sources (e.g DNS, NIS, or the
traditional /etc/hosts file) : the file /etc/nsswitch.conf , which may contain
hosts: files dns
this means that when you try to access a remote host by name (e.g. ping neptune) it will look for neptune first
in /etc/hosts, then do an lookup in DNS (nslookup using the server specified in /etc/resolv.conf)
Similarly for usernames, you may have
passwd: files nis
So when you run a command which refers to a username (e.g. cd ~oracle ) , it first looks in /etc/passwd then does a
lookup in NIS (ypmatch oracle passwd).