linux下如何查看硬件配置和 常用的命令

网卡信息

1) dmesg | grep -i 'eth'

2) cat /etc/sysconfig/hwconf | grep -i eth

3) lspci | grep -i 'eth'

6, 鼠标键盘和USB信息

查看键盘和鼠标:cat /proc/bus/input/devices

查看USB设备:cat /proc/bus/usb/devices

查看各设备的中断请求(IRQ):cat /proc/interrupts

7, 显卡信息

1)lspci |grep -i 'VGA'

linux下如何查看硬件配置和常用的命令

一、查看操作系统的版本和机器型号 

1、查看操作系统的版本 

2、查看机器型号 

3、查看所有硬件的信息 

二、查看硬件的详细情况 

1、查看内存大小 

2、查看CPU信息(型号)等 

3、查看硬盘及分区情况 

4、查看网卡信息 

三、常用的一些服务器维护命令 

1、查看内存使用情况 

2、服务器磁盘使用情况 

3、查看服务器的平均负载 

4、查看系统整体性能情况 

5、查看系统已载入的相关模块 

6、如何查找PCI设置 

7、解决linux默认root用户不能直接远程登录问题 

四、linux常用的命令 

1、启动,关机命令 

2、Shell相关命令 

3、用户管理相关命令 

4、系统相关命令 

5、文件操作相关命令 

6、文件编辑相关命令 

7、压缩/解压相关命令 

8、控制外设的相关命令 

9、进程及任务相关命令 

linux下如何查看硬件配置和常用的命令

由于公司用的linux服务器挺多,大家不像用widows那样常用,很多新同事可能对linux不是很熟悉,而要安装好多软件又不像windows那样直接双击就行,需要了解机器的硬件信息和系统版本等,故写了本文,希望能抛砖引玉。

一、查看操作系统的版本和机器型号

1、查看操作系统的版本

[root@testes5 etc]# uname –a(此命令在UNIX下也通用)

Linux testes5 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:12 EDT 2008 i686 i686 i386 GNU/Linux

2.6.18-92.el5这里显示了系统内核的版本,el5说明本系统是Enterprise Linux5,对于redhat linux也可以用下面的命令查看到系统的详细版本号:

[root@testes5 etc]# more /etc/redhat-release

Red Hat Enterprise Linux Server release 5.2 (Tikanga)

[root@testes5 etc]# cat /etc/issue | grep Linux

Red Hat Enterprise Linux Server release 5.2 (Tikanga)

或是:[root@testes5 ~]# lsb_release -a

LSB Version:    :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch

Distributor ID: RedHatEnterpriseServer

Description:    Red Hat Enterprise Linux Server release 5.2 (Tikanga)

Release:        5.2

Codename:       Tikanga

2、查看机器型号

[root@testes5 etc]#  dmidecode | grep "Product Name"

        Product Name: VMware Virtual Platform

        Product Name: 440BX Desktop Reference Platform

3、查看所有硬件的信息

[root@testes5 ~]# dmidecode | more

# dmidecode 2.7

SMBIOS 2.31 present.

45 structures occupying 1654 bytes.

Table at 0x000E0010.

Handle 0x0000, DMI type 0, 20 bytes.

BIOS Information

        Vendor: Phoenix Technologies LTD

        Version: 6.00

        Release Date: 12/06/2006

        Address: 0xE78A0

        Runtime Size: 100192 bytes

        ROM Size: 64 kB

        Characteristics:

                ISA is supported

                PCI is supported

                PC Card (PCMCIA) is supported

                PNP is supported

                APM is supported

                BIOS is upgradeable

                BIOS shadowing is allowed

                ESCD support is available

                USB legacy is supported

                Smart battery is supported

                BIOS boot specification is supported

Handle 0x0001, DMI type 1, 25 bytes.

