Showing posts with label Linux For DBA. Show all posts
Showing posts with label Linux For DBA. Show all posts

Wednesday, June 29, 2011

GET FIRST AND LAST DAY OF A MONTH IN BASH SHELL

GET FIRST AND LAST DAY OF A MONTH IN BASH SHELL




Linux system comes with a date commend. The man page has all the details. The following shows how to get the first date and last day of a month using the date commends in bash shell.

First Day, current month:
# date -d "-0 month -$(($(date +%d)-1)) days"

First Day, last month:
# date -d "-1 month -$(($(date +%d)-1)) days"

Last Day, current month:
# date -d "-$(date +%d) days +1 month"

Last Day, last month:
# date -d "-$(date +%d) days -0 month"

Last Day, month before last month:
# date -d "-$(date +%d) days -1 month"

%d = day of month.


Thursday, September 02, 2010

Linux Sed: Print Lines From File Using Sed

Print Lines Using Sed

This is the third note on Text Manipulations with Linux Sed. The first note covers Append and Insert to a file using sed. It also covers the Option Switches. The second note covers Replace and Delete from a file using sed

To test each of the commands and options, let’s use the following files as an example:

#> cat sed_edit.txt
New York, Big Apple
Washington DC, The Capital
New Jersey, Garden Stata
Paris, The City of Light
Hong Kong, Pearl of the Orient

1 Use Sed ‘p’ to print line(s) by address

Following is the Syntax to print lines with address:

#sed -n ‘ADDRESS P’ inputfilename

Here some examples use print command with address to print line(s) from a input file.

• Example 1: print the 3r line from a file
#>sed -n '3p' sed_edit.txt
New Jersey, Garden Stata

• Example 2: print a range of lines
Print line 2 to to from the input file

#sed -n '2,4p' sed_edit.txt
Washington DC, The Capital
New Jersey, Garden Stata
Paris, The City of Light

• Example 3: Print from line 2 to the end of file.
#>sed -n '2,$p' sed_edit.txt
Washington DC, The Capital
New Jersey, Garden Stata
Paris, The City of Light
Hong Kong, Pearl of the Orient

2 Use Sed ‘p’ to print line(s) by matches of pattern

Following is the Syntax to print lines with address:

#>sed -n ‘/PATTERN/ P’ inputfilename

Here are some examples use print command with match of pattern to print line(s) from a input file.

• Example 1: print line matches a patter.
Print out the line that matches that pather “Paris”

$sed -n '/Paris/ p' sed_edit.txt
Paris, The City of Light

• Example 2: print number of lines from the matched pattern
Print line that matches ‘New Jersey’ and the next two lines

#sed -n '/New Jersey/,+2p' sed_edit.txt
New Jersey, Garden Stata
Paris, The City of Light
Hong Kong, Pearl of the Orient

• Example 3: print line starting from a given line to the parttern matched line.
Print from 2nd line to the line that matches “Paris”

#>sed -n '2,/Paris/p' sed_edit.txt
Washington DC, The Capital
New Jersey, Garden Stata
Paris, The City of Light

• Example 4: print line between two match patterns
Print lines between match patterns “Washington” and “Paris”

#> sed -n '/Washington/,/Paris/p' sed_edit.txt
Washington DC, The Capital
New Jersey, Garden Stata
Paris, The City of Light

• Show all the “Lock wait timeout exceeded” errors from the mysql server error log file

#>sed -n -e '/Lock wait timeout exceeded/,+1p' mysql-error.log

“grep” command can do the similar thing, but the +1 (plus 1 line) option, or change to multiple lines, comes handy sometime when we want to inclue messges after the error message. I found it can be helpful to extract messages that are related to an event from any logs (database server logs, syslogs,etc)

• Select all the enteries during a period of time from the Oracle alert log

#sed -n -e '/Thu Jun 4 14:/,/Thu Jun 4 17:/P' alert_ora.log

The above example select the log entries from 2:00pm to 5:00pm on Thursday, July 14.

References:


Linux Sed: REPLACE, AND DELETE LINES FROM A FILE USING SED

REPLACE, AND DELETE LINES FROM A FILE USING SED


To test each of the commands and options, let’s use the following files as an example:

#> cat sed_edit.txt
New York, Big Apple
Washington DC, The Capital
New Jersey, Garden Stata
Paris, The City of Light
Hong Kong, Pearl of the Orient
 1. Use Sed ‘c\’ to replace a line indicate by the address

