"Reprint" What are the time-saving tips that every Linux user should know

Source: Internet
Author: User
Tags garbage collection

There are netizens in the question and answer site Quora asked: "What are the time-saving skills, every Linux user should know?" "Joshua Levy usually works on the Linux platform, and he has accumulated a lot of practical command-line skills, and he picked out some of the answers." For technical users, these skills are important or practical, but not many people know. The following is a bit long, generally speaking, users do not need to understand all the content, but in order to achieve the time-saving convenience of the purpose, Joshua Levy still spared no effort to do proofreading, to ensure that each listed is worth reading, if you are a Linux heavy users.

In order to get more information about a command mentioned in this article, try "Man < command name >", in some cases, in order for the command to execute properly, you must install the appropriate package, either with aptitude or yum. If it fails, help Google.

basic
• Learning-based bash. In fact, reading the entire Bash Help Handbook is easy to understand and not too lengthy. Some of the other optional shell skins may be more beautiful, but bash is powerful and always available (learn zsh or tcsh in many cases you'll get a limit).
• Learn vim, and for random edits under Linux, there are few tools to make it right (even if you spend most of your time using Emacs or Eclipse).
• Learn about SSH, and skip the basics of password verification on every login, via Ssh-agent,ssh-add and more.
• Familiarize yourself with the work management under bash: &,ctrl-z,ctrl-c,jobs,fg,bg,kill, and more.
• Basic file management: LS and ls-l (specifically, learn the meaning of each column field listed in "Ls-l"), Less,head,tail,tail-f,ln,ln-s (Learn the difference between soft links and hard links), Chown,chmod, Du (Quick understanding of disk overall occupancy), Df,mount.
• Basic network management commands: IP or Ifconfig,dig.
• Learn about regular expressions, and the different command options for grep and Egrep, -0,-a,-b are worth knowing.
• Learn to use Apt-get or yum (depending on your release package) to find and install the package you need.

daily use
• Use the ctrl-r to search the history of a command when using bash.
• When using bash, use Ctrl-w to clear the last word and use ctrl-u to clear the entire line. You can view the man readline to get the binding settings for the default key in bash. A lot of content. Like alt-. (Note: The point) iterates over the parameters used in the previous command, alt-* expands the matching pattern of the parameters.
• Go back to the last working directory: CD-.
• If you change your mind halfway through your command, you can use alt-#来在命令前面增加一个 # to make it a one-line comment (or use ctrl-a to go back to the beginning of the command and then type #). You can return it later by searching the history record.
• Use Xargs (or parallel). It's very powerful. Note that you can control how many items are executed per row (-l) and how concurrency (-P) can be controlled. If you are not sure that it will work as you wish, use Xargs first. Furthermore,-l{} is useful. For example:
Find-name *.py | xargs grep some_function
Cat hosts | xargs-l{} SSH root at {} hostname pstree-p can be easily displayed The entire process tree.
• Use Pgrep and pkill to discover processes by name or to signal processes (the-f option is useful).
• Understand the kind of signal you can send to a process. For example, to suspend a process, use kill-stop [process id]. Refer to man 7 signal for the entire list.
• If you want a background process to run all the time, use Nohup or disown.
• Use NETSTAT-LNTP to detect which processes are listening. You can also use lsof.
bash script, use Set-x to debug the output. Use SET-E to terminate execution when there is an error. To make a strict output error, consider using Set-o pipefail (although this topic is somewhat complicated). For more complex scripts, you can also use a trap. In the
bash script, a child shell (written in parentheses) is a convenient way to organize commands. A very common example is moving to another working directory temporarily, for example:

do something in the current directory (CD/some/additional/directory; perform other actions) #继续在原来的目录下执行 • Be aware that there are many kinds of variable expressions in bash. Check if a variable exists: ${name:? error message}. For example, if a bash script requires a single variable, just write Input_file=${1:?usage: $ inpute_file}. Numeric extension: i=$ ({(i+1)%5}). Sequence: {1..10}. Collation of Strings: ${var%suffix} and ${var#prefix}. For example:

If var==foo.pdf, then echo ${var%.pdf}.txt #会打印 "Foo.txt". • With < (other instructions), the output of a command can be treated as a file's content. For example, to compare local and remote/etc/hosts files, you can use Diff/etc/hosts < (SSH [remote host] cat/etc/hosts).
• Learn about "here documents" in bash, such as Cat < log files 2>&1 redirect standard output and standard errors. It is common practice to add "</dev/null" to your current terminal in order to ensure that an instruction does not leave an open file descriptor for the standard input.
• Use man ASCII to get a complete ASCII table with corresponding 16-and 10-binary values.
• When connecting to a remote terminal via SSH, use screen or Dtach to maintain your session and prevent interruption. In SSH, it is useful to know how to use the-l or-D option (and sometimes the-R), for example, if you access a Web page from a remote server.
• Optimizing your SSH options may also work. For example, the following. Ssh/config content in some network environments can prevent the connection off the line, when connected to the new host does not need to reconfirm, jump authentication, and also use compression (for some low-bandwidth connection environment in the use of SCP will be helpful).
Tcpkeepalive=yes serveraliveinterval=15 serveralivecountmax=6 stricthostkeychecking=no Compression=yes ForwardAgent =yes

Data Processing article
• Turn HTML into text: Lynx-dump standard input
• It will be great if you are dealing with Xml,xmlstarlet.
• It is convenient for Amazon S3,s3cmd (though immature, there may be some less-than-good features).
• Learn about the sort and uniq (including the-U and-D options for Uniq).
• Learn cut,paste,join to manipulate text files. Many people use cut but forget to join.
• It is very convenient to use Sort/uniq when you want to add, subtract, and differential operations between files. If A and B are two of the already-heavy text files, then the operations will be fast and can be performed between files of any size, even to gigabytes of bytes. (Sort is not limited by memory, but if/tmp is in a very small root partition, you may need to use the-t option)
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 b | Sort | Uniq-u > C # c is set difference A-b understand that localization can affect the work of many command lines, including sequencing and performance. Most Linux installers set lang or some other localized variable to a local setting similar to American English. This makes sort and some other commands much slower to run. (Note that even if you use UTF-8 encoded text, you can still safely sort through the ASCII code order, which is a lot of use) to avoid i18n slowing down everyday work, using the traditional byte-based sort order, using the export lc_all=c (in fact, Consider adding in your. bashrc).
• Learn basic awk and SED commands to do simple data processing. For example, sum the numbers in the third column of a text file: awk ' {x + = $ $} END {print x} '. This is probably three times times faster than the equivalent Python speed and the code length is 3 times times shorter.
• Replace a string in place in all occurrences of the file.
Perl-pi.bak-e ' s/old-string/new-string/g ' my-files-*.txt uses Shuf to randomly shuffle a line in a file or select a random line.
• Learn about the various options for sort. Know how the key value works. In particular, when you want to use-K1, pay extra attention to: 1 Sorts only the first field,-k1 means sort by the entire row.
• Stable sequencing (sort-s) may be useful. For example, if you sort by the second field, and then sort by the first field, you can use a sort-k1,1 | Sort-s-k2,2
• If you need to write a tab key in the command line in bash, press CTRL + V, or $ ' t ' (the latter is better because you can copy, paste).
• For binary files, use HD for simple export 16 binary notation or binary editing with BVI.
• For binary files, strings (and grep, etc.) allows you to discover the byte bits (0101) of the file. To make a file, you can try the iconv, or if you want to use more advanced usage, try Uconv, which can support some advanced Unicode aspects. For example, this command can have the accent lowercase and removed (by extending and discarding):
Uconv-f Utf-8-T utf-8-X ':: Any-lower; :: ANY-NFD; [: nonspacing Mark:] >; :: ANY-NFC; ' < Input.txt > output.txt to slice the file, you can try split (by size) or csplit (slice by pattern).

System Debug Chapter
• For Web debugging, curl and curl-l will be useful, as well as the same part of the wget function.
• If you want to know the status of a disk/cpu/network, you can use Iostat,netstat,top (better, with Htop), and (in particular) Dstat, which is very convenient for you to quickly understand what is happening in your system. If you want to know the current state of the memory, you can use free and vmstat, as well as understand what each output means. In particular, you need to know that the value of "cached" is the size of the space that the Linux kernel retains to make the file cache, so the actual available memory is the corresponding value of the "free" item.
Java's system debugging is completely different, but there is a simple trick on sun and other JVMs that you can run kill-3, get a full stack call trajectory, and the aggregate usage of the heap (including the garbage collection details that are generated, where the bread contains a lot of information), will be directed to a standard error or log.
• Use MTR as a better network trace to identify problems with the network.
• To see if a disk is full, NCDU is faster than the general "Du-sk *".
• To see which sockets or processes are taking up bandwidth, try Iftop or netlogs.
The AB tool (released with Apache's installation package) is useful for detecting the performance of a network server, and for more complex stress tests, you can try siege. For more serious network problems debugging, try Wireshark or Tshark. Learn about Strace and Ltrace. This can be helpful when a program suddenly fails, hangs, or crashes, and you are overwhelmed, or if you want to know the overall performance of the program. You can note the-C and-P options.
• Learn some questions about using LDD to check shared library functions.
• Learn how to use GDB to connect to a running program and get its call stack.
• Use/proc. It will be very helpful for on-site commissioning. For example:/proc/cpuinfo,/PROC/XXX/CWD,/proc/xxx/exe,/proc/xxx/fd/,/proc/xxx/smaps.
• When you want to debug a problem that has occurred over a period of time, the SAR can be useful to display statistics about the CPU, memory, and network over time.
• For deeper system performance optimizations, you can focus on STAP (SYSTEMTAP) or perf.
• Try DMESG (such as hardware or driver problems) when there are some very strange problems.

Reference Documentation:

Http://www.quora.com/What-insights-do-expert-hackers-have-for-novice-programmers

http://www.yebohe.cn/article/f79b5177e0905ac085ebcef11f699b06/

Http://www.quora.com/What-are-some-time-saving-tips-that-every-Linux-user-should-know

http://segmentfault.com/a/1190000000379479

"Reprint" What are the time-saving tips that every Linux user should 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.