System Information

        Manufacturer: VMware, Inc.

        Product Name: VMware Virtual Platform

        Version: None

        Serial Number: VMware-56 4d 35 c4 fd a8 d4 12-f5 82 c5 a7 17 c6 24 7e

        UUID: 564D35C4-FDA8-D412-F582-C5A717C6247E

        Wake-up Type: Power Switch

Handle 0x0002, DMI type 2, 8 bytes.

Base Board Information

        Manufacturer: Intel Corporation

        Product Name: 440BX Desktop Reference Platform

        Version: None

        Serial Number: None


Handle 0x0003, DMI type 3, 17 bytes.

Chassis Information

        Manufacturer: No Enclosure

        Type: Other

        Lock: Not Present

        Version: N/A

        Serial Number: None

--More—

二、查看硬件的详细情况

1、查看内存大小

[root@testes5 ~]# cat /proc/meminfo|more

MemTotal:       515492 kB

MemFree:         33968 kB

Buffers:         33924 kB

Cached:         278224 kB

SwapCached:          0 kB

Active:         197136 kB

Inactive:       253448 kB

HighTotal:           0 kB

HighFree:            0 kB

LowTotal:       515492 kB

LowFree:         33968 kB

SwapTotal:      786424 kB

SwapFree:       786424 kB

Dirty:              16 kB

Writeback:           0 kB

AnonPages:      138440 kB

Mapped:          42928 kB

Slab:            21492 kB

PageTables:       3860 kB

NFS_Unstable:        0 kB

Bounce:              0 kB

CommitLimit:   1044168 kB

Committed_AS:   537668 kB

VmallocTotal:   507896 kB

VmallocUsed:      4316 kB

VmallocChunk:   503420 kB

HugePages_Total:     0

HugePages_Free:      0

HugePages_Rsvd:      0

Hugepagesize:     4096 kB

2、查看CPU信息(型号)等

Processor Information

[root@testes5 ~]# cat /proc/cpuinfo

processor       : 0

vendor_id       : GenuineIntel

cpu family      : 6

model           : 15

model name      : Intel(R) Core(TM)2 Duo CPU     T7250  @ 2.00GHz

stepping        : 8

cpu MHz         : 1994.661

cache size      : 2048 KB

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 10

wp              : yes

flags           : fpu vme de pse tsc sr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss nx lm constant_tsc up ida pni ds_cpl cx16 lahf_lm

bogomips        : 3994.07

这样可以完整的看到当前机器的cpu信息

[root@localhost ~]#  cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c

Intel(R) Xeon(TM) CPU 3.00GHz

这里能看到CPU的型号和逻辑cpu的个数是4个

[root@localhost ~]#  cat /proc/cpuinfo | grep physical | uniq -c

      2 physical id     : 0

      2 physical id     : 3

从这里可以看出该机器有两颗物理cpu

[root@testes5 ~]# getconf LONG_BIT

32

这里显示32说明CPU当前运行在32位模式下,但不能凭这个说该CPU不支持64位。

[root@testes5 ~]# cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l

1

结果大于0,说明支持64位计算. lm指long mode,支持lm则是支持64位。

3、查看硬盘及分区情况

[root@testes5 /etc]# fdisk -l

Disk /dev/hda: 6442 MB, 6442450944 bytes

255 heads, 63 sectors/track, 783 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System

/dev/hda1   *           1          13      104391   83  Linux

/dev/hda2              14         783     6185025   8e  Linux LVM

4、查看网卡信息

[root@testes5 etc]#  dmesg | grep -i eth

eth0: registered as PCnet/PCI II 79C970A

eth0: link up

eth0: no IPv6 routers present

eth0: link up

eth0: no IPv6 routers present

eth0: link up

eth0: no IPv6 routers present

eth0: link up

eth0: no IPv6 routers present

eth0: link up

eth0: no IPv6 routers present

查看网络配置信息:

[root@testes5 etc]# ifconfig -a