Following is the Syntax to replace a line with address:

#sed 'ADDRESS a\
  Line which you want to replace' filename

‘ADDRESS’ is a number with represents the line, i.e.,3, represent the 3rd line.

Here am examples using sed replace with address command:

• Replace 3rd line with ,” San Francisco, Golden City”

  #> sed '3 c\San Francisco, Golden City' sed_edit.txt
New York, Big Apple
Washington DC, The Capital
San Francisco, Golden City
Paris, The City of Light
Hong Kong, Pearl of the Orient

2 Use Sed ‘c\’ to replace a line that match with a pathern

Following is the Syntax to append a line with a match of a pattern:

#sed '/PATTERN/ c\
   Line which you want to replace' filename

Here is an example using sed replace to replace a line of match of pattern to a file.

• There is a typo in line “New Jersey, Garden Stata” with the word “Stata”. Let’s replace it.
  #>sed '/New Jersey, Garden Stata/ c\New Jersey, Garden State' sed_edit.txt
New York, Big Apple
Washington DC, The Capital
New Jersey, Garden State
Paris, The City of Light
Hong Kong, Pearl of the Orient

2.Sed Delete
2.1 Use Sed ‘d’ to delete line(s) indicate by the address

Following is the Syntax to replace a line with address:
#>sed ‘ADDRESS d’ inputfilename

Please note there is no “backslash”(“\”) after d.

There are some examples use sed delete command to delete line(s) from a input file.
• Example 1: delete the 3rd line from the file.

# sed ‘3d’ sed_edit.txt
New York, Big Apple
Washington DC, The Capital
Paris, The City of Light
Hong Kong, Pearl of the Orient

• Example 2: delete the line 2 to line 4 from the file.

# sed '2,4d' sed_edit.txt
New York, Big Apple
Hong Kong, Pearl of the Orient

2.2 Use Sed ‘d’ to delete line(s) indicate by match of pattern

Following is the Syntax to replace a line with address:

#sed ‘/PATTERN/ d’ inputfilename

Here some examples use sed delete command with match of pattern to delete line(s) from a input file.

• Example 1: delete line matches a given pattern.
  Delete the line “New Jersey, Garden Stata” from the file
  #>sed '/New Jersey, Garden Stata/ d' sed_edit.txt
   New York, Big Apple
   Washington DC, The Capital
   Paris, The City of Light
   Hong Kong, Pearl of the Orient

• Example 2: delete all the blank link from a file
  Let’s change the file to look like this:
  #>cat sed_edit.txt
  New York, Big Apple

 Washington DC, The Capital

 New Jersey, Garden Stata

  Paris, The City of Light
  Hong Kong, Pearl of the Orient

Now, use delete to remove all blank lines.
 #>sed '/^$/d' sed_edit.txt
 New York, Big Apple
 Washington DC, The Capital
 New Jersey, Garden Stata
 Paris, The City of Light
  Hong Kong, Pearl of the Orient

• Example 3: delete multiple lines starting from the the line that matches a given pattern
 Delete the lines that match “Paris” and all lines that after this lines

#>sed '/Paris/,$d' sed_edit.txt
New York, Big Apple
Washington DC, The Capital
New Jersey, Garden Stata

• Example 4: delete 1 addition lines from the match pattern
Delete the line that matches “Paris” and one more line after that

#sed '/Paris/,+1d' sed_edit.txt
New York, Big Apple
Washington DC, The Capital
New Jersey, Garden Stata

References:


LINUX SED: APPEND, INSERT AND WRITE TO A FILE FROM A FILE USING SED

APPEND, INSERT AND WRITE LINES TO A FILE FROM A FILE USING SED

This is the first note on Text Manipulations Using Linux Sed.

This note covers how to using Linux sed command to do simple append, insert, and write lines to an output file using a text file as input. Sed provides lot of commands to perform number of operations with the lines in a file. This comes handy in situations that we want to use a script to update files.

1 Sed Dose Not Change Input file.

"SED" stands for Stream EDitor. Sed reads its input from stdin ("standard input," i.e., the console or pipe), or from files, and writes its results to stdout (“standard output”, i.e., the screen). Therefore, sed doesn't modify any input files. Sed takes any number of user-specified editing operations ("commands") and performed on each line in order on the input data.

