一

{"type":"编程笔记"}


  • Home

  • Archives
  • Search

linux 常用命令之 硬件查看命令

Posted on 2018-06-11   |   In linux

Linux 查看硬件信息的命令

  • hwinfo
  • lshw
  • lscpu
  • lspci
  • lsscsi
  • lsblk
  • df
  • fdisk
  • free
  • dmidecode

lshw -short

 lshw -shortH/W path        Device      Class      Description==================================================                            system     Standard PC (i440FX + PIIX, 1996)/0                          bus        Motherboard/0/0                        memory     96KiB BIOS/0/400                      processor  Virtual CPU 714389bda930/0/1000                     memory     512MiB System Memory/0/1000/0                   memory     512MiB DIMM RAM/0/100                      bridge     440FX - 82441FX PMC [Natoma]/0/100/1                    bridge     82371SB PIIX3 ISA [Natoma/Triton II]/0/100/1.1                  storage    82371SB PIIX3 IDE [Natoma/Triton II]/0/100/1.2                  bus        82371SB PIIX3 USB [Natoma/Triton II]/0/100/1.2/1    usb1        bus        UHCI Host Controller/0/100/1.2/1/1              input      QEMU USB Tablet/0/100/1.3                  bridge     82371AB/EB/MB PIIX4 ACPI/0/100/2                    display    GD 5446/0/100/3                    network    Virtio network device/0/100/3/0      ens3        network    Ethernet interface/0/100/4                    storage    Virtio block device/0/100/4/0      /dev/vda    disk       21GB Virtual I/O device/0/100/4/0/1    /dev/vda1   volume     19GiB EXT4 volume/0/100/5                    generic    Virtio memory balloon/0/100/5/0                  generic    Virtual I/O device/0/100/6                    generic    Virtio RNG/0/100/6/0                  generic    Virtual I/O device/0/1            scsi1       storage/0/1/0.0.0      /dev/cdrom  disk       QEMU DVD-ROM

hwinfo --short

 hwinfo --shortcpu:                       Virtual CPU 714389bda930, 2400 MHzkeyboard:  /dev/input/event1    AT Translated Set 2 keyboardmouse:  /dev/input/mice      Adomax QEMU USB Tablet  /dev/input/mice      VirtualPS/2 VMware VMMouse  /dev/input/mice      VirtualPS/2 VMware VMMousegraphics card:                       Red Hat QEMU Virtual Machinestorage:                       Floppy disk controller                       Red Hat Qemu virtual machine                       Virtio Storage 0network:  ens3                 Virtio Ethernet Card 0network interface:  ens3                 Ethernet network interface  lo                   Loopback network interfacedisk:  /dev/vda             Diskpartition:  /dev/vda1            Partitioncdrom:  /dev/sr0             QEMU DVD-ROMusb controller:                       Red Hat QEMU Virtual Machinebios:                       BIOSbridge:                       Red Hat Qemu virtual machine                       Red Hat Qemu virtual machine                       Red Hat Qemu virtual machinehub:                       Linux Foundation 1.1 root hubmemory:                       Main Memoryunknown:                       FPU                       DMA controller                       PIC                       Keyboard controller                       PS/2 Controller                       Red Hat Virtio network device                       Red Hat Virtio RNG                       Red Hat Virtio memory balloon                       Red Hat Virtio block device                       Virtio Unclassified device                       Virtio Unclassified device
Read more »

linux 常用命令之 ps

Posted on 2018-06-10   |   In linux

tldr ps

 tldr psInformation about running processes.  - List all running processes:    ps aux  - List all running processes including the full command string:    ps auxww  - Search for a process that matches a string:    ps aux | grep string  - List all processes of the current user in extra full format:    ps --user $(id -u) -F  - List all processes of the current user as a tree:    ps --user $(id -u) f  - Get the parent pid of a process:    ps -o ppid= -p pid  - To see every process on the system using standard syntax:    ps -e    ps -ef    ps -eF    ps -ely  - To see every process on the system using BSD syntax:    ps ax    ps axu  - To print a process tree:    ps -ejH    ps axjf  - To get info about threads:    ps -eLf    ps axms  - To get security info:    ps -eo euser,ruser,suser,fuser,f,comm,label    ps axZ    ps -eM  - To see every process running as root (real & effective ID) in user format:    ps -U root -u root u  - To see every process with a user-defined format:    ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm    ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm    ps -eopid,tt,user,fname,tmout,f,wchan  - Print only the process IDs of syslogd:    ps -C syslogd -o pid=  - Print only the name of PID 42:    ps -q 42 -o comm=