eth0      Link encap:Ethernet  HWaddr 00:0C:29:C6:24:7E  

          inet addr:10.87.58.71  Bcast:10.87.58.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fec6:247e/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:3364 errors:0 dropped:0 overruns:0 frame:0

          TX packets:1347 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:248507 (242.6 KiB)  TX bytes:201769 (197.0 KiB)

          Interrupt:169 Base address:0x2000


lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:2526 errors:0 dropped:0 overruns:0 frame:0

          TX packets:2526 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:3806446 (3.6 MiB)  TX bytes:3806446 (3.6 MiB)

sit0      Link encap:IPv6-in-IPv4  

          NOARP  MTU:1480  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

或是查看如下文件:

[root@testes5 network-scripts]# more /etc/sysconfig/network-scripts/ifcfg-eth0

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

DEVICE=eth0

BOOTPROTO=none

BROADCAST=10.87.58.255

HWADDR=00:0C:29:C6:24:7E

IPADDR=10.87.58.71

NETMASK=255.255.255.0

NETWORK=10.87.58.0

ONBOOT=yes

TYPE=Ethernet

USERCTL=no

IPV6INIT=no

PEERDNS=yes

查看机器名:

[root@testes5 etc]# hostname

testes5

或:[root@testes5 network-scripts]# more /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=no

HOSTNAME=testes5

查看机器的DNS配置:

[root@testes5 network-scripts]# more /etc/resolv.conf

nameserver 202.102.224.68

nameserver 202.102.227.68

三、常用的一些服务器维护命令

Linux下最常用的查看机器性能的命令是top,具体显示如下,能看到cpu和内存负载

 [root@testes5 /etc]# top

top - 02:11:32 up  1:38,  3 users,  load average: 0.07, 0.06, 0.18

Tasks: 133 total,   2 running, 126 sleeping,   4 stopped,   1 zombie

Cpu(s):  0.0%us,  0.7%sy,  0.0%ni, 98.7%id,  0.3%wa,  0.3%hi,  0.0%si,  0.0%st

Mem:    515492k total,   509400k used,     6092k free,    26300k buffers

Swap:   786424k total,        0k used,   786424k free,   287908k cached

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

 8377 root      15   0 35692  10m 5892 S  0.3  2.0   1:22.50 Xorg                                                                   

 8606 root      15   0 98052  12m 9756 S  0.3  2.5   0:01.49 mixer_applet2                                                          

    1 root      15   0  2060  648  556 S  0.0  0.1   0:00.67 init                                                                   

    2 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 migration/0                                                            

    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0                                                            

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

    5 root      10  -5     0    0    0 S  0.0  0.0   0:00.06 events/0                                                               

    6 root      16  -5     0    0    0 S  0.0  0.0   0:00.00 khelper                                                                

    7 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 kthread                                                                

   10 root      10  -5     0    0    0 S  0.0  0.0   0:00.23 kblockd/0                                                              

   11 root      20  -5     0    0    0 S  0.0  0.0   0:00.00 kacpid                                                                 

   72 root      20  -5     0    0    0 S  0.0  0.0   0:00.00 cqueue/0                                                               

   75 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 khubd                                                                  

   77 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 kseriod                                                                

  141 root      25   0     0    0    0 S  0.0  0.0   0:00.00 pdflush                                                                

  142 root      15   0     0    0    0 S  0.0  0.0   0:00.15 pdflush                                                                

  143 root      10  -5     0    0    0 S  0.0  0.0   0:00.15 kswapd0                                                                

  144 root      20  -5     0    0    0 S  0.0  0.0   0:00.00 aio/0                                                                  

  301 root      11  -5     0    0    0 S  0.0  0.0   0:00.00 kpsmoused                                                              

  325 root      16  -5     0    0    0 S  0.0  0.0   0:00.00 ata/0                                                                  

  326 root      16  -5     0    0    0 S  0.0  0.0   0:00.00 ata_aux                                                                

  337 root      20  -5     0    0    0 S  0.0  0.0   0:00.00 ksnapd                                                                 

  340 root      10  -5     0    0    0 S  0.0  0.0   0:01.38 kjournald                                                              

  373 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 kauditd                                                                

  407 root      14  -4  2988 1572  488 S  0.0  0.3   0:01.48 udevd                                                                  

  868 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 kgameportd                                                             

 3780 root      14  -5     0    0    0 S  0.0  0.0   0:00.00 kmpathd/0                                                              

 3804 root      11  -5     0    0    0 S  0.0  0.0   0:00.00 kjournald                                                              

 6374 root      15   0  5768 1464 1188 S  0.0  0.3   0:00.25 bash                                                                   

 7202 root      12  -5     0    0    0 S  0.0  0.0   0:00.00 ib_mcast                                                               

 7203 root      12  -5     0    0    0 S  0.0  0.0   0:00.00 ib_inform                                                              

 7204 root      12  -5     0    0    0 S  0.0  0.0   0:00.00 local_sa                                                               

 7210 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 ib_addr                                                                

 7216 root      12  -5     0    0    0 S  0.0  0.0   0:00.00 iw_cm_wq                                                               

 7222 root      12  -5     0    0    0 S  0.0  0.0   0:00.00 ib_cm/0                                                                

 7228 root      13  -5     0    0    0 S  0.0  0.0   0:00.00 rdma_cm                                                                

 7258 root      12  -5     0    0    0 S  0.0  0.0   0:00.00 ipoib                                                                  

 7264 root      12  -5     0    0    0 S  0.0  0.0   0:00.00 sdp                                                                    

 7547 root      16  -3 12128  648  488 S  0.0  0.1   0:00.03 auditd                                                                 

 7549 root      12  -3 12048  648  556 S  0.0  0.1   0:00.02 audispd                                                                

 7566 root      15   0 10240 8576  244 S  0.0  1.7   0:00.01 restorecond                                                            

 7577 root      18   0  1716  612  516 S  0.0  0.1   0:00.16 syslogd                                                                

 7580 root      15   0  1668  396  332 S  0.0  0.1   0:00.03 klogd                                                                  

