Linux instructions: Linux Command output headers, overlay two commands to obtain the headers and content, linux2

Source: Internet
Author: User

Linux instructions: Linux Command output headers, overlay two commands to obtain the headers and content, linux2
Linux Command output Header

When using Linux commands, if there is a pipeline "|" in the command, the header (title) information is lost in the output information. It is inconvenient to see what each column means.

$ ps axuwUSER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMANDroot         1  0.0  0.2  37888  5952 ?        Ss   01:21   0:02 /sbin/init nopromptroot         2  0.0  0.0      0     0 ?        S    01:21   0:00 [kthreadd]root         3  0.0  0.0      0     0 ?        S    01:21   0:00 [ksoftirqd/0]root         5  0.0  0.0      0     0 ?        S<   01:21   0:00 [kworker/0:0H]

After adding the Pipeline character

$ ps axuw | grep javafaster    8502  0.0  0.0  12948   972 pts/1    S+   02:15   0:00 grep java
Simple Method: overlay two commands to obtain the header and content

First, add "| head-1" to the Command itself to get the header (title), and then use the command to output the content. overlay the two to get the desired result.

$ ps axuw | head -1;ps axuw | grep javaUSER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMANDfaster    8510  0.0  0.0  12948   940 pts/1    S+   02:17   0:00 grep java

Sort output results

Method 1: | Sort-rn-k column no.

root@ubuntu:/home/faster/Fastdfs/FastDFS# ps auxw | sort -rn -k6root       851  0.2  1.6 408816 33224 ?        Ssl  01:21   0:10 /usr/bin/docker daemon -H fd://root       868  0.0  0.6 213068 13320 ?        Ssl  01:21   0:02 containerd -l /var/run/docker/libcontainerd/docker-containerd.sock --runtime runc --start-timeout 2mroot      8452  0.0  0.3  95584  7212 ?        Ss   01:47   0:00 sshd: tiger [priv]root       980  0.0  0.3  95464  7088 ?        Ss   01:21   0:00 sshd: tiger [priv]root      1044  0.0  0.3  95464  7048 ?        Ss   01:23   0:00 sshd: tiger [priv]root       854  0.0  0.3  65612  6616 ?        Ss   01:21   0:00 /usr/sbin/sshd -Droot       592  0.0  0.3 274592  6240 ?        Ssl  01:21   0:00 /usr/lib/accountsservice/accou

In this example, 6th columns are sorted, before the maximum number of rows.

Method 2:-Sort =-column name

ps auxw --sort=-rss

If you only want to view the first 10 items:

ps auxw | sort -rn -k6 | head -10
Application 1: display the top 10 processes with the maximum memory consumption
Ps auxw | head-1; ps auxw | sort-rn-k6 | head-10 or ps auxw -- sort =-rss | head-10

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.