ps 命令参数语法

ps命令的参数支持三种语法格式:

  1. UNIX options, which may be grouped and must be preceded by a dash -.
  2. BSD options, which may be grouped and must not be used with a dash -.
  3. GNU long options, which are preceded by two dashes --.

ps 命令行 UNIX 风格参数简单说明

  1. 部分参数是为了在所有进程中选择参数指定的那部分进程,如-e显示全部进程
  2. 部分参数是为控制输出结果的,如-o控制字段显示
  3. 部分参数是最后对前面的输出结果进行修正的,如--sort按指定字段排序

这里只显示了部分参数的简单说明,不是全部参数,更多的可以看官方手册说明man ps。

ps 进程选择相关的参数

  1. -C 以指定命令显示
  2. -A 显示所有进程(等价于-e)
  3. -e 显示全部进程,同-A
  4. -g grplist 按组 id 或者组名显示
  5. -p pidlist 按进程 id 显示
  6. -u userlist 按用户id或者是用户名显示
  7. -t ttylist 按 tty 显示

ps 输出字段相关的参数

  1. -f 全部列出,通常和其他选项联用,如:ps -fa 或者 ps -fx
  2. -F 显示-f之外的一些字段
  3. -l 显示的字段更多些,常用如:ps -ely
  4. -o 用户自定义显示字段格式
  5. -O 除用户自定义显示字段,还有默认显示的一些字段

ps 输出结果修改参数

  1. -H 显示进程的层次(和其它的命令合用,如:ps -Ha 或者 ps -ejH)
  2. --sort 按指定字段排序,如:ps jax --sort=uid,-ppid,+pid

ps -o 用户自定义输出字段格式说明

这里只简单列出来ps -o支持的标准格式中的部分字段及简短说明,ps另外支持 AIX 的字段格式输出。