此命令可以看到包括机器的cpu和内存的负载情况

1、查看内存使用情况

[root@testes5 /etc]# free -m

             total       used       free     shared    buffers     cached

Mem:        503        497        6         0       25        280

-/+ buffers/cache:          190        312

Swap:        767         0         767

参数解释:这里的大小是按M显示的

Total:内存总数

Used:已经使用的内存数

free:空闲的内存数

shared:多个进程共享的内存总额

buffers:Buffer Cache和cached Page Cache 磁盘缓存的大小

buffers/cache (已用)的内存数:used - buffers - cached

+buffers/cache(可用)的内存数:free + buffers + cached

可用的内存=free memory+buffers+cached

另一个命令可以用top

2、服务器磁盘使用情况

有时感觉硬盘反应很慢,或需要查看日志所在分区时,下列命令可以查看磁盘的使用情况,很有用:

A、查看当前硬盘使用情况

[root@testes5 /etc]# df -h

文件系统容量已用可用已用%挂载点

/dev/mapper/VolGroup00-LogVol00

                      5.0G  3.9G  907M  82% /

/dev/hda1              99M   12M   83M  13% /boot

tmpfs                 252M     0  252M   0% /dev/shm

/dev/hdc              950M  950M     0 100% /media/syshbkcd

B、查看硬盘性能:

[root@localhost ~]# iostat -x 1 10

Linux 2.6.9-34.ELsmp (localhost.localdomain)    12/14/2010

avg-cpu:  %user   %nice    %sys %iowait   %idle

           0.03    0.00    0.01    0.02   99.95

Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util

cciss/c0d0   0.00   0.36  0.01  0.24    0.86    4.83     0.43     2.42    22.89     0.01   46.80   5.29   0.13

dm-0         0.00   0.00  0.01  0.60    0.86    4.83     0.43     2.42     9.27     0.02   32.07   2.14   0.13

参数解释:

Tps该设备每秒I/O传输的次数(每秒的I/O请求)

Blk_read/s表求从该设备每秒读的数据块数量

