Summary of Common Linux commands

Source: Internet
Author: User
Tags aliases curl cpu usage file permissions high cpu usage server port

Https://github.com/linw7/Skill-Tree/blob/master/Linux%E5%B7%A5%E5%85%B7.md

Online to see others summed up.

Linux Tools

There are still a lot of great development tools under Linux.

In the daily use of Linux, the most commonly used commands are sudo, LS, CP, MV, CAT, etc., but as a background developer, the above command is far from enough. From my understanding, the qualified C + + developers need at least a few development tools, from the development and debugging tools, file processing, performance analysis, network Tools four aspects of targeted use. Here I have listed some, most of the development is often required to use the command, some of the more simple commands I will give some basic usage, some of their own system (such as VIM, GDB, etc.) commands can only be attached to the link.

The development and debugging tool describes the full set of commands for tracing the call process from the editor-to-compile, parse target file, which describes the basic text manipulation commands such as find, statistics, and replace, and provides performance analysis that describes viewing process information, CPU load, I/O load, Basic commands such as memory usage, the Network tool describes a tool that lets you view information about the application layer, Transport layer, link layer, network layer, and so on. In addition, other commands also list some of the commands that developers often use to meet their daily development needs.

Directory
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5
Development and commissioning File processing Performance analysis Network Tools Other
  • Development and commissioning

    • Editor: Vim
    • Compiler: gcc/g++
    • Debugging Tools: GDB
    • View Dependent libraries: LDD
    • Binary file Analysis: objdump
    • Elf file format analysis: readelf
    • System call in trace process: strace
    • Trace Process Stack: pstack
    • Process Memory Mapping: PMAP
  • File processing

    • File Lookup: Find
    • Text Search: grep
    • Sort by: Sort
    • Conversion: TR
    • Slice text by column: Cut
    • Stitching text by column: paste
    • Statistic lines and characters: WC
    • Text substitution: SED
    • Data flow processing: awk
  • Performance analysis

    • Process query: PS
    • Process monitoring: Top
    • Open file query: lsof
    • Memory Usage: Free
    • Monitoring performance indicators: SAR
  • Network Tools

    • NIC configuration: Ifconfig
    • View current network connection: netstat
    • View route table: route
    • Check network connectivity: Ping
    • Forwarding path: traceroute
    • Network Debug Analysis: NC
    • Command-line Grab bag: tcpdump
    • Domain Name resolution tool: Dig
    • Network Request: Curl
  • Other

    • Terminate process: Kill
    • Modify file Permissions: chmod
    • Create Link: ln
    • Display end of File: tail
    • Version control: git
    • Set Alias: Alias
Content Development and commissioning

Most of the development tools provide perfect functionality, so there is no listing of usage. At a technical level, debugging tools test a person's engineering capabilities more than development tools.

  1. Editor: Vim

    • Server-side development must know, powerful, not listed here, but the basic open files, save the exit to be.
    • See
  2. Compiler: gcc/g++

    • C + + compiler, must know, but need to know the preprocessing---compilation--------a series of processes such as links.
    • See
  3. Debugging Tools: GDB

    • Server-side debugging prerequisites.
    • See
  4. View Dependent libraries: LDD

    • Program Dependent Library Query
    # LDD after the executable  # The first column of the program depends on what library, the second list of the system provides the library corresponding to the needs of the library, the third listed library load start Address # The first two columns can determine whether the system provides the library and the required library matches, The third column can tell where the current library starts in the process address space ldd a.out 
  5. Binary file Analysis: objdump

    • Disassembly, need to understand assembly language
    • See
  6. Elf file format analysis: readelf

    • You can get the content of the elf file, analyze the link, symbol table, etc. need to use
    • See
  7. System call in trace process: strace

    • See
  8. Trace Process Stack: pstack

    • See
  9. Process Memory Mapping: PMAP

    • Show Process Memory mappings
    #-X Display extension information, followed by process PID# Address: Memory start addresses # Display information: Kbytes: Memory-Consuming bytes RSS: Number of bytes reserved Memory Dirty: Number of bytes of dirty pages (both shared and private) Mode: Permissions for Memory: Read, write, execute, shared, private Mapping: memory-intensive files, or [anon] (allocated memory), or [stack] (stacks) Device: Device name (Major:minor) Pmap-x 12345 