2 Sed command syntax and option switches.

Sed commands need to be put inside a pair of sigle quotes ‘’. All text lines that involve append, insert and replace need to be preceded by a “backslash” ( “\”). Make sure that there is no space between the command switch and the “\”. For example, the following command adds a line “add this line after the 3rd line”, to the input file inputfile.txt:

#sed ‘3 a\add this line after the 3rd line’ inputfile.txt 

Following are option switches and commands that use in this note. There is more information on sed can be found in the man page here.

Options:
• -n, --quiet, --silent suppress automatic printing of pattern space
• -e, script, --expression=script add the script to the commands to be executed
• -f, script-file, --file=script-file add the contents of script-file to the commands to be executed
Commands:
• P – Upper case P. Print up to the first embedded newline of the current pattern space.
• p – Lower case p. Print the current pattern space.
• = -- print current line number.
• W filename – Uper case W. Write the first line of the current pattern space to filename.
• w filename – Lower case w. Write the current pattern space to filename.
• a \text – Append text, which has each embedded newline preceded by a backslash.
• i \text – Insert text, which has each embedded newline preceded by a backslash.
• c\ text -- Replace the selected lines with text, which has each embedded newline preceded by a backslash.
• D – Upper case D. Delete up to the first embedded newline in the pattern space. Start next cycle, but skip reading from the input if there is still data in the pattern space.
• d – Delete pattern space. Start next cycle.

To test each of the commands and options, let’s use the following files as an example:

# cat sed_edit.txt
New York, Big Apple
Washington DC, The Capital
New Jersey, Garden Stata
Paris, The City of Light
Hong Kong, Pearl of the Orient

3 Sed Append
3.1 Use Sed ‘a\’ to appends a line after every line with the address

Following is the Syntax to append a line with address:

#sed 'ADDRESS a\
  Line which you want to append' filename
‘ADDRESS’ is a number with represents the line, i.e., 3, represent the 3rd line.

Here are some examples using sed append with address command:

• Example 1. Add a line after the 3rd line of the file.
Add the line “San Francisco, Golden City” after the 3rd line.

#sed ‘3 a\San Francisco, Golden City’ sed_edit.txt
New York, Big Apple
Washington DC, The Capital
New Jersey, Garden Stata
San Francisco, Golden City
Paris, The City of Light
Hong Kong, Pearl of the Orient

• Example 2: Add a line at the end of the file.
Sed also works with regurlar expression. The following command add the line “San Francisco, Golden City” at the end of the file

#sed ‘$,a\San Francisco, Golden City’ sed_edit.txt
New York, Big Apple
Washington DC, The Capital
New Jersey, Garden Stata
Paris, The City of Light
Hong Kong, Pearl of the Orient
San Francisco, Golden City

Here, the ‘$’ is the regurlar expression for end of file.

3.2 Use Sed ‘a\’ to appends a line after every line that match with a pathern

Following is the Syntax to append a line with a match of a pattern:

#sed '/PATTERN/ a\
Line which you want to append' filename

‘/PATTERN/’ is the pattern that wants match,i.e., /Paris/. Pattern need to be put between two forwardslashes,”/”.
Here is an examples using sed append command with a match of pattern:

• Append a line,” San Francisco, Golden City”, after a match of pattern “Paris”

#sed '/Paris/ a\San Francisco, Golden City' sed_edit.txt
New York, Big Apple
Washington DC, The Capital
New Jersey, Garden Stata
Paris, The City of Light
San Francisco, Golden City
Hong Kong, Pearl of the Orient

4 Sed Insert
The different between sed append and sed insert is that sed append adds the line after the address or match of pattern while sed insert adds the line before the address or match of the parttern.

4.1 Use Sed ‘i\’ to insert a line before every line with the address
Following is the Syntax to append a line with address:

#sed 'ADDRESS a\
Line which you want to append' filename

‘ADDRESS’ is a number with represents the line, i.e., 3, represent the 3rd line.

Here are some examples using sed insert to insert a line before an address.

• Example 1: Insert a line before the 3rd line of the file.
Insert the line “San Francisco, Golden City” before the 3rd line.

# sed '3 i\San Francisco, Golden City' sed_edit.txt
New York, Big Apple
Washington DC, The Capital
San Francisco, Golden City
New Jersey, Garden Stata
Paris, The City of Light
Hong Kong, Pearl of the Orient