Blk_wrth/s表示从该设备每秒写的数据块数量

3、查看服务器的平均负载

感觉到系统压力较大时用可top或uptime查看下服务器的平均负载。

[root@localhost ~]# uptime

15:01:56 up 245 days,  1:32,  3 users,  load average: 0.00, 0.00, 0.00

uptime的另一个用法是查看你的Linux服务器已经稳定运行多少天没有重启了.

4、查看系统整体性能情况

如果感觉系统比较繁忙,可以用vmstat查看系统整体性能情况。vmstat不仅仅适应于linux系统,它同样适用于unix系统。

[root@localhost ~]# vmstat 1 2

procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----

 r  b   swpd   free   buff  cache       si   so     bi    bo   in    cs  us  sy  id  wa

 0  0      0 112032  74456 3758984     0    0     0     0    0     0  0   0  100  0

 0  0      0 112032  74456 3758984     0    0     0     0   1006   20  0  0  100  0

如果r经常大于 4 ,且id经常少于40,表示cpu的负荷很重。

如果pi,po 长期不等于0,表示内存不足。

如果disk经常不等于0,且在 b中的队列 大于3,表示io性能不好.

5、查看系统已载入的相关模块

Linux操作系统的核心具有模块化的特性,因此在编译核心时,务须把全部的功能都放入核心。可以用以下命令查看linux已经加载的模块:

[root@testes5 ~]# lsmod

Module                  Size  Used by

nls_utf8                6209  1

autofs4                24517  2

hidp                   23105  2

rfcomm                 42457  0

l2cap                  29505  10 hidp,rfcomm

bluetooth              53797  5 hidp,rfcomm,l2cap

sunrpc                144893  1

ib_iser                34453  0

libiscsi               30401  1 ib_iser

scsi_transport_iscsi    31689  2 ib_iser,libiscsi

ib_srp                 32729  0

ib_sdp                 51593  0

ib_ipoib               74345  0

rdma_ucm               16449  0

ib_ucm                 19653  0

ib_uverbs              34921  2 rdma_ucm,ib_ucm

ib_umad                19049  0

rdma_cm                34293  3 ib_iser,ib_sdp,rdma_ucm

ib_cm                  34861  4 ib_srp,ib_ipoib,ib_ucm,rdma_cm

iw_cm                  13125  1 rdma_cm

ib_addr                11845  1 rdma_cm

ib_sa                  38581  4 ib_srp,ib_ipoib,rdma_cm,ib_cm

ib_mad                 37717  3 ib_umad,ib_cm,ib_sa

ib_core                54465  13 ib_iser,ib_srp,ib_sdp,ib_ipoib,rdma_ucm,ib_ucm,ib_uverbs,ib_umad,rdma_cm,ib_cm,iw_cm,ib_sa,ib_mad

dm_multipath           22089  0

video                  21193  0

sbs                    18533  0

backlight              10049  1 video

i2c_ec                  9025  1 sbs

button                 10705  0

battery                13637  0

asus_acpi              19288  0

ac                      9157  0

ipv6                  258273  17 ib_ipoib

xfrm_nalgo             13765  1 ipv6

crypto_api             11969  1 xfrm_nalgo

lp                     15849  0

floppy                 57125  0

snd_ens1371            28513  1

gameport               18633  1 snd_ens1371

snd_rawmidi            26561  1 snd_ens1371

snd_ac97_codec         93025  1 snd_ens1371

ac97_bus                6337  1 snd_ac97_codec

snd_seq_dummy           7877  0

snd_seq_oss            32577  0

snd_seq_midi_event     11073  1 snd_seq_oss

snd_seq                49585  5 snd_seq_dummy,snd_seq_oss,snd_seq_midi_event

snd_seq_device         11725  4 snd_rawmidi,snd_seq_dummy,snd_seq_oss,snd_seq

snd_pcm_oss            42945  0

snd_mixer_oss          19009  1 snd_pcm_oss