| CODE       |  HEADER    | DESCRIPTION---------------------------------------------------------------------------------------------------------------------------------------------------| %cpu       |  %CPU      | cpu utilization of the process in "##.#" format. (alias pcpu)| %mem       |  %MEM      | ratio of the process's resident set size to the physical memory on the machine, expressed as a percentage. (alias pmem).| args       |  COMMAND   | command with all its arguments as a string.| bsdstart   |  START     | time the command started.| bsdtime    |  TIME      | accumulated cpu time, user + system. The display format is usually "MMM:SS"| cmd        |  CMD       | see args. (alias args, command).| comm       |  COMMAND   | command name (only the executable name).| command    |  COMMAND   | see args. (alias args, cmd).| cp         |  CP        | per-mill (tenths of a percent) CPU usage. (see %cpu).| cputime    |  TIME      | cumulative CPU time, "[dd-]hh:mm:ss" format. (alias time).| egid       |  EGID      | effective group ID number of the process as a decimal integer. (alias gid).| egroup     |  EGROUP    | effective group ID of the process. (alias group).| etime      |  ELAPSED   | elapsed time since the process was started, in the form [[dd-]hh:]mm:ss.| euid       |  EUID      | effective user ID. (alias uid).| euser      |  EUSER     | effective user name. (alias uname, user).| f          |  F         | flags associated with the process, see the PROCESS FLAGS section. (alias flag, flags).| fgid       |  FGID      | filesystem access group ID. (alias fsgid).| fgroup     |  FGROUP    | filesystem access group ID. (alias fsgroup).| fname      |  COMMAND   | first 8 bytes of the base name of the process's executable file.| fuid       |  FUID      | filesystem access user ID. (alias fsuid).| gid        |  GID       | see egid. (alias egid).| group      |  GROUP     | see egroup. (alias egroup).| lstart     |  STARTED   | time the command started. See also bsdstart, start, start_time, and stime.| ni         |  NI        | nice value. This ranges from 19 (nicest) to -20 (not nice to others), see nice(1). (alias nice).| nlwp       |  NLWP      | number of lwps (threads) in the process. (alias thcount).| pcpu       |  %CPU      | see %cpu. (alias %cpu).| pgid       |  PGID      | process group ID or, equivalently, the process ID of the process group leader. (alias pgrp).| pgrp       |  PGRP      | see pgid. (alias pgid).| pid        |  PID       | process ID number of the process.| pmem       |  %MEM      | see %mem. (alias %mem).| ppid       |  PPID      | parent process ID.| pri        |  PRI       | priority of the process. Higher number means lower priority| psr        |  PSR       | processor that process is currently assigned to.| rgid       |  RGID      | real group ID.| rgroup     |  RGROUP    | real group name.| rss        |  RSS       | resident set size, the non-swapped physical memory that a task has used (in kiloBytes). (alias rssize, rsz).| rssize     |  RSS       | see rss. (alias rss, rsz).| rsz        |  RSZ       | see rss. (alias rss, rssize).| rtprio     |  RTPRIO    | realtime priority.| ruid       |  RUID      | real user ID.| s          |  S         | minimal state display (one character). (alias state).| sid        |  SID       | see sess. (alias sess, session).| sig        |  PENDING   | see pending. (alias pending, sig_pend).| sigcatch   |  CAUGHT    | see caught. (alias caught, sig_catch).| sigignore  |  IGNORED   | see ignored. (alias ignored, sig_ignore).| sigmask    |  BLOCKED   | see blocked. (alias blocked, sig_block).| size       |  SZ        | approximate amount of swap space . This number is very rough!| spid       |  SPID      | see lwp. (alias lwp, tid).| stackp     |  STACKP    | address of the bottom (start) of stack for the process.| start      |  STARTED   | time the command started.| start_time |  START     | starting time or date of the process.| stat       |  STAT      | multi-character process state.| state      |  S         | see s. (alias s).| suid       |  SUID      | saved user ID. (alias svuid).| suser      |  SUSER     | saved user name.| svgid      |  SVGID     | see sgid. (alias sgid).| svuid      |  SVUID     | see suid. (alias suid).| sz         |  SZ        | size in physical pages of the core image of the process.| thcount    |  THCNT     | see nlwp. (alias nlwp). number of kernel threads owned by the process.| tid        |  TID       | see lwp. (alias lwp).| time       |  TIME      | cumulative CPU time, "[dd-]hh:mm:ss" format. (alias cputime).| tname      |  TTY       | controlling tty (terminal). (alias tt, tty).| tt         |  TT        | controlling tty (terminal). (alias tname, tty).| tty        |  TT        | controlling tty (terminal). (alias tname, tt).| ucmd       |  CMD       | see comm. (alias comm, ucomm).| ucomm      |  COMMAND   | see comm. (alias comm, ucmd).| uid        |  UID       | see euid. (alias euid).| uname      |  USER      | see euser. (alias euser, user).| user       |  USER      | see euser. (alias euser, uname).| vsize      |  VSZ       | see vsz. (alias vsz).| vsz        |  VSZ       | virtual memory size of the process in KiB (alias vsize).| wchan      |  WCHAN     | name of the kernel function in which the process is sleeping, a "-" if the process is running.
Read more »

linux 常用命令之 流量监控命令

Posted on 2018-06-09   |   In linux

Linux 查看流量相关的命令

  • nethogs
  • iptraf
  • ifstat
  • ethtool
  • tcpdump
  • ss
  • dstat
  • slurm
  • nload
  • bmon
  • nmon
  • dstat
  • atop
  • iftop
  • iptraf
  • sar
  • jnettop
  • slurm
  • tcptrack

其中一些在 Mac OSX 上也能同样工作,如:

  1. nethogs
  2. tcptrack
  3. iftop
  4. bmon
  5. slurm

