Linux_ Common Command Brief introduction (NETSTAT,AWK,TOP,TAIL,HEAD,LESS,MORE,CAT,NL)

Source: Internet
Author: User
Tags domain name server log4j

1.netstat

NETSTAT-TNL | grep 443 (see if Port 443 is occupied) root user, with Netstat-pnl | grep 443 (also shows the process PID that occupies the native 443 port). -A (all) show all options, default does not show listen related-t (TCP) only show TCP-related options-U (UDP) only show UDP-related options-n deny display aliases, can display all numbers converted into numbers. Use the IP address directly, not through the domain name server. -L only lists the service status in Listen (listening)-p displays the program name that establishes the relevant link-r display routing information, routing table-e displays extended information, such as UID, etc.-s per protocol to statistics-C every other fixed time, executes the netstat command.

2. awk

awk ' {pattern + action} ' {filenames} where pattern represents what AWK looks for in the data, and action is a series of commands that are executed when a match is found. Curly braces ({}) do not need to always appear in the program, but they are used to group a series of instructions according to a particular pattern. pattern is the regular expression to be represented, surrounded by slashes. The most basic function of the awk language is to browse and extract information in a file or string based on the specified rules, before awk extracts the information for additional text operations. A complete awk script is typically used to format the information in a text file. Typically, awk is treated as a unit of a file's behavior. awk processes the text by executing the corresponding command for each line that receives the file. Each row is sliced with a space as the default delimiter, and the cut section is then processed in various analytical ways. 1). command line mode awk [-f field-separator] ' commands ' input-file (s) where commands is the true awk command, [-F domain delimiter] is optional. Input-file (s) is the file to be processed. In awk, each line in a file, separated by a domain delimiter, is called a domain. In general, the default field delimiter is a space without naming the-F domain delimiter. 2). Shell scripting way to insert all awk commands into a file and make the awk program executable, and then awk command interpreter as the first line of the script to invoke by typing the script name. Equivalent to the first line of the shell script: #!/bin/sh can be replaced by: #!/bin/awk3). Insert all awk commands into a single file, and then call: Awk-f awk-script-file input-file (s) where,- The f option loads the awk script in Awk-script-file, and Input-file (s) is the same as above. Common commands: Split with ":" To print the first column of content cat/etc/passwd |awk-f ': ' {print $} ' cat/etc/passwd |awk-f ': ' {print ' \ t ' $7} ' to find inside that begins with ' root ' Awk-f: '/^root/'/etc/passwd search/etc/passwd all rows with the root keyword and display the corresponding shellawk-f: '/root/{print $7} '/etc/passwd content is referenced in: http:/ /www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html 

3.top

The top command is a common performance analysis tool under Linux that shows the resource usage of each process in the system in real time. The first five elements are the statistical information area of the current system situation as a whole. Let's look at the specific meaning of each line of information. The first line, the task queue information, and the execution result of the uptime command, the specific parameters are as follows: 14:06:23-current system time up to 70 days, 16:44-the system has been running for 16 hours and 44 minutes (during which the system has not restarted the Yo!). Users-currently has 2 users logged into the system load average:1.15, 1.42, 1.44-load average the three numbers are 1-minute, 5-minute, and 15-minute load cases respectively. The load average data is the number of active processes that are checked every 5 seconds and then calculated by a particular algorithm. If this number is divided by the number of logical CPUs, the result above 5 indicates that the system is overloaded. The second line, tasks-task (process), the specific information is described as follows: The system now has 206 processes, of which there are 1 running, 205 in hibernation (sleep), 0 in the stoped state, and 0 in the zombie State (zombie). The third line, CPU status information, the specific properties are described as follows: 5.9%us-the percentage of CPU occupied by user space. 3.4% sy-The percentage of CPU consumed by the kernel space. 0.0% ni-Change the priority of the process to occupy the percentage of CPU 90.4% id-Idle CPU percent 0.0% Wa-io waiting for CPU percentage 0.0% hi-hard Interrupt (Hardware IRQ)% of CPU 0.2% si-soft interrupt (so Ftware interrupts) Percentage of CPU Usage Note: In this case the CPU utilization ratio and the Windows concept are different, need to understand Linux system user space and kernel space knowledge! The four-line, memory state, specific information is as follows: 32949016k total-total Physical Memory (32GB) 14411180k used-total Memory in use (14GB) 18537836k free-total free memory (18GB) 169884k buffers-Cache Memory (169M) line fifth, swap swap partition information, specific information is described as follows: 32764556k total-swap Area total (32GB) 0k used-Total swap area (0K) 32764556k free-free Swap area total (32GB) 3612636k cached-buffer swap area total (3.6GB) Note: The total amount of memory in use in line fourth (used) refers to the amount of memory that is now controlled by the system kernel, and the total amount of free memory that the kernel has not included in its control range. The memory that is included in kernel management is not always in use, but also includes the memory that has been used in the past that can now be reused, and the kernel does not return these reusable memory to free, so there is less memory on Linux, but don't worry about it. If you are accustomed to calculating the number of available memory, here is an approximate formula: The fourth line of Free + fourth row buffers + fifth row of cached, according to this formula this server's available memory: 18537836k +169884k +3612636k = 22GB or so. For memory monitoring, in the top we have to monitor the fifth line swap partition used, if this value is constantly changing, indicating that the kernel is constantly in memory and swap data exchange, which is really not enough memory. Line six, blank line. Line seventh below: status monitoring of each process (task), the project column information is described as follows: pid-process iduser-Process owner pr-process priority Ni-nice value. A negative value represents a high priority, and a positive value represents the total amount of virtual memory used by the low-priority virt-process, in kilobytes. The size, in kilobytes, of the physical memory used by the virt=swap+resres-process and not swapped out. res=code+datashr-Shared memory size, unit kbs-process state. d= non-disruptive sleep state r= run s= sleep t= track/stop z= zombie process%cpu-Last update to current CPU time consumption percentage%mem-process uses the percentage of physical memory time+-process uses CPU time total, unit 1/100 seconds command-process name  Call (command name/command line) Common operation: Top//Every 5 seconds resource consumption of explicit all processes top-d 2//Every 2 seconds explicit process Resource usage top-c//Every 5 seconds, and display the process's command-line arguments (default only process name) top-p 12345-p 6789//every 5 seconds the PID is 12345 and the PID is 6789 of the resource consumption of two processes top-d 2-c-P 123456//Every 2 seconds shows the PID is 12345 of the resource usage of the process,          and explicitly the process starts with the command-line arguments that the content is transferred from: http://www.cnblogs.com/peida/archive/2012/12/24/2831353.html  Http://www.cnblogs.com/ggjucheng/archive/2012/01/08/2316399.html 