snd_pcm                72005  3 snd_ens1371,snd_ac97_codec,snd_pcm_oss

pcnet32                35141  0

mii                     9409  1 pcnet32

i2c_piix4              12237  0

snd_timer              24517  2 snd_seq,snd_pcm

snd                    52421  12 snd_ens1371,snd_rawmidi,snd_ac97_codec,snd_seq_oss,snd_seq,snd_seq_device,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_timer

soundcore              11553  1 snd

snd_page_alloc         14281  1 snd_pcm

pcspkr                  7105  0

i2c_core               23745  2 i2c_ec,i2c_piix4

ide_cd                 40033  1

parport_pc             29157  1

cdrom                  36705  1 ide_cd

parport                37513  2 lp,parport_pc

serio_raw              10693  0

dm_snapshot            21477  0

dm_zero                 6209  0

dm_mirror              29125  0

dm_mod                 61405  9 dm_multipath,dm_snapshot,dm_zero,dm_mirror

ata_piix               22341  0

libata                143997  1 ata_piix

sd_mod                 24897  0

scsi_mod              134605  6 ib_iser,libiscsi,scsi_transport_iscsi,ib_srp,libata,sd_mod

ext3                  123593  2

jbd                    56553  1 ext3

uhci_hcd               25421  0

ohci_hcd               23261  0

ehci_hcd               33357  0

例如以下用法查看是否被正确加载:

[root@testes5 ~]# lsmod | grep ipv6

ipv6                  258273  17 ib_ipoib

xfrm_nalgo             13765  1 ipv6

6、如何查找PCI设置

有时需要在Linux下查找PCI设置,可用lspci命令:

[root@testes5 ~]# lspci

00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)

00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01)

00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)

00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)

00:07.2 USB Controller: Intel Corporation 82371AB/EB/MB PIIX4 USB

00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)

00:0f.0 VGA compatible controller: VMware Inc Abstract SVGA II Adapter

00:10.0 SCSI storage controller: BusLogic BT-946C (BA80C30) [MultiMaster 10] (rev 01)

00:11.0 PCI bridge: VMware Inc Unknown device 0790 (rev 01)

02:00.0 Ethernet controller: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rev 10)

02:01.0 Multimedia audio controller: Ensoniq ES1371 [AudioPCI-97] (rev 02)

02:02.0 USB Controller: VMware Inc Abstract USB2 EHCI Controller

它可以列出机器中的PCI设备,比如声卡、显卡、Modem、网卡等,主板集成设备也能列出来。这个命令最常见的用法是查看网卡型号:

[root@testes5 ~]#  lspci | grep Ethernet

02:00.0 Ethernet controller: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rev 10)

7、解决linux默认root用户不能直接远程登录问题

[root@localhost pam.d]#vi /etc/pam.d/login

#%PAM-1.0

auth       required     pam_securetty.so

auth       required     pam_stack.so service=system-auth

auth       required     pam_nologin.so

account    required     pam_stack.so service=system-auth

password   required     pam_stack.so service=system-auth

# pam_selinux.so close should be the first session rule

session    required     pam_selinux.so close

session    required     pam_stack.so service=system-auth

session    required     pam_loginuid.so

session    optional     pam_console.so

# pam_selinux.so open should be the last session rule

session    required     pam_selinux.so open

注释掉这行 

#auth        required     pam_securetty.so    //该行注释掉

注意:linux默认的登录协议是ssh2,不是telnet,如果要用telnet登录linux则需要先确认你的服务器安装并开启了telnet server的服务,并且确认配置了允许telnet登录,具体命令如下:

[root@testes5 hda]# rpm -qa telnet

telnet-0.17-39.el5

[root@testes5 hda]# rpm -qa telnet-server

telnet-server-0.17-39.el5

[root@testes5 hda]# more /etc/xinetd.d/telnet

# default: on

# description: The telnet server serves telnet sessions; it uses \

#       unencrypted username/password pairs for authentication.

service telnet