File processing

Everything is file. In the Linux environment, the text processing is very frequent, so some of the parameters of the command still need to remember. In addition, the output of many other commands requires a file Processing command to filter useful information.

  1. File Lookup: Find

    Find by Name:

      • Find a specific file (general method)
    *.cpp
      • Find specific files (regular mode)
    ". *.cpp$"

    Custom Search:

      • Find by Type
    . -type F
      • Find by Time
    # Atime for access time, x days plus the parameter "-atime-x", more than x days Plus "-atime-x".-type f-atime-7
      • Find by size
    . -type f-size-1k
      • Query by permissions
    . -type-perm 644
  2. Text Search: grep

    • Pattern matching
    "Iostream" Test.cpp  
    • Multiple pattern matching
    "Using" iostream  
    • Output information
    "Iostream" Test.cpp  
  3. Sort by: Sort

    • File Content Line Sort
    # Sort in memory, do not change file  #-N (number) means sort by numeric,-D (dictionary) means by dictionary order #-K n means sort by row nth column test  
  4. Conversion: TR

      • Character substitution
    # Convert in memory, do not change file      ' 1' 2'  
      • Character deletion
    # Convert in memory, do not change file      ' 1' 
      • Character compression
    # Convert in memory, do not change file       '-S
  5. Split text by column: Cut

    • intercept specific columns
     # captured memory, does not change file #-B (Byte) in bytes,-C (character) in characters,-F in field # numbers for specific column ranges cut-f test        
    • specifying a delimiter
     # intercepted memory, does not change file #-D followed by delimiter Cut-f 2- D  " ' new       
  6. Stitching text by column: paste

    • Concatenation by column
    # in memory splicing, do not change the file  # Two files by the corresponding column stitching # finally plus-D "x" will be the specified delimiter (Paste test1 test2-d ",")# Two file columns can be different paste test1 test2
                  
    • Specify the delimiter stitching
    # stitching in memory, without changing the file    "," 
  7. Statistic lines and characters: WC

    • Basic statistics
    Test
  8. Text substitution: SED

    • Unlike the above command, SED can directly change the contents of the edited file.
    • See
  9. Data flow processing: awk

    • Unlike the above command, awk can change the contents of the edited file directly.
    • See
System Information

Performance monitoring tools work for programmers just as a stethoscope does for a doctor. System information is mainly aimed at the low performance of the server troubleshooting, including CPU information, file I/O and memory usage, through the process as a link to get the bottleneck of system operation.

  1. Process query: PS

    • View Running Processes
    # often combined with grep filtering information (e.g, PS-EF | grep xxx) PS-EF
    • Show all processes in full format
    # often combines grep to filter information PS-AJX
  2. Process monitoring: Top

    • Show real-time process information
    # This is a big trick, with no parameters, specific information through grep filter  # Interactive mode type M process list by memory usage size descending, type P process list in descending order by CPU size #%ID indicates CPU idle rate, Too low to indicate a possible CPU bottleneck #%WA indicates the percentage of CPU time waiting for I/O, too high I/O bottlenecks > Further analysis of top with Iostat  
  3. Open file query: lsof

    • Viewing processes that occupy a port
    # The most common is the MySQL port used (lsof i:3307)# Known ports (FTP:20/21, Ssh:22, telnet:23, smtp:25, dns:53, http:80, pop3:110, HTTPS : 443) lsof-i:53
    • View open files for a user
    #-U (user) for user, followed by username Lsof-u Inx
    • View files opened by the specified process
    #-P (process) for progress, followed by process Pidlsof-p 12345
    • View files opened by process in the specified directory
    # here is "+d", need to be aware, use "+d" recursive directory lsof +d/test
  4. Memory Usage: Free

    • Amount of memory used
    # can get the total amount of memory and swap area, the amount of usage, the amount of idle information free
  5. Monitoring performance indicators: SAR

    Monitor CPU

    • Monitor CPU Load
    # Plus-Q to see the number of processes in the running queue, the process size on the system, the average load, etc.  # here "1" means that the sampling interval is 1 seconds, where "2" means the sample count is 2sar-q 1 2
    • Monitor CPU Usage
    # can show CPU usage  # parameter meaning ibid. sar-u 1 2

    Monitoring memory

    • Querying memory
    # can show memory usage  # parameter meaning ibid. sar-r 1 2
    • Page Exchange Query
    # can see if there is a large number of page exchanges, the throughput rate is significantly reduced when the  # parameter meaning ibid. sar-w 1 2