• Example 2: insert a line at the beginning of the file.
Insert the line “San Francisco, Golden City” at the beginning of the file.

#sed '1 i\San Francisco, Golden City' sed_edit.txt
San Francisco, Golden City
New York, Big Apple
Washington DC, The Capital
New Jersey, Garden Stata
Paris, The City of Light
Hong Kong, Pearl of the Orient

Here address “1” represents the first line of the file.

4.2 Use Sed ‘i\’ to insert a line before every line that match with a pathern

Following is the Syntax to append a line with a match of a pattern:

#sed '/PATTERN/ i\
Line which you want to append' filename

Here is an example using sed insert to insert a line to a file.
• Insert a line,” San Francisco, Golden City”, before each match of pattern “Paris”

#sed '/Paris/ i\San Francisco, Golden City' sed_edit.txt
New York, Big Apple
Washington DC, The Capital
New Jersey, Garden Stata
San Francisco, Golden City
Paris, The City of Light
Hong Kong, Pearl of the Orient


5 Sed Write To a File
 Following is the Syntax to write to a file with address and pathern:

#sed 'ADDERSSw outputfilename' inputfilename

#sed '/PATTERN/w outputfilename' inputfilename
To store output of the above example, we can do the following:

#sed -n '/Washington/,/Paris/w sed_edit.out' sed_edit.txt

 Sed_edit.out will contain the output of the sed command.

However, to save a copy of the file that after insert,delete or update(replace) you may find it easier just to use the “>outputfilename” syntax.

For example, to save the changes make to the input file with the replace command, we can do:

#sed '/New Jersey, Garden Stata/ c\New Jersey, Garden State' sed_edit.txt > sed_edit.out

References:


Tuesday, April 20, 2010

Linux Command: cp -f, --force, Not Working

Today, when I tried to copy some files from one dirctory to the other in my Linux server, I issued the following Linux command:

#>cp -rf /dir1/* /dir2

However, the -f, --force switch, which was to tell cp command to overwrite the existing files (it meas if an existing destination file cannot be opened, remove it and try again), did not seen to work. I kept getting the following message:

cp: overwrite ‘/dir1/subdir1/file.dat with /dir2/subdir1/file.dat’

Since I had about 300 files to copy, it was not easy for me to keep typing ‘y’. So, I did some searches and found the following solution.

1. Run the alias command to check if cp was set to alias with a different command.

#> alias

alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'

Which you can see, cp was acturaly alias as 'cp –i'. -i, --interactive, which means prompt before overwrite. Therefore, -f was ignored.

I want to remove the alias so I could copy the files. To do so, I needed to issue the following command:

#>unalias cp

However, in normally situation, we do want to use cp –i to prevent accidentally override files. Therefore, I issued the following command after done with copying the files:

#>alias ‘cp=cp –I’

One more detail, to perform the above steps, it required root access. So, what happen if we don’t have root access? Well, the following command works:

Command:
#> /bin/cp -rf /dir1/* /dir2

It is because that the /bin/cp copy is not alias to any other command switch.


Wednesday, February 25, 2009

Linux: Find Out Who Are Logged On or Were Logged On

There are a few ways to find out who are logged on:

1. Use the w command

#>w
00:03:53 up 4:45, 1 user, load average: 0.00, 0.00, 0.00
SER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/1 192.168.1.107 00:03 0.00s 0.02s 0.00s w

2.  Use who -a command.
Who -a command also provides list all the users who have an open session (currently logon)
 
#>who -a
Feb 24 19:18 518 id=si term=0 exit=0

system boot Feb 24 19:18
run-level 5 Feb 24 19:18 last=S
Feb 24 19:19 4465 id=l5 term=0 exit=0
LOGIN tty1 Feb 24 19:19 5706 id=1
LOGIN tty2 Feb 24 19:19 5709 id=2
Feb 24 19:19 5711 id=3
Feb 24 19:19 5727 id=4
Feb 24 19:19 5739 id=5
LOGIN tty6 Feb 24 19:19 5745 id=6
Feb 24 19:19 5746 id=x
root + pts/1 Feb 25 00:03 00:02 6610 (192.168.1.107)
root + pts/2 Feb 25 00:07 . 6646 (192.168.1.107)

3. Use the users coomand.
The user command shows user ids of the current login users.

#>users
root root