{

        disable =yes

        flags           = REUSE

        socket_type     = stream        

        wait            = no

        user            = root

        server          = /usr/sbin/in.telnetd

        log_on_failure  += USERID

        #disable                = yes

}

默认{后面是disable=yes,需要加#注释掉,或者改为disable=no disable = no

四、linux常用的命令

首先需要注意的是linux的命令参数是区分大小写的。

1、启动,关机命令

[shutdown]停止系统

[halt]停止系统

[reboot]重启动

[poweroff]切断电源

[sync]把内存里的内容写入磁盘

[init]将系统启动到对应的运行级别

2、Shell相关命令

[csh] [bash] 切换Shell

[history] 显示历史命令

[which] 显示命令所在位置

[echo] 显示字符串或者变量内容

[set] 设置/显示Shell变量

[printenv] 显示环境变量

[export] 设置环境变量

[env] 设置临时环境变量

[setenv] 设置环境变量

[unsetenv]释放环境变量

[man]查询命令或是帮助,经常用来查看某个命令的手册或是具体使用示例,例如:

[root@testes5 hda]# man ls

LS(1)                            User Commands                           LS(1)


NAME

       ls - list directory contents


SYNOPSIS

       ls [OPTION]... [FILE]...


DESCRIPTION

       List  information  about  the FILEs (the current directory by default).  Sort entries alphabetically if none of

       -cftuvSUX nor --sort.


       Mandatory arguments to long options are mandatory for short options too.


       -a, --all

              do not ignore entries starting with .


3、用户管理相关命令

[su] 切换到其他用户

[useradd] 追加用户

[userdel] 删除用户

[usermod] 修改用户设置

[groupadd] 添加用户组

[groupdel] 删除用户组

[groupmod] 修改组设置

[passwd] 更改密码

[id] 显示指定用户的ID信息

4、系统相关命令

[date]显示/设置当前时间

[last]显示用户登录/登出信息

[lastb]显示非法登录信息

[df]查询磁盘使用信息

[du]查询磁盘使用信息

[dmesg]显示系统启动消息

[sysunconfig]取消或是还原系统的一些基础配置并进行重新配置,例如主机名,IP,时区,语言等

5、文件操作相关命令

[ls]显示文件列表

常用参数解释:

-l以长格式列出文件,包括文件大小、日期和时间、属性

-t对文件以时间排序

-S对文件以大小排序

-r与一个排序开关组合起来使用,逆序排列。

-t将最新的文件显示在列表的顶部。

-h使用 k、M、G 等来标识文件的大小,而不是以字节为单位。

-a显示目录中所有的文件,包括隐藏文件

[pwd]显示当前路径

[cd]更改当前路径

[mkdir]创建路径

[rmdir]删除路径

[cp]复制文件/目录

常用参数解释:

-R 递归地复制文件;当需要复制整个目录时会用到

-f 强制复制并覆盖已有的文件,不询问用户

-l 链接文件,而不是复制;见下面的说明

[rm]删除文件/目录

常用参数解释:

-d 删除目录

-r或是-R强制删除目录及目录中的文件

[mv]移动文件/目录,修改文件名

[chown]更改文件/目录的所有者

[chgrp]修改文件/目录的所有组

[chmod]修改文件/目录的权限

[ln]建立文件/目录链接

ln默认创建的是硬链接。使用-s参数可以创建符号链接。

[find]查找文件

[whereis]显示文件存在的路径名

[file]查询文件种类

6、文件编辑相关命令

[cat]显示文件内容

[more]分屏显示文件内容

[head]显示文件头部内容

[tail]显示文件尾部内容

[sort]排列文件的行,本命令经常用来做系统文件系统满了查找大文件进行删除,非常有用

[wc]统计文本单词数,文件大小等,也经常用来统计进程数,和ps合用

[vi] vi文字编辑器,修改文件内容,很好用的一个编辑器

7、压缩/解压相关命令

[tar]压缩/解压缩文件

[compress]压缩/解压缩文件

[uncompress]解压缩

[gzip]压缩/解压缩文件

[gunzip]解压缩

8、控制外设的相关命令

[mount] 挂载设备,经常用来挂载阵列或是磁盘

[umount]解除已经mount上的设备

[eject]弹出(CD/DVD等)

[fdisk]配置/显示硬盘分区

[mkfs]格式化磁盘分区

[fsck]检查/修复磁盘错误,这个在机器突然断电或是重启后硬盘报错时比较常用,对磁盘坏块进行修复

[ifconfig]显示/设定NIC配置,主要用来查看和配置网卡,也常用来进行临时设置机器的IP地址

9、进程及任务相关命令

[ps]显示正在运行的进程

[kill]中止进程或任务

[killall]中止进程或任务

[nohup]在后台执行任务,Logout之后也不退出,经常和&连用,将进程置于后台运行

[crontab]设置程序或是脚本定期或是运行,类似windows的计划任务,对于自动化维护服务器或是定时执行程序非常有用

10、网络类相关命令

[netstat]显示当前网络连接状况,常见的用法是:

netstat –an查看主机上开放的端口

netstat –rn查看主机上网络和路由配置

[route]显示/设置路由

[host]显示网络主机情况

[hostname]显示/设置当前主机的名字

[ping]确认和远程机器的连接情况

[traceroute]显示路由信息

[telnet]用telnet登陆到远程机器

[ftp]用ftp传输文件

[setup] 配置系统一些参数,一般这个命令经常用来打开或是关闭linux的防火墙,或是配置主机IP,或是配置或取消开机要运行的服务


网卡信息

1) dmesg | grep -i 'eth'

