Linux Scroll

Just another WordPress.com site

Monthly Archives: July 2011

sar Command

sar – Collect, report, or save system activity information.

CPU statistics 5 times (with 1 second interval):

$ sar 1 5
Linux 2.6.35-28-generic (Hostname) Date _x86_64_ (1 CPU)

09:09:32 PM CPU %user %nice %system %iowait %steal %idle
09:09:33 PM all 4.00 0.00 1.00 0.00 0.00 95.00
09:09:34 PM all 4.00 0.00 4.00 0.00 0.00 92.00
09:09:35 PM all 5.00 0.00 2.00 0.00 0.00 93.00
09:09:36 PM all 4.00 0.00 2.00 0.00 0.00 94.00
09:09:37 PM all 5.00 0.00 2.00 0.00 0.00 93.00
Average: all 4.40 0.00 2.20 0.00 0.00 93.40

sar Version:

$ sar -V
sysstat version 9.0.6.1
(C) Sebastien Godard (sysstat orange.fr)

CPU usage of individual Core:

$ sar -P ALL 1 1
Linux 2.6.35-28-generic (Hostname) Date _x86_64_ (1 CPU)

11:29:21 PM CPU %user %nice %system %iowait %steal %idle
11:29:22 PM all 40.00 0.00 8.00 0.00 0.00 52.00
11:29:22 PM 0 40.00 0.00 8.00 0.00 0.00 52.00
11:29:22 PM 1 40.00 0.00 8.00 0.00 0.00 52.00

Average: CPU %user %nice %system %iowait %steal %idle
Average: all 40.00 0.00 8.00 0.00 0.00 52.00
Average: 0 40.00 0.00 8.00 0.00 0.00 52.00
Average: 1 40.00 0.00 8.00 0.00 0.00 52.00

CPU usage of seeond Core only:

$ sar -P 1 1 1
Linux 2.6.35-28-generic (Hostname) Date _x86_64_ (1 CPU)

11:29:21 PM CPU %user %nice %system %iowait %steal %idle
11:29:22 PM 1 40.00 0.00 8.00 0.00 0.00 52.00

Average: CPU %user %nice %system %iowait %steal %idle
Average: 1 40.00 0.00 8.00 0.00 0.00 52.00

Memory usage:

$ sar -r 1 3
Linux 2.6.35-28-generic (Hostname) Date _x86_64_ (1 CPU)

11:36:01 PM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit
11:36:02 PM 2752924 1045940 27.53 44012 291864 1615028 13.85
11:36:03 PM 2752924 1045940 27.53 44012 291864 1615028 13.85
11:36:04 PM 2752924 1045940 27.53 44012 291864 1615028 13.85
Average: 2752924 1045940 27.53 44012 291864 1615028 13.85

Swap usage:

$ sar -S 1 3
Linux 2.6.35-28-generic (Hostname) Date _x86_64_ (1 CPU)

12:48:50 PM kbswpfree kbswpused %swpused kbswpcad %swpcad
12:48:51 PM 7863780 0 0.00 0 0.00
12:48:52 PM 7863780 0 0.00 0 0.00
12:48:53 PM 7863780 0 0.00 0 0.00
Average: 7863780 0 0.00 0 0.00

Swap statistic:

$ sar -W 1 3
Linux 2.6.35-28-generic (Hostname) Date _x86_64_ (1 CPU)

12:50:36 PM pswpin/s pswpout/s
12:50:37 PM 0.00 0.00
12:50:38 PM 0.00 0.00
12:50:39 PM 0.00 0.00
Average: 0.00 0.00

Overall I/O activities:

$ sar -b 1 3
Linux 2.6.35-28-generic (1010) 07/29/2011 _x86_64_ (1 CPU)

01:02:27 PM tps rtps wtps bread/s bwrtn/s
01:02:28 PM 0.00 0.00 0.00 0.00 0.00
01:02:29 PM 0.00 0.00 0.00 0.00 0.00
01:02:30 PM 0.00 0.00 0.00 0.00 0.00
Average: 0.00 0.00 0.00 0.00 0.00

* tps – Transactions per second (read and write)
* rtps – Read transactions per second
* wtps – Write transactions per second
* bread/s – Bytes read per second
* bwrtn/s – Bytes written per second

Advertisements

Advanced search file

Search png file in dummy directory.

$ file -Lz * | grep PNG | cut -d":" -f1 | xargs ls -l

file command

file – determine file type

Determine file type:

$ file text.txt 
text.txt: ASCII text, with CRLF line terminators

Determine compress file type:

$ file crm.tar.gz 
crm.tar.gz: gzip compressed data, from Unix, last modified:

$ file -z crm.tar.gz 
crm.tar.gz: POSIX tar archive (GNU) (gzip compressed data, from Unix, last modified:)

Determine symbolic links path:

$ file Music
Music: symbolic link to `/data/Music'

Determine symbolic links file type:

$ file -L Music
Music: directory

Stat command

Display file1 information:

$ stat file1

Display file system info of the file1:

$ stat -f file1

Quick change permission and ownership

Quick assign permission for file2 same with file1:

chmod --reference file1 file2

Quick change ownership for file2 same with file1:

chown --reference file1 file2

Quick change group for file2 same with file1:

chgrp --reference file1 file2