nethogs

 nethogsNetHogs version 0.8.5-2    PID   USER PROGRAM                                     DEV SENT   RECEIVED      ?   root 149.28.53.9:80-101.86.236.205:65032     311.416 10.356   KB/sec      ?   root 149.28.53.9:8888-112.65.48.103:62927      0.998 0.727    KB/sec  12083   root sshd:                                root@pts/0 0.617     0.444 KB/sec    712 nobody /usr/bin/python                            ens3 0.346     0.049 KB/sec    713 nobody /usr/bin/python                            ens3 0.000     0.000 KB/sec      ?   root unknown                                     TCP 0.000     0.000 KB/sec  TOTAL                                                    274.976      10.216 KB/sec
Read more »

linux 常用命令之 top

Posted on 2018-06-06   |   In linux

tldr top

 tldr topDisplay dynamic real-time information about running processes.  - Start top:    top  - Do not show any idle or zombie processes:    top -i  - Show only processes owned by given user:    top -u user_name  - Show only the processes with the given PID(s), passed as a comma-separated list. (Normally you would not know PIDs off hand. This example picks the PIDs from the process name):    top -p $(pgrep -d ',' process_name)  - Show java processes    top -p $(pgrep -d ',' java)  - Show threads of specified java process    top -Hp 15961  - Get help about interactive commands:    ?

top 默认值

*开头的参数可以在top命令行参数中进行覆盖,其他的参数可以通过~/.toprc文件自定义配置。

Global_defaults   'A' - Alt display      Off (full-screen) * 'd' - Delay time       3.0 seconds   'I' - Irix mode        On  (no, 'solaris' smp) * 'p' - PID monitoring   Off * 's' - Secure mode      Off (unsecured)   'B' - Bold disable     OffSummary_Area_defaults   'l' - Load Avg/Uptime  On  (thus program name)   't' - Task/Cpu states  On  (1+1 lines, see '1')   'm' - Mem/Swap usage   On  (2 lines worth)   '1' - Single Cpu       On  (thus 1 line if smp)Task_Area_defaults   'b' - Bold hilite      On  (not 'reverse') * 'c' - Command line     Off (name, not cmdline) * 'H' - Threads          Off (show all threads) * 'i' - Idle tasks       On  (show all tasks)   'R' - Reverse sort     On  (pids high-to-low) * 'S' - Cumulative time  Off (no, dead children)   'x' - Column hilite    Off (no, sort field)   'y' - Row hilite       On  (yes, running tasks)   'z' - color/mono       Off (no, colors)

top 命令常用选项

  1. -b:批量模式,一般用来导出 top 命令结果到一个文件中
  2. -c:显示完整的命令路径信息
  3. -d:屏幕刷新间隔时间
  4. -u:指定用户名
  5. -p:指定进程
  6. -n:循环显示的次数

top 帮助文档

  1. h : 显示帮助画面。
  2. k : 终止一个进程。
  3. i : 忽略闲置和僵死进程。
  4. q : 退出程序。
  5. r : 重新安排一个进程的优先级别。
  6. S : 切换到累计模式。
  7. s : 改变两次刷新之间的延迟时间。
  8. f : 从当前显示中添加或者删除项目。
  9. o : 改变显示项目的顺序。
  10. l : 切换显示平均负载和启动时间信息。
  11. m : 切换显示内存信息。
  12. t : 切换显示进程和CPU状态信息。
  13. c : 切换显示命令名称和完整命令行。
  14. M : 根据驻留内存大小进行排序。
  15. P : 根据CPU使用百分比大小进行排序。
  16. T : 根据时间/累计时间进行排序。
  17. W : 将当前设置写入~/.toprc文件中。