4. Use the last command.
The  last command  looks through /var/log/wtmp and displays a log of the last users logged on, including those currently logged on.

#>last
root pts/2 192.168.1.107 Thu Feb 25 00:07 still logged in
root pts/1 192.168.1.107 Thu Feb 25 00:03 still logged in
reboot system boot 2.6.9-89.ELsmp Wed Feb 24 19:18 (04:54)
root pts/1 192.168.1.107 Wed Feb 24 08:56 - down (00:02)
reboot system boot 2.6.9-89.ELsmp Tue Feb 23 19:28 (13:30)
root pts/2 192.168.1.102 Tue Feb 23 03:39 - 05:50 (02:11)

5.  Check system messages log
You may need root privilege to see the messages

#>grep sshd /var/log/messages

Feb 25 00:03:50 pc-1 sshd(pam_unix)[6608]: session opened for user root by (uid=0)
Feb 25 00:07:16 pc-1 sshd(pam_unix)[6644]: session opened for user root by (uid=0)


Wednesday, February 04, 2009

Mailx Error:can not write to queue directory /var/spool/clientmqueue/

Problem:

Try to use linux mail to send email and got error:

/bin/mailx -s "$SUBJECT" "$RECIPIENT"

can not write to queue directory /var/spool/clientmqueue/ (RunAsGid=51, required=101): Permission denied
can not write to queue directory /var/spool/clientmqueue/ (RunAsGid=51, required=101): Permission denied

Fix:

Check the owner and permission of /var/spool/clientmqueue.

Go to directory /var/spool, and used ls –ln command to see who is the owner and what is the permission are:

Shell>ls –ln

drwxrwx--- 2 51 51 4096 Jan 19 12:45 clientmqueue

The directory need to be owned by smmsp:smmsp.

If you only see the group id and user id display, check the /etc/passwd file to see is the group id belong to smmsp.

Shell>vi /etc/passwd

smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin

If the group and user is not smmsp:smmsp, change them.

Shell> chown –R smmsp:smmsp clientmqueue.


Thursday, August 21, 2008

Linux: Add User To A Group

First, if the group dose not exists, use the following command to add a group:

groupadd

For example, to add a group called mysql, use the following command:
#>groupadd mysql

To add a user with a group, use:
useradd -s -m -d -g UserName

For example, to add a use called mysql to a mysql group, using the following command:

#> useradd -s /bin/csh -m -d /home/mysql -c "Mysql User" -g mysql mysql


Monday, July 28, 2008

Linux: Check Linux Version

Here are the commands which can be used to check Linux version:

$cat /proc/version
Linux version 2.6.18-128.4.1.el5 (mockbuild@hs20-bc1-7.build.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)) #1 SMP Thu Jul 23 19:59:19 EDT 2009

$uname –a
Linux host.domain.net 2.6.9-78.0.1.ELsmp #1 SMP Tue Jul 22 18:11:48 EDT 2008 i686 i686 i386 GNU/Linux

Check 32 vs 64 bits

$>uname –m

i686

$>file /usr/bin/file
/usr/bin/file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), stripped


Saturday, March 01, 2008

Linux: Install a Package on Redhat Linux

1.check what packages had been installed on the server:
#rpm -q binutils compat-db control-center gcc gcc-c++ glibc glibc-common \
gnome-libs libstdc++ libstdc++-devel make pdksh sysstat xscreensaver \
libaio openmotif21

binutils-2.15.92.0.2-13
compat-db-4.1.25-9
control-center-2.8.0-12
gcc-3.4.3-22.1
gcc-c++-3.4.3-22.1
glibc-2.3.4-2.9
glibc-common-2.3.4-2.9
gnome-libs-1.4.1.2.90-44.1
libstdc++-3.4.3-22.1
libstdc++-devel-3.4.3-22.1
make-3.80-5
pdksh-5.2.14-30
package sysstat is not installed
xscreensaver-4.18-5.rhel4.2
libaio-0.3.103-3
openmotif21-2.1.30-11.RHEL4.4

the above commend will display packages had been installed for:

binutils compat-db control-center gcc gcc-c++ glibc glibc-common gnome-libs libstdc++ libstdc++-devel make pdksh sysstat xscreensaver libaio openmotif21

the “\ “is a line braker. This command will print the package name, version, and release number of installed package foo. Use this command to verify that a package is or is not installed on your system.