4. View Text command:

Tail

command format; tail[necessary parameters [select parameters] [file]   command function: Used to display the end of the specified file, when the file is not specified as input information for processing. Common view log files. Command parameter:-F loop Read-Q does not display processing information-v displays verbose processing information-c< number > bytes displayed-n< lines > Display rows--pid=pid is combined with-F to indicate the end of the process after Id,pid is dead.-Q,--quiet,- -silent never outputs the header-S of the file name,--sleep-interval=s and-F are shared, representing the interval of sleep s seconds at each repetition example: tail-10 log4j.log  shows the last ten lines tail-n +5 Show content from line fifth Tail-f Log4j.log  as the file changes, show what's behind

Head

Command format: Head [parameters] ... [File] ...  Command function: Head is used to display the beginning of the file to the standard output, the default head command prints the first 10 lines of its corresponding file. Command parameters:-Q Hide File name-V display file name-c< bytes > Display bytes-n< number of rows > displayed number of rows example: Head-n 5 Log4j.log  show the first n rows of a file Head-n-6 Log4j.log  Output file except the last n rows of the entire content

Less

The less tool is also a tool for paging through files or other output. Less does not load the entire file until it is viewed. SPACEBAR to PAGE DOWN. Command parameters:-B < buffer size > Set buffer size-e  When the file display ends, automatically leaves the-F  force to open special files such as peripheral code, directory and binary file-G  only flag the last search keyword  -i Ignore search case-m displays a  percentage like the more command-n  displays the line number of each line-o < file name > save less output in the specified file-Q  does not use warning tone-S to  display continuous empty behavior line-S  the line too long will be out of the partial discard-x < number > the "tab" key is displayed as the specified number of spaces/strings: Search down the "string" function? String: Search Up "string" function N: Repeat previous search (with/or? related) N: Reverse repeat previous search (with Or? About) b  turn back one page D  back half page H  display Help interface Q  exit less command U  Roll forward Half page forward  scroll one line [PageDown]: screen content to flip a page, not file page [ PageUp]:   screen content flipping up a page, not file page G-Move to the last line G-Move to the first row

More

The more command, which functions like cat, the Cat command is the entire contents of the file displayed on the screen from top to bottom. More will be a page-by-page display to facilitate users to read pages, and the most basic instruction is to press the blank key (space) on the next page, press the B key will be back to a page, but also the function of the search string. The more command reads the file backwards from the front, so it loads the entire file at startup. Command parameters: +n      start from joys N lines       to define a screen size of n rows +/pattern search for the string before each profile is displayed, then start with the first two lines of the string, and then display  the       -C screen from the top, and then show the-D       tip "Press space to continue, ' Q ' to quit (pressing SPACEBAR to continue, press the Q key to exit)", disable the ring function-L        ignore ctrl+l (page break) character-p to       change the page by clearing the window instead of scrolling the screen, Similar to-C option       -s displays consecutive empty lines as one line-u       remove the down line from the file contents

Cat

The purpose of the cat command is to connect files or standard input and print. This command is commonly used to display the contents of a file, or to connect several files to display, or to read from a standard input and display it, often in conjunction with redirection symbols. Command function: Cat has three main functions: 1. Display the entire file at once: Cat filename2. Create a file from the keyboard: cat > FileName can only create new files and cannot edit existing files. 3. Merge several files into one file: Cat file1 file2 > File Command function: Cat has three main functions: 1. Display the entire file at once: Cat filename2. Create a file from the keyboard: cat > FileName can only create new files and cannot edit existing ones. 3. Merge several files into one file: Cat file1 file2 > file

nl

The NL command is used in a Linux system to calculate the line number of a file. NL can automatically add a line number to the output file content! The default result is a bit different from Cat-n, NL can make the line number more display design, including the number of digits and whether auto-completion 0 and so on.  Command parameters:-B  : Specifies the way the line number is specified, mainly in two ways:-B A: Indicates that the line number (similar to cat-n) is also listed, whether or not it is a blank line;-B T: If there is a blank line, the empty row does not list the line number (the default);-N  : Lists the methods represented There are three main kinds:-N ln: The line number is displayed on the left of the screen, and the line number is displayed on the very right of its field, without adding 0;-n RZ: The line number is displayed on the right-most side of its field, plus 0;  -W: the number of digits occupied by the line number field. -P does not restart the calculation at the logical delimiter.
Code reproduced in: http://www.cnblogs.com/peida/archive/2012/12/05/2803591.html

  

Linux_ Common Command Brief introduction (NETSTAT,AWK,TOP,TAIL,HEAD,LESS,MORE,CAT,NL)

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.