2) cat /etc/sysconfig/hwconf | grep -i eth

3) lspci | grep -i 'eth'

6,鼠标键盘和USB信息

查看键盘和鼠标:cat /proc/bus/input/devices

查看USB设备:cat /proc/bus/usb/devices

查看各设备的中断请求(IRQ):cat /proc/interrupts

7,显卡信息

1)lspci |grep -i 'VGA'

1. lshw

  lshw命令显示详细硬件信息。如果要用概要方式显示,可以加上short参数:lshw -short

  要显示指定硬件信息,加上class(或C)参数:lshw -class memory

  2. sysstat

  3.查看PCI信息:lspci -v (相比cat /proc/pci更直观)。lspci 是读取 hwdata 数据库,hwdata 由软件包 hwdata 提供。

  4.查看系统体系结构:uname -a

  5. dmidecode查看硬件信息,包括bios、cpu、内存等信息

  6. dmesg是一个显示内核缓冲区系统控制信息的工具;比如系统在启动时的信息会写到/var/log/.

  注:dmesg工具并不是专门用来查看硬件芯片组标识的工具,但通过这个工具能让我们知道机器中的硬件的一些参数;因为系统在启动的时候,会写一些硬件相关的日志到 /var/log/message* 或 /var/log/boot* 文件中。

  7. lshal和 hal-device-manager

  8.查看 /proc

  对于“/proc”中文件可使用文件查看命令浏览其内容,文件中包含系统特定信息:

  Cpuinfo主机CPU信息

  Dma主机DMA通道信息

  Filesystems文件系统信息

  Interrupts主机中断信息

  Ioprots主机I/O端口号信息

  Meninfo主机内存信息

  Version Linux内存版本信息

  查看CPU信息:cat /proc/cpuinfo

  查看板卡信息:cat /proc/pci

  查看内存信息:cat /proc/meminfo

  查看USB设备:cat /proc/bus/usb/devices

  查看键盘和鼠标:cat /proc/bus/input/devices

  查看各设备的中断请求(IRQ):cat /proc/interrupts

 # cat /etc/issue | grep Linux

    Red Hat Enterprise Linux AS release 4 (Nahant Update 5)

(查看当前操作系统发行版信息

你可能感兴趣的:(linux下如何查看硬件配置和 常用的命令)