Example of linux top

 toptop - 15:17:03 up 32 days, 22:35,  1 user,  load average: 0.06, 0.04, 0.00Tasks: 101 total,   1 running, 100 sleeping,   0 stopped,   0 zombieCpu(s): 11.3%us,  3.4%sy,  0.0%ni, 84.3%id,  0.1%wa,  0.0%hi,  0.9%si,  0.0%stMem:   3924684k total,  3817324k used,   107360k free,     8628k buffersSwap:        0k total,        0k used,        0k free,   414188k cached  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND27221 tomcat    20   0 5221m 2.7g  17m S 59.3 73.0 591:09.49 java26833 nginx     20   0 76096  29m 1340 S  2.0  0.8  25:51.72 nginx    1 root      20   0 21448 1104  804 S  0.0  0.0   0:00.77 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:13.43 migration/0    4 root      20   0     0    0    0 S  0.0  0.0   3:08.30 ksoftirqd/0    5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0
Read more »

命令行神器之 openssl 篇

Posted on 2018-04-28   |   In linux

tldr openssl

 tldr opensslOpenSSL cryptographic toolkit.- Generate a 2048bit RSA private key and save it to a file:      openssl genrsa -out filename.key 2048- Generate a certificate signing request to be sent to a certificate authority:      openssl req -new -sha256 -key filename.key -out filename.csr- Generate a self-signed certificate from a certificate signing request valid for some number of days:      openssl x509 -req -days days -in filename.csr -signkey filename.key -out filename.crt- Display certificate information:      openssl x509 -in filename.crt -noout -text- Display the start and expiry dates for a domain certificate:      openssl s_client -connect host:port 2>/dev/null | openssl x509 -noout -dates- Display the certificate presented by an SSL/TLS server:      openssl s_client -connect host:port </dev/null- Display the complete certificate chain of an HTTPS server:      openssl s_client -connect host:443 -showcerts </dev/null

OpenSSL

OpenSSL 是一个开放源代码的软件库包,其主要库是以 C 语言所写成,实现了基本的加密功能,实现了 SSL 与 TLS 协议。

OpenSSL 功能组成

OpenSSL 整个软件包大概可以分成三个主要的功能部分:

  1. libcryto,这是一个具有通用功能的加密库,里面实现了众多的加密库。
  2. libssl,这个是实现ssl机制的,它是用于实现TLS/SSL的功能。
  3. openssl,是个多功能命令行工具,它可以实现加密解密,甚至还可以当CA来用,可以让你创建证书、吊销证书。

OpenSSL 基本功能

  1. Creation and management of private keys, public keys and parameters
  2. Public key cryptographic operations
  3. Creation of X.509 certificates, CSRs and CRLs
  4. Calculation of Message Digests
  5. Encryption and Decryption with Ciphers
  6. SSL/TLS Client and Server Tests
  7. Handling of S/MIME signed or encrypted mail
  8. Time Stamp requests, generation and verification

对称加密

OpenSSL 一共提供了8种对称加密算法,其中7种是分组加密算法,仅有的一种流加密算法是 RC4。

这7种分组加密算法分别是:

  1. AES
  2. DES
  3. Blowfish
  4. CAST
  5. IDEA
  6. RC2
  7. RC5

都支持电子密码本模式(ECB)、加密分组链接模式(CBC)、加密反馈模式(CFB)和输出反馈模式(OFB)四种常用的分组密码加密模式。其中,AES使用的加密反馈模式(CFB)和输出反馈模式(OFB)分组长度是128位,其它算法使用的则是64位。事实上,DES算法里面不仅仅是常用的DES算法,还支持三个密钥和两个密钥3DES算法。

非对称加密

OpenSSL 一共实现了4种非对称加密算法,包括DH算法、RSA算法、DSA算法和椭圆曲线算法(EC)。DH 算法一般用于密钥交换。RSA 算法既可以用于密钥交换,也可以用于数字签名,当然,如果你能够忍受其缓慢的速度,那么也可以用于数据加密。DSA 算法则一般只用于数字签名。

信息摘要

OpenSSL实现了5种信息摘要算法,分别是MD2、MD5、MDC2、SHA(SHA1)和RIPEMD。SHA算法事实上包括了SHA和SHA1两种信息摘要算法。此外,OpenSSL还实现了DSS标准中规定的两种信息摘要算法DSS和DSS1。

Read more »
1…789…99
yuweijun

yuweijun

492 posts
12 categories
RSS
GitHub Twitter
© 2021 yuweijun
Powered by Hexo
Theme - NexT.Mist.KISS