Linux Commands II

If you want a good manual with unix commands, you have two options:

1st – A small and quick manual within no more than 5 pages

2nd- A list of all kind of linux commands in a book or pdf with 300 pages or more.

If you choose first option and you use all commands in the list, you will get know in a week because of use.

My point of view is: I like a book with thousands of commands with each explanation to review. I will never know all commands. It is stupid to know all ones when you have a good help and the most known search engine website ūüėČ Anyway, if you want to be a good administrator, you should know a long list. Each command have a list of options that you can check with:

[user@localhost ~]$ help {command}

or

[user@localhost ~]$ man {command}

That is the reason because  is not mandatory to know all commands within options.

In this post, I will  put some interesting commands.

TOP – Command to know the CPU usage. It displays a listing of the most CPU intensive tasks on the system.

Tasks: 193 total,   1 running, 192 sleeping,   0 stopped,   0 zombie

Cpu(s):  1.8%us,  1.5%sy,  0.0%ni, 96.6%id,  0.0%wa,  0.2%hi,  0.0%si,  0.0%st

Mem:   2060700k total,  1849668k used,   211032k free,    58676k buffers

Swap:  4194292k total,       20k used,  4194272k free,  1187076k cached


PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND

2658 eduardo   20   0  129m  24m  16m S  2.3  1.2   2:42.51 chrome

3321 eduardo   20   0  354m 112m  24m S  1.7  5.6   2:10.95 firefox

1625 root      20   0 98412  62m  17m S  1.0  3.1  63:29.99 Xorg

4421 root      20   0  2556 1104  824 R  0.7  0.1   0:00.30 top

3658 eduardo   20   0  115m  25m  13m S  0.3  1.3   0:09.74 chrome

3723 eduardo   20   0 48832  12m 9212 S  0.3  0.6   0:06.31 gnome-terminal

1 root      20   0  2024  780  580 S  0.0  0.0   0:01.14 init

2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd

3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0

4 root      20   0     0    0    0 S  0.0  0.0   0:00.16 ksoftirqd/0

5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/0

6 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/1

7 root      20   0     0    0    0 S  0.0  0.0   0:00.66 ksoftirqd/1

8 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/1

9 root      20   0     0    0    0 S  0.0  0.0   0:00.11 events/0

10 root      20   0     0    0    0 S  0.0  0.0   0:01.25 events/1

11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cpuset

12 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper

13 root      20   0     0    0    0 S  0.0  0.0   0:00.00 netns

14 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr

15 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm

PS – Reports the process status. This command typed alone show you the current running processes.

[user@localhost ~]$ ps
PID TTY          TIME CMD
3725 pts/0    00:00:00 bash
3743 pts/0    00:00:00 ps

Adding the following options, you can get the top 5 CPU users

[user@localhost ~]$ ps -eo pcpu,pid,user,args | sort -k 1 -r | head -5

%CPU   PID USER     COMMAND

62.4  2538 user  vinagre

4.8  2997 user  rhythmbox

31.6  1625 root     /usr/bin/Xorg :0 -nr -verbose -auth /var/run/gdm/auth-for-gdm-LC90Bs/database -nolisten tcp vt1

2.8  3321 user  /usr/lib/firefox-3.5/firefox http://www.google.com

MPSTAT – Display the unilization of each CPU individually.

[root@localhost user]# mpstat

Linux 2.6.32.12-115.fc12.i686 (localhost.localdomain) 05/27/2010 _i686_ (2 CPU)


11:21:15 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle

11:21:15 PM  all   32.00    0.34   16.37    0.66    0.07    2.06    0.00    0.00   48.51

This command display activities for each available processor and can be used on SMP(Multiple CPU) and UP machines, but in the latter, only global average activities will be printed:
[root@localhost user]# mpstat -P ALL
Linux 2.6.32.12-115.fc12.i686 (localhost.localdomain) 05/27/2010 _i686_ (2 CPU)

11:23:43 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
11:23:43 PM  all   32.06    0.33   16.44    0.65    0.07    2.08    0.00    0.00   48.37
11:23:43 PM    0   48.16    0.37   14.58    0.82    0.05    1.24    0.00    0.00   34.77
11:23:43 PM    1   17.44    0.30   18.13    0.49    0.08    2.83    0.00    0.00   60.73
IOSTAT – Display CPU statistics and in/out statistics for devices and partitions. Useful to know your CPU utilization since the last reboot.
[root@localhost user]# iostat
Linux 2.6.32.12-115.fc12.i686 (localhost.localdomain) 05/27/2010 _i686_ (2 CPU)
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
32.17    0.32   18.63    0.64    0.00   48.24
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda               4.77       149.94       347.32    1680964    3893686
sdb               0.03         0.87         0.00       9782          1
VMSTAT – Reports information about processes, memory, paging, block IO, traps, and cpu activity.

[root@localhost user]# vmstat 3
procs ———–memory———- —swap– —–io—- –system– —–cpu—–
r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
2  0    548  52268  55060 1212524    0    0    37    81  955 1157 32 18 48  1  0
2  0    548  54620  55464 1209524    0    0   252  4275 1769 1565 24  4 52 20  0
1  0    548  54224  55548 1204264    0    0    37  3940 1624 1536 20  4 60 15  0
1  0     20  52704  55600 1201252   45    0   145  3536 1258 1306  7  5 60 28  0
TCPDUMP – Dump traffic no a network
[root@localhost user]# tcpdump ‘tcp port pop3’ tcpdump: verbose output suppressed, use -v or -vv for
full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes

NETSTAT – Ddisplays network connections, routing tables, interface statistics, masquerade

connections, and multicast memberships. Output of this command can be too long, but you can
put some options to get a short result like:
[root@localhost user]# netstat -nat | awk ‘{print $6}’ | sort | uniq -c | sort -n
1 established)
1 ESTABLISHED
1 Foreign
1 TIME_WAIT
10 LISTEN
51 CLOSE_WAIT
Sources:

Advertisements

Posted on 27 May 2010, in command, linux and tagged . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: