Command line for Linux users

Source: Internet
Author: User
Tags html to text
Linux users need to understand the command line 1, basic command 1, understand the basic bash: Read the entire bashmanpage.2, learn VIM: on Linux systems, although you have Emacs and Eclipse, but VIM is still a powerful tool. 3. understand SSH and basic password-free authentication methods. Example... command line 1, basic command 1, basic bash: Read the entire bash man page. 2. learn VIM: On Linux, although you have Emacs and Eclipse, VIM is still a powerful tool. 3. understand SSH and basic password-free authentication methods. For example, use ssh-agent or ssh-add. Lingxi Zhiqui usually uses the following script to complete password-free verification, saving time and effort. Run sh nopasswd USER REMOTE_HOST. before executing this script, make sure that id_dsa.pub already exists on the local machine. If no. Run the ssh-keygen-t dsa command to obtain the result. Log on to the user's home directory on the remote machine. the. ssh folder already exists. if No. ssh folder is created. $ Cat nopasswd #! /Bin/sh scp ~ /. Ssh/id_dsa.pub $1 @ $2 :~ /Ssh $1 @ $2 "touch ~ /. Ssh/authorized_keys; cat ~ /Id_dsa.pub> ~ /. Ssh/authorized_keys; chmod 644 ~ /. Ssh/authorized_keys; exit "4. familiar with common Bash task management commands: &, Ctrl-Z, Ctrl-C, jobs, fg, bg, and kill. 5. basic file management commands: ls, ls-l, less, head, tail, tail-f, ln, ln-s, chmod, chown, du, du-sk *, df, mount 6, basic network management commands: ipconfig, ifconfig, dig 7, familiar with regular expressions, and options used by grep and egrep:-o, -A,-B 8, software installation commands: apt-get and yum cat-n: can help display the row number. II. some expressions !!: Execute the previous command again! $: Last Word of the previous command {.. b}: a number list from a to B {a, B, c}: three words a, B, c. you can use touch/tmp/{foo, bar, baz} {$1-$9} as follows: command line parameter $0: name of the command being executed $ #: number of parameters passed in the currently started command $?: The execution return value of the previous command. $: Process ID of the shell. $ *: Start all parameters of the shell script from $1. III. Daily command Ctrl-R: In bash, Ctrl-R is used to search for Ctrl-W, Ctrl-U, Alt-BackSpace: bash in History commands, ctrl-W delete the last word, Ctrl-U delete the last line, Alt-BackSpace delete the word man readline before the cursor contains a large number of default hotkey bindings in bash. cd-: returns the previous working path xargs: a very powerful command. If you are not sure whether the task can be correctly executed, you can check it with xargs echo. The following is an example using this function: find. -name \*. py | xargs grep some_function cat hosts | xargs-l {} ssh root @ {} hostname parallel: a more powerful command. you can execute tasks in parallel, split input files, and specify multiple nodes to run commands at the same time. for detailed functions, refer to this link. pstree-p: the effective tool pgrep that uses the process tree. pkill: queries a process by name or sends a signal directly to a process with the specified name. Understand the signal that a user can send to a process. For example, kill-STOP [pid] to suspend the pid process. Nohup, disown, screen, and tmux: These two commands are useful when you need to keep processes running in the background forever. Lsof, netstat-lntp: queries the current process listening port. Set: in the bash script, use set-x to get the debug output and set-e to get the error output. ;: A semicolon is used to open a sub-shell and close it after running. For example: # execute some commands in the current path (cd/some/other/dir; other-command) # The working path is still the current directory to understand multiple parameter expressions in shell: $ {name :? Error message} checks whether a variable exists. If no error message exists. $ {Var % suffix}, $ {var # prefix}: output part of the var variable except the prefix or suffix. For example, the output code is foo.txt. Var = foow.echo {{var}}.txt <,>: input/output redirection operation. Some_command> logfile 2> & 1: output the standard output and standard error output during the running of some_command to the logfile. Man ascii: get an easy-to-use ASCII table that contains 10-digit and 16-digit values. Screen and dtach: in remote ssh painting, use these two commands to save your session and avoid interruption due to network problems. Curl, curl-l, wget: in web page debugging, these commands can help you download web page code, which is very useful. Lynx-dump-stdin: Converts HTML to text xmlstarlet: this command is useful when you need to process XML. Ssh-L, ssh-D: this command helps you establish an ssh tunnel between the remote server and your machine when you need to access the webpage using a remote server. Ssh connection optimization: the following configuration can help you avoid link loss. you do not need to enter yes for confirmation every time and enable compression on the link. We recommend that you put it in. ssh/config. TCPKeepAlive = yes ServerAliveInterval = 15 ServerAliveCountMax = 6 StrictHostKeyChecking = no Compression = yes ForwardAgent = yes added before the command being entered #: The command has already been entered in half. suddenly, I want to reduce the running time, you can use Alt-# to add '#' before the command to change the entire command into a comment. In this way, you can find the command later in the command history. Cron: helps you develop scheduled tasks. Ctrl-S Ctrl-C: when you accidentally need to output a large amount of text, enter these two operations in sequence, which is faster than simply pressing Ctrl-C to terminate the program. IV. Data processing sort, uniq, uniq-u, and uniq-d: Learn about these sorting commands. Cut, paste, and join: Understand the maintenance tools for these text files. Many people forget to join after using cut. Use sort/uniq to perform the intersection, addition, and population operations of the set. assume that a and B are two text files, and the rows are unique. The following commands can quickly implement some set operations. Cat a B | sort | uniq> c # c is a union B cat a B | sort | uniq-d> c # c is a intersect B cat a B | sort | uniq -u> c # c is set difference a-B using LC_ALL = C: locale settings in Linux affect a large number of command line tools, including sorting tools. In most installed Linux systems, LANG or other locale are set to US English by default. However, this may lead to several times slower sorting and other commands. Therefore, export LCALL = C can avoid using i18n to process data and improve performance. Awk, sed: These two tools can implement complex data replacement and modification. For example, the following command calculates the sum of the data in the middle and lower columns of a text file. Using shell to perform this operation is three times faster than using Python. Awk '{x + = $3} END {print x}' shuf: this command can be used to mix the rows in a file or randomly select some rows from the command. Sort: understand how common sort options (-t,-k,-s) work. Note:-k1 and 1 will only sort the first column, while-k1 will sort the entire row. -S can achieve stable sorting. For example, first sort by the second domain and then sort by the domain, you can use this command to achieve: cat INPUT_FILE | sort-k1, 1 | sort-s-k2, 2 (tab input); in the bash command line, if you need to enter a tab, you can use Ctrl-V Or $ '\ t. Hd and bvi: for binary files, these two commands perform hexadecimal extraction and binary editing respectively. Strings, grep: helps search for text in binary files. Iconv, uconv: can help convert text encoding split, csplit: can separate files by size and by specific mode respectively. 5. system debugging iostat, netstat, top, atop, htop, and dstat: helps you understand the hard disk, CPU, memory, and network status. This helps you first understand what is happening in the system. Free, vmstat: These two commands are important if you want to know the memory status. Cached indicates the file cache size in the Linux kernel. Kill-3 : When debugging a Java program, you can use this command to find the complete stack trace and heap information (including garbage collection details) in stderr/logs ). Mtr and traceroute: helps you find network problems. The former is better than traceroute. Iftop and nethogs: These two commands can be used to find out which port or how much network bandwidth the process occupies. AB, siege: This Apache tool can help you quickly check the performance of web servers. Wireshark and tshark are powerful tools for more advanced network debugging. Strace and ltrace: These two commands can help you provide some clues about program failures, false positives, crashes, and other issues without knowing anything about them. In addition, they can help find some performance problems. For example, The-c option can be used for profiling, and The-p option can be mounted to a specified process. Ldd: check the shared library. gdb: learn how to use GDB to connect to a running process and obtain its stack trace. /Proc/: useful for on-site debugging. For example,/proc/cpuinfo,/proc/XXX/cwd,/proc/XXX/exe,/proc/XXX/fd/,/proc/XXX/smaps sar: when you need to determine why a system error occurred at a certain time in the past, this command can display the CPU, memory, and network history. Stap and perf: These two tools are useful when a deeper analysis system and performance are required. Dmesg: This is useful when the system encounters abnormal phenomena, such as hardware or driver problems.
Related Article

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.