Linux display information about installed hardware


You need to use command called lsdev. It gathers information about your computer's installed hardware from the interrupts, ioports and dma files in the /proc directory, thus giving you a quick overview of which hardware uses what I/O addresses and what IRQ and DMA channels.

This command is very useful while troubleshooting various hardware conflict problems.

Task display : CPU Information

$ cat /proc/cpuinfo

Task: Display Free and used Memory Information

$ free -m

Task: Display partition information

# fdisk -l

Task: Display file system disk space usage

# df -H
OR
# df -h

Task: Estimate file space usage

# du

Task: List PCI devices

# lspci

Task: List USB devices

# lsusb

Task display : More Information

$ lsdev
Output:
Device            DMA   IRQ  I/O Ports
------------------------------------------------
0000:00:1d.0                 d800-d81f
0000:00:1d.1                 d000-d01f
0000:00:1d.2                 d400-d41f
0000:00:1f.0                 4000-407f 4080-40bf
0000:00:1f.1                 f000-f00f
0000:00:1f.3                 5000-501f
0000:00:1f.5                 e000-e0ff e400-e43f
0000:01:05.0                   c000-c0ff
8139too                          c000-c0ff
acpi                      9
bttv0                    22
cascade             4
dma                          0080-008f
dma1                         0000-001f
dma2                         00c0-00df
ehci_hcd:usb4            20
eth0                     18
fpu                          00f0-00ff
GPE0_BLK                       4028-402f
i8042                  1 12
ICH4                     21
ide0                     14  01f0-01f7 03f6-03f6   f000-f007
ide1                     15  0170-0177 0376-0376   f008-f00f
Intel                          e000-e0ff   e400-e43f
keyboard                     0060-006f
parport0                  7  0378-037a
PCI                          0cf8-0cff c000-cfff
pic1                         0020-0021
pic2                         00a0-00a1
PM1a_CNT_BLK                   4004-4005
PM1a_EVT_BLK                   4000-4003
PM_TMR                         4008-400b
rtc                       8  0070-0077
serial                       02f8-02ff 03f8-03ff
timer                     0
timer0                       0040-0043
timer1                       0050-0053
uhci_hcd                       d000-d01f   d400-d41f   d800-d81f
uhci_hcd:usb1            16
uhci_hcd:usb2            19
uhci_hcd:usb3            17
vga+                         03c0-03df

Linux display each multiple SMP CPU processors utilization individually


Q. My AMD sever is quad processor with SMP kernel, How do I display the utilization of each CPU individually?

A. Linux can display each multiple SMP CPU processors utilization individually using mpstat command.

The mpstat command displays output activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. The mpstat command can be used both on SMP and UP machines, but in the latter, only global average activities will be printed.

# mpstat -P ALL.
Where, -P cpu | ALL option indicate the processor number for which statistics are to be reported. cpu is the processor number. Note that processor 0 is the first processor. The ALL keyword indicates that statistics are to be reported for all processors.

Output:

Linux 2.6.9-55.ELsmp (server.xyz.com)     06/11/2007

04:13:29 PM  CPU   %user   %nice %system %iowait    %irq   %soft   %idle    intr/s
04:13:29 PM  all    5.63    0.01    2.33    0.85    0.01    0.10   91.06   2255.03
04:13:29 PM    0    5.74    0.00    2.17    0.88    0.01    0.15   91.05   1170.16
04:13:29 PM    1    5.53    0.01    2.49    0.83    0.01    0.06   91.07   1084.87

Understanding mpstat output

The report generated by the mpstat command has the following format:

  • CPU: Processor number. The keyword all indicates that statistics are calculated as averages among all processors.
  • %user: Show the percentage of CPU utilization that occurred while executing at the user level (application).
  • %nice: Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.
  • %system: Show the percentage of CPU utilization that occurred while executing at the system level (kernel). Note that this does not include the time spent servicing
    interrupts or softirqs.
  • %iowait: Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
  • %irq: Show the percentage of time spent by the CPU or CPUs to service interrupts.
  • %soft: Show the percentage of time spent by the CPU or CPUs to service softirqs. A softirq (software interrupt) is one of up to 32 enumerated software interrupts
    which can run on multiple CPUs at once.
  • %idle: Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
  • intr/s: Show the total number of interrupts received per second by the CPU or CPUs.

Display five reports of global statistics among all processors at two second intervals, enter:

# mpstat 2 5

Display five reports of statistics for all processors at two second intervals, enter:

# mpstat -P ALL 2 5

Linux Check Memory Usage


How do I check used and free RAM memory usage under Linux operating systems using command line and GUI tools?

Linux comes with different set of commands to check memory usage. The free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. The vmstat command reports information about processes, memory, paging, block IO, traps, and cpu activity. Finally, you can use the top command which provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel.

free command


Display free memory size in MB:

$ free -mOutput:

             total       used       free     shared    buffers     cached
Mem:           750        625        125          0         35        335
-/+ buffers/cache:        254        496
Swap:          956          0        956
 