2.Install a package
#rpm -ivh foo-1.0-2.i386.rpm

It is also better to use Update , rpm –Uvh (see 4), to install packages, since it works fine even when there are no previous versions of the package installed. This way, it will not give error if a package already exists.

3.Uninstall a package
#rpm –e foo

Notice that we used the package name foo, not the name of the original package file foo-1.0-2.i386.rpm.

4.Update a RPM package.
#rpm -Uvh foo-1.0-2.i386.rpm
With this command, RPM automatically uninstall the old version of foo package and install the new one. Always use rpm -Uvh to install packages, since it works fine even when there are no previous versions of the package installed.

5.Display package Information
# rpm -qi foo
This command display package information; includes name, version, and description of the installed program. Use this command to get information about the installed package.
6.List Files in package
# rpm –qlfoo
This command will list all files in a installed RPM package. It works only when the package is already installed on your system.
7.Check RPM Signature package
#rpm –checksig foo
This command checks the PGP signature of specified package to ensure its integrity and origin. Always use this command first before installing new RPM package on your system. Also, GnuPG or Pgp software must be already installed on your system before you can use this command.


Friday, September 14, 2007

Linux Admin Tool: Iostat

The iostat command at its most basic provides an overview of CPU and disk I/O statistics:

#iostat

iostat
Linux 2.4.21-32.ELsmp (dw1.corp.co.com) 03/30/2007
avg-cpu: %user %nice %sys %iowait %idle
4.10 0.01 1.26 4.69 89.94

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
cciss/c0d0 19.43 24.51 27.90 726081316 826335200
cciss/c0d0p1 16.75 17.37 110.99 514613362 3287372808
cciss/c0d0p2 2.57 6.44 60.75 190884490 1799215720
cciss/c0d0p3 0.10 0.69 1.17 20583160 34713968

Below the first line (which contains the system's kernel version and hostname, along with the current date), iostat displays an overview of the system's average CPU utilization since the last reboot. The CPU utilization report includes the following percentages:

· Percentage of time spent in user mode (running applications, etc.)
· Percentage of time spent in user mode (for processes that have altered their scheduling priority using nice(2))
· Percentage of time spent in kernel mode
· Percentage of time spent idle

Below the CPU utilization report is the device utilization report. This report contains one line for each active disk device on the system and includes the following information:

· The device specification, displayed as dev-sequence-number, where is the device's major number[1], and is a sequence number starting at zero.
· The number of transfers (or I/O operations) per second.
· The number of 512-byte blocks read per second.
· The number of 512-byte blocks written per second.
· The total number of 512-byte blocks read.
· The total number of 512-byte block written.

This is just a sample of the information that can be obtained using iostat. For more information, refer to the iostat(1) man page.


Thursday, August 16, 2007

Linux: vmstat

vmstat

Provides real-time reports on CPU consumption, CPU dispatcher run queue, RAM page in, scan rate, RAM page outs. Example:
#vmstat 2 5

procs memory swap io system cpu
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 11160 327148 35036 3446588 0 1 1 0 0 0 0 0 0 1

Procs
r: The number of runnable processes waiting for access to the CPU.
b: The number of processes in uninterruptible sleep.

Memory
swpd: the amount of virtual memory used.
free: the amount of idle memory.
buff: the amount of memory used as buffers.
cache: the amount of memory used as cache.
inact: the amount of inactive memory. (-a option)
active: the amount of active memory. (-a option)

Swap
si: Amount of memory swapped in from disk (/s).
so: Amount of memory swapped to disk (/s).

IO
bi: Blocks received from a block device (blocks/s).
bo: Blocks sent to a block device (blocks/s).

System
in: The number of interrupts per second, including the clock.
cs: The number of context switches per second.

CPU
These are percentages of total CPU time.
us: The percentage of the time the CPU ran user-level code (non-kernel. (user time, including nice time)
sy: Time spent running kernel code. (system time)
id: The percentage of the time the CPU was idle. Prior to Linux 2.5.41, this includes IO-wait time.
wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.


Sunday, February 04, 2007

Linux: Truncate A File

There is a simple command that will truncate the file to zero length without affecting any permissions. Here it is:
shell>:>filename
If the file already exists, it will be truncated to zero bytes, else this command will create an empty file. This is handy for truncating big log files.

Or you can use:

shell>cat /dev/null > some_log_file.log