Network Tools

The Network Tools section only describes the basic functionality, and the parameters section takes a stroke. This part of the focus is not the use of tools, but the feedback of the data interpretation, and this part of the command function is still relatively high degree of overlap.

  1. NIC configuration (link layer): ifconfig

    • Display device Information
    # can display the activated network device information ifconfig
    • Start off the specified NIC
    # The previous parameter is a specific NIC, the latter one for the switch information  # Up for open, down for off ifconfig eth0 up
    • Configure IP Address
    # The previous parameter is a specific NIC, and the latter is the configured IP address ifconfig eth0 192.168.1.1
    • Setting the maximum transmission unit
    The previous parameter is a specific NIC, followed by the MTU size  # To set the link Layer MTU value, typically 1500ifconfig eth0 MTU
    • Enabling and shutting down the ARP protocol
    # 开启arp如下,若关闭则-arpifconfig eth0 arp
  2. View current network connection (link layer/Network layer/Transport layer): netstat

      • Network interface Information
    # Display network card information, can be combined with ifconfig learning Netstat-i
      • List ports
    #-A (all) means all ports,-t (TCP) indicates that all the TCP ports in use  #-L (Listening) represent the port being monitored netstat-at
      • displaying port statistics
    #-S (status) displays protocol information  #-plus-T (TCP) displays TCP protocol information, plus-u (UDP) displays UDP protocol information netstat-s
      • Displays the name of the application using a protocol
    #-P (Progress) represents a program that can display the name of an app that uses the TCP/UDP protocol netstat-pt
      • Find the specified process, port
    # Reciprocal operation The first shows the port number used by a program, and the second shows the use process of a port number      ' : -X '
  3. View the routing table (Network layer IP protocol): route

    • Viewing routing information
    # Get routing table information, detailed analysis of routing table work requires network knowledge  # can get the same route table route through Netstat-r (route)
  4. Check network connectivity (Network layer ICMP protocol): Ping

    • Check if connectivity
    # The main function is to detect network connectivity  # can be added to the site's IP address and connection maximum/minimum/average time-consuming. Ping baidu.com
  5. Forwarding path (Network layer ICMP protocol): Traceroute

    • IP of the package path
    # You can print the IP address of the router that passes along Traceroute baidu.com
  6. Network Debug Analysis (Network layer/Transport Layer): NC

    • Port scan
    # hackers love  # Scan a server port usage #- V (view) to display instruction execution,-W (wait) to set timeout duration #-Z use input and output mode (only used when port scanning)# number for the scanned port range NC- V-w 1 baidu.com-z 75-1000   
    • Other details
  7. Command-line grab packet (network layer/Transport Layer): tcpdump

    • Grab a weapon, nothing is more trustworthy than data. You can track the entire transport process.
    • See
  8. Domain Name resolution tool (Application-level DNS protocol): Dig

    # application layer, DNS# Print Domain name resolution Results # The DNS server addresses that are involved in the print domain resolution process dig baidu.com 
  9. Network request (Application layer): Curl

    • See
Other

