Commands that efficient Linux users need to know

Source: Internet
Author: User
Tags garbage collection html to text locale stack trace

Here are some command-line tools that are useful in the daily work of several respondents. for any commands you don't know, use "man <COMMANDNAME>" to view or use Google. Some commands need to be installed first with yum, apt-get Install command.

Table of Contents
    • 1 Basic commands

    • 2 Some expressions

    • 3 Daily Use commands

    • 4 Data processing

    • 5 System Commissioning

1 Basic commands
  • Learn about the basic bash

  • Read through the Bash man page.

  • Learn Vim

  • On Linux systems, although you have Emacs and Eclipse, Vim is still a powerful weapon.

  • Learn about SSH, the basic method of no password authentication.

  • For example, through Ssh-agent, Ssh-add and so on. "Empathy" usually use the following script to complete no password verification, save effort.
    Execution modesh nopasswd USER REMOTE_HOST
    Before you execute this script, verify that:

      • This machine already has id_dsa.pub , if not. obtained using commands ssh-keygen -t dsa .

      • On the remote machine login user home directory, there is already an. SSH folder, if not created.

$ cat nopasswd #!/bin/shscp ~/.ssh/id_dsa.pub [email protected]$2:~/ssh [email protected]$2] Touch ~/.ssh/authorized_ke YS; Cat ~/id_dsa.pub >> ~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keys; Exit

  • Familiar with task management commands commonly used in bash

  • &,Ctrl-Z,Ctrl-C,jobs,fg,bg,killsuch as

  • Basic file Management Commands

  • ls, ls-l, less, head, tail, tail -f, ln, ln -s, chmod, chown, du, du -sk *, df, mount

  • Basic Network Management commands

  • ipconfig, ifconfig, dig

  • Familiar with regular expressions, and the options used by Grep,egrep

  • -o, -A, -B

  • Software Installation Commands Learn about

  • Apt-get and Yum

  • cat -n

  • can help display line numbers.

2 Some expressions
  • !!

  • Execute the previous command again

  • !$

  • The last word of the previous command

  • {a..b}

  • A list of numbers in order from A to B

  • {a,b,c}

  • Three words a,b,c. Can be used this waytouch /tmp/{foo,bar,baz}

  • {$1-$9}

  • Command-line arguments when executing shell scripts

  • $0

  • Name of the command being executed

  • $#

  • The number of arguments passed in the currently started command

  • $?

  • The execution return value of the previous command.

  • $$

  • The process number of the shell.

  • $*

  • Start all parameters for the shell script starting with $.

3 Daily Use commands
    • Ctrl-R

    • In bash, Ctrl-r is used to search in the history command

    • Ctrl-W, Ctrl-U, Alt-BackSpace

    • Bash, Ctrl-w deletes the last word, Ctrl-u deletes the last line, alt-backspace a word in front of the delete cursor man readline contains a lot of default hotkey bindings in bash.

    • cd -

    • Return to previous work path

    • xargs

    • Very powerful command. If you are not sure if you can perform the task correctly, you can use xargs echo to view it first. Here is an example of this feature:

Find. -name \*.py | Xargs grep Some_functioncat Hosts | xargs-l {} SSH [email protected]{} hostname

  • parallel

  • A more powerful command. Can be implemented in parallel tasks, and can split the input file, specify multiple nodes to run the command and other functions. Detailed functionality can be found in this link.

  • pstree -p

  • A powerful tool for playing with the process tree

  • pgrep,pkill

  • Use the name lookup process, or send a signal directly to a process that specifies a name.

      • Learn some of the signals that users can send to processes. For example kill -STOP [pid] , let the PID process hang.

  • nohup,disown,screen, tmux

  • These two commands are useful when you need to keep the process running in the background forever.

  • lsof, netstat -lntp

  • Query what process is currently listening on what port.

  • set

  • In the bash script, use the set -x get debug output to set -e get the error output.

  • ;

  • A semicolon is used to open a child shell and to close after it has finished running. For example:

#在当前路径下执行一些命令 (Cd/some/other/dir; other-command) # The working path is still the current directory

    • Understanding multiple parameter expressions in the shell


      • ${name:?error message}

      • Checks if a variable exists, if no output error message exists.

      • ${var%suffix}, ${var#prefix}

      • Output var variable except for prefix or suffix part. As the following code output is foo.txt.

var = foo.pdfecho ${var%pdf}.txt

  • <,>

  • The input and output redirection operation.

  • some_command > logfile 2>&1

  • some_commandboth the standard output and the standard error output during the run are output to the file logfile.

  • man ascii

  • Get an easy-to-use ASCII table that contains 10-binary and 16-binary values.

  • screen,dtach

  • In remote SSH painting, you can save your session with these two commands, avoiding interruptions due to network problems.

  • curl, curl -l, wget

  • In the Web page debugging, these commands can help you to download the Web page code, very useful.

  • lynx -dump -stdin

  • Convert HTML to Text

  • xmlstarlet

  • This command is useful when you need to work with XML.

  • ssh -L, ssh -D

  • This command can help you establish an SSH tunnel between the remote server and your machine when you need to access the Web page with a remote server.

  • ssh连接优化

  • The following configuration can help you avoid the loss of links, do not need to enter the Yes confirmation and the remote server link, as well as the link to enable compression. It is recommended to put it in the. Ssh/config.

Tcpkeepalive=yesserveraliveinterval=15serveralivecountmax=6stricthostkeychecking=nocompression=yesforwardagent =yes

    • 在正输入的命令前加#

    • The command has been entered in half, and suddenly changed his mind to run less,
      You can use Alt-# the ' # ' in front of the command to turn the entire command into a comment. This will enable you to find the command in the command history later.

    • cron

    • can help you set up some scheduled tasks for scheduled execution.

    • Ctrl-S Ctrl-C

    • When you accidentally need a large amount of output text, enter both actions in turn,
      More often than simply press CTRL-C to get the program to terminate faster.

4 Data processing
    • sort,uniq, uniq -u, uniq -d

    • Learn about these sort commands

    • cut,paste, join

    • Learn about the maintenance tools for these text files. Many people forget to join after using cut

    • 使用sort/uniq进行集合的交、并、补运算=

    • Suppose A and B are two text files, where the lines are unique.
      The following commands allow you to implement some set operations quickly.

Cat A B | Sort | Uniq > C # c is a union bcat a B | Sort | uniq-d > C # c is a intersect bcat a b b | Sort | Uniq-u > C # c is set difference A-b

    • 使用LC_ALL=C

    • The settings for locale in Linux affect a large number of command-line tools, including the Sort tool.
      Most installed Linux systems set lang or other locale defaults to US 中文版.
      But this can lead to several times slower ordering and other commands.
      As a result, export lcall=c avoids processing data in the form of i18n, resulting in performance gains.

    • awk,sed

    • These two tools enable complex data substitution and modification.
      For example, the following command implements the sum of data in a lower three column in a text file.
      Using the shell to do this is 3 times times faster than Python.

awk ' {x + = $ $} END {print x} '

    • shuf

    • The command can either mix rows from a file, or randomly select rows from it.

    • sort

    • Learn how the common options for sort (-t,-k,-s) work. Note that-k1,1 will only sort the first column,
      The-K1 will be sorted according to the entire row. -S to achieve stable sequencing.
      For example, you can use this command to sort the second field first, and then sort by field.

Cat Input_file | sort-k1,1 | Sort-s-k2,2

    • tab input

    • hd,bvi

    • strings,grep

    • can help you find text in a binary file.

    • iconv,uconv

    • can help convert text encoding

    • split,csplit

5 System Commissioning
  • iostat,netstat,top,atop,htop,dstat

  • can help to understand the state of hard disk, CPU, memory, network.
    This will help you have a first understanding of what is happening in the system.

  • free,vmstat

  • These two commands are important if you want to understand the state of the memory.
    Where cached is the size of the file cache in the Linux kernel.

  • kill -3 <pid>

  • When debugging a Java program, using this command, you can find the complete stack trace in Stderr/logs.
    Heap information (contains details of garbage collection).

  • mtr,traceroute

  • can help to find network problems, the former better than Traceroute.

  • iftop,nethogs

  • These two commands can be done just to find out which port or process is consuming much network bandwidth.

  • ab,siege

  • This Apache-brought tool can help you quickly check the performance of your Web server.

  • wireshark,tshark

  • is a powerful tool for more advanced network debugging.

  • strace,ltrace

  • These two commands can help you in the case of ignorance, the program failed to run, suspended animation, crashes and other problems brought some clues.
    In addition, they can help to find some performance problems. For example,-c option can do profiling;
    The-p option can be hung onto a specified process.

  • ldd

  • Check for Shared library conditions

  • gdb

  • Learn how to use GDB to connect to a running process and get its stack trace.

  • /proc/

  • It is very useful when doing the field debugging. Like what/proc/cpuinfo, /proc/XXX/cwd, /proc/XXX/exe, /proc/XXX/fd/, /proc/XXX/smaps

  • sar

  • This command shows the history of CPU, memory, and network when it is necessary to determine why a system error occurred in the past.

  • stap, perf

  • These two tools are useful when you need a deeper analysis system, as well as a performance situation.

  • dmesg

  • This works well when there are some very unusual phenomena in the system, such as hardware or driver problems.


Commands that efficient Linux users need to know

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.