Displays a line containing the totals memory in MB:
$ free -t -m
Output:

       total       used       free     shared    buffers     cached
Mem:           750        625        125          0         35        335
-/+ buffers/cache:        253        496
Swap:          956          0        956
Total:        1707        625       1082
 

vmstat command


Type vmstat command at shell prompt:

$ vmstat
Output:

procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
1  0      0 131620  35432 341496    0    0    42    82  737  1364 15  3 81  1
 

top command


Type top command at the shell prompt:
$ top
Sample outputs:


Fig.01: top command displaying used memory

To exit from top command type q key. Read man page of free, vmstat, top command for more information.

GNOME Desktop: GUI Tool



The Gnome System Monitor application enables you to display basic system information and monitor system processes, usage of system resources, and file systems. You can also use System Monitor to modify the behavior of your system. You can start System Monitor by visiting System menu > Choose Administration > System Monitor option. Or type the following command at the shell prompt:

 
gnome-system-monitor
 
 
Sample outputs:


Fig.02: Linux See Memory Usage With GUI System Monitor Tool

Linux / UNIX: Restrict Access to A Given Command

How do I restrict access to a given command for instance /opt/apps/start, to authorized users only under Linux / UNIX / BSD operating system?




You need to use traditional Unix groups concept to enhance security including restricted access to a given command.

Step # 1: Create and Maintain a Group For All Authorized Users

 

Create a group named appsonly:
# groupadd appsonly
Add all authorized users to appsonly:
# usermod -aG {groupName} {userName}
# usermod -aG appsonly tom
# usermod -aG appsonly jerry
# id jerry

Where,

  1. -a : Add the user to the supplemental group(s) i.e. appends the user to the current supplementary group list.
  2. -G : A list of supplementary groups which the user is also a member of.

 

Step #2: Restrict Access


Now a group of user had been created. Next, use the chgrp command to change the group of /opt/apps/start to appsonly group:
# chgrp {groupName} {/path/to/command}
# chgrp appsonly /opt/apps/start


Disable the file permission for others


Finally, use the chmod command to change file permission as follows:
# chmod 750 /path/to/command
# chmod 750 /opt/apps/start

You can also apply permissions to directory (this will disable ls command access to others) :
# chgrp appsonly /opt/apps
# chmod 0640 /opt/apps


Step # 3: Test It


su to tom, enter:
# su - tom
$ id
$ /opt/apps/start
$ exit

su to vivek (not a member of appsonly group), enter:
# su - vivek
$ id
$ /opt/apps/start

Sample outputs:
bash: /opt/apps/start: Permission denied
 

A Note About ACL and SELinux


The access control policies which can be enforced by chmod, chgrp, and usermod commands are limited, and configuring SELinux and fille system ACLs (access control list) is a better and recommend option for large deployments.

How to collect Linux system utilization data into a file


I’ve already documented the procedure to find out CPU utilization under Linux and UNIX oses using various tools.

However I received a couple of email questions via email:

Howdo I collect Linux system utilization data into a file? How do I email the data or move to another computer?

To be frank you don’t have to do anything data is collected and stored in /var/log/sa location using sa1 and sa2 scripts. It is part of sadc - System activity data collector tools.

The sadc command samples system data a specified number of times ( count ) at a specified interval measured in seconds ( interval ). It writes in binary format to the specified output file.

The sa1 command is a shell procedure variant of the sadc command and handles all of the flags and parameters of that command. The sa1 command collects and store binary data in the /var/log/sa/sadd file, where the dd parameter indicates the current day. The interval and count parameters specify that the record should be written count times at interval seconds.

The sa1 command is designed to be started automatically by the cron command. Type the following command to list files:

# ls /var/log/sa
Output:

sa13  sa14  sa15  sa16  sa17  sa18  sa19  sa20  sa21  sar12  sar13  sar14  sar15  sar16  sar17  sar18  sar19  sar20

How do I copy log files?

You can copy all these logs files using ssh/scp or ftp to another computer. You can run use sar command to read binary raw data files, enter
# sar -f sa13
Output:

Linux 2.6.9-55.ELsmp (monster.labs.nixcraft.in)     05/13/2007


12:00:02 AM       CPU     %user     %nice   %system   %iowait     %idle
12:10:01 AM       all     19.75      0.00      2.29      7.49     70.48
12:20:01 AM       all      2.28      0.00      0.27      0.06     97.39
12:30:01 AM       all      2.58      0.00      0.32      0.07     97.02
12:40:02 AM       all     16.05      0.00      3.12     13.48     67.36
12:50:01 AM       all     10.78      0.00      1.20      3.61     84.41
01:00:01 AM       all      2.42      0.00      0.29      0.30     96.99
01:10:01 AM       all      3.70      0.00      0.42      0.42     95.47
01:20:01 AM       all      2.47      0.00      0.28      0.14     97.11
01:30:01 AM       all      3.20      0.00      0.31      0.15     96.34
01:40:01 AM       all      2.46      0.00      0.27      0.07     97.20
01:50:01 AM       all      2.40      0.00      0.26      0.10     97.24
....
.....