This is the daily development of high-frequency commands.

  1. Terminate process: Kill

    • Kill a specific process
    # Plus specific process pidkill 12345
    • Kill a process-related process
    # Plus "-9" kills a process-related process kill-9 12345
  2. Modify file Permissions: chmod

    • Change file permissions
    # Three types of users can be set permissions, U (user, owner), G (group), O (Other)# file can have three permissions, R (Read), W (write), X (execute)# here u+ R indicates that the file owner has added file read permissions on the original Basis # Here 777 corresponds, u=7,g=7,o=7, specific number meaning self googlechmod u+r filechmod 777 file  
  3. Create Link: ln

    • Create a hard link
    # The number of links in the file inode will increase, only the number of links reduced to 0 o'clock files is really deleted ln file1 file2
    • Create a soft (symbolic link) Link
    #-S (symbol) is a symbolic link, only refers to the path  # compared to hard links the biggest feature is that can cross file system # Similar to the Windows create shortcut, the actual file deletion link fails ln-s file1 file2 
  4. Display end of File: tail

    • View File Trailer
    #-F parameter can not immediately return the end signal, when the file has new write data will be updated in time   test
  5. Version control: git

    • Version control is best used by software, not one. At least you should know "Git init", "Git Add", "Git Commit", "Git Pull", "Git Push" several commands.
    • See
  6. Set Alias: Alias

    • Frequently used commands to add aliases
    # ". BASHRC" file to configure the common command alias, after the effective on the command line only need to use aliases to replace the original long command alias rm=' rm-i'  
Actual combat

Assuming that the GCC compiler has compiled the executable file server through vim editing, you can use some of the tools commonly used by developers for post-commissioning. Here are the simplest uses, designed to quickly master some of the basic development tools.

Clone this project first, then use Src_code to compile the code after passing through the following command debugging. Code

    1. Single-Step Debugging: GDB
    • Not running the correct results you can determine where the problem is by using GDB to set breakpoints to see each of the intermediate variable values. Because GDB debugging content is many, here does not elaborate. In addition, GDB can step through the variable values and analyze the Coredump file to troubleshoot errors.
    1. Dynamic Library dependencies: LDD
    • Command: LDD./server

    • You can view all the dynamic libraries required by the executable file server, the directory in which the dynamic library resides, and the virtual address space to which it is mapped.

    1. Performance Analysis: Top
    • Top can view the current system a lot of information, such as 1, 5, 15 minutes of load, running, hibernation, the number of zombie processes, users, kernel programs accounted for CPU percentage, storage information and so on. Top can target which processes are high CPU usage and memory usage. We can use this to locate the performance problem on what program (for example, after you perform tkeed server in the background, you can see that the CPU occupancy rate is 99%, we need to start with this program).
    1. System call: Strace
    • Command: Strace./server

    • As mentioned above, the CPU utilization of Tkeed server is 99%, so the problem is usually in the dead loop. We then find the dead loop position in the code. Because epoll_wait in the program need to block the process, we suspect that there is no blocking here, then we can run the server program in the way above. At this point we can print the infestation system calls and their parameters, etc., we can also add-o filename to save the system call information.

    1. Printing process: PS
    • Command: PS-EJH

    • The parent process of the program that we open under the command line is the shell program, which previously opened the server program with Strace, and Strace is also the parent process of the server. Sometimes we need to know that the hierarchical relationship between processes needs to print the process tree, the above PS command can do. When a zombie process occurs, the process tree can be used to pinpoint which process is out of the question. In addition, when you want to know the process PID, Ps-el | grep xxx is also very common.

    1. Open File: lsof
    • lsof-i:3000

    • For example, when you run the server and discover that the port is occupied, you can use Lsof-i:port to see which process the corresponding port number is being occupied by. Port occupancy is a very common problem, such as 3306 of the time that I've met several times, either because a program is just taking up or not being able to end the process before, which can help you see the port with Lsof.

    1. Modify Permissions: chmod
    • chmod/index.html.

    • Can modify the file permissions, which is set to 000, so that anyone can not access, re-request in the browser 127.0.0.1:3000/index.html because the file permissions are not enough to show, the server returned a status code of 403, in line with our expectations. Modify the permission and then request it again to get the status code 200.

    1. Nic Information: Ifconfig
    • Ifconfig

    • If you want to see the entire transmission process, you can use tcpdump to grasp the package, but the parameters need to grab the packet card information, this time can be ifconfig to obtain network card information.

    1. Packet Capture Analysis: tcpdump
    • Tcpdump-i eth0 Port 3000

    • can use Tcpdump to capture packet analysis three handshake and data transfer process,-I followed by the previous step to get the network card address, port can specify the port number to listen.

Summary of Common Linux commands

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.