A good thing under the Linux command line

Source: Internet
Author: User
Tags ack webp python script rsync

650) this.width=650; "Src=" http://mmbiz.qpic.cn/mmbiz_png/ Zjosibraw8clwlvibetrzxwwuy4je8rmiconxyukfmuia43wtxta55grfbfia17sgcmnmfrcl2swpzwm9pbc2ndyhnw/640?wx_fmt=png &tp=webp&wxfrom=5&wx_lazy=1 "style=" margin:0px;padding:0px;height:auto;vertical-align:top; Border-style:none;width:auto; "alt=" 640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy= "/>



650) this.width=650; "width=" 650 "src=" http://mmbiz.qpic.cn/mmbiz/ p6vlqvia1uicwutdysibyelgvclgzbgurlkfibp3kryetvj1b8gib4msykk8dobxwricgrftfuqslz3dfzfc5alzfyg/0?wx_fmt=gif& Tp=webp&wxfrom=5&wx_lazy=1 "style=" Margin:0px;padding:0px;height:auto;vertical-align:top;border-style: None;width:auto; "alt=" 0?wx_fmt=gif&tp=webp&wxfrom=5&wx_lazy=1 "/>

List the useful Linux command-line commands you may not have noticed

Now do the mobile application of the site is the most attention is the promotion, to promote the success of the more than half, relatively no exposure to the product is also very difficult to do. The vast majority of Linux command-line promotions are simply rotten to the point of view. A wide variety of Linux useful command-line tools are quietly lying in your release version of the default installation of the package, many times only when you encounter any problem when the Internet search a circle to know. More egg pain is a lot of things in this once you know, you will think I did not have this how to go on. So here I'll list some of the things I've used, most of which are available by default, or can be easily accessed with package management tools.

This article only discusses what's in the Linux environment, and it's clear that MacOS works as well. In fact, a lot of things, although there are Windows can be found but the configuration is more troublesome, here is no longer carefully said. Many things like Linux veterans seem to think hahaha is too basic. But like cd , ls mkdir These too basic writing here also appears too amateur, so a lot of very common commands here I also skipped. Like git this heavyweight tool, and sed , awk these can be alone out of the book of Things I think I also do not know, so this is a simple function of small things. But these little problems just forget it ...

If you have more time

... So why not read this book: <<the Linux Command line\>>. The content of the book is the same as the title, the introduction of the so-called "Linux command Line" in all aspects, this article is also a lot of content from the book to see. The website has the PDF legal free download, the writing is very good can very casually see not to feel the pressure is too big. Most of all, if you are just in touch with Linux then this is probably the best tutorial, I regret that I did not know the book. So the other Linux beginner's tutorial should be the bird's private dish, which is so famous that I feel nothing to say.

If you have no time to spare,

The following is a random list of some of the command-line tools that I think are great. Here is not a detailed description of the various parameters, you should do is man xxx to use to view the document. If these programs are not installed in your distribution, please check them manually. Mac users should be able to find them in homebrew.

Tmux

Although the order is very random, but this one must be ranked first. Many people use Linux in the state of their own machine is Windows, with putty a connection to a Linux server to work. In this way, every time you disconnect, the program you run will be killed. You may want to be able to keep the open program there when you exit, and you will be able to automatically get to the previous working state the next time you connect. tmuxis the ultimate solution to this problem. Their function is to create multiple "windows" in a Terminal, on the other hand, if you close the connection or accidentally drop the line, they will not be turned off by default, the next time you can use tmux attach to restore your previous working status.

If you haven't heard of this or something like that screen , you should give me a little cash.

Tree

lsMay be one of your most used commands. treeYou can recursively list all the files in the directory and show them in a tree form:

$ tree.├──b├──c│└──d└──what

The corresponding also has a pstree process tree that can be displayed in this way.

Ack

I remember being asked in the interview, "please write how to call grep to list all the files in the current directory, containing a string of lines." My answer to this question is "use ack it." ackThe official website domain name is called betterthangrep.com. Since it is so common to find a string in all files downloaded in the current directory, execution can be ack foo found in all files in the current directory foo . ackBy default, many useless directories and files are skipped, making the lookup faster and the output more accurate. In addition, the color display, which is turned on by default, is comfortable to use.

ackCurrently, most distributions do not, and if you are using Ubuntu, the name of the package is the same as the name of the executable ack-grep file. You can view the documentation here.

Rsync

For example, you have a local computer, remote has a server. You want to copy all of your folders to somewhere on the other side. You often have to update this folder, hoping that some way to update the part can be quickly synchronized past. How is this supposed to be done? If you don't know, rsync you might want to use git it, build one ftp , or use it scp or whatever. But the truth is that the rsync real software that is born to solve this problem accurately. rsyncthe best part is the differential update, which simply passes the missing things on the other side, and you don't need any extra configuration to fly faster. An example:

Rsync-arvuzp--chmod=g+rx./built/[Email Protected]:/var/www/site
Aspell

As a programmer, you will someday have to write English documents. It is too normal for me to have a spelling error when my mother tongue is not English. If you use Word, you will be underlined, but if you write comments in the code or write markdown under Linux, there seems to be no way. In fact this is also a problem that has been solved, it aspell is to do this. aspellany plain text can be checked for spelling, and as a programmer-oriented tool it can detect file types, such as a C + + program that only checks the words in the comments.

Tee

Sometimes the results of some commands run very long, and you may use less them to look up and down. Or you might use > it to redirect to a file. But sometimes the program may require you to enter y to confirm, or some programs run for a long time, just redirect the word is not sure whether it is running normally. teecan be done and output to the screen, but also redirected to the file. A simple example:

$ echo waht | Tee OUT.txt

wahtwill be output to the screen and will be written to the out.txt file. In tee fact, the input and output in the T middle pull a lot of pulled out a, it is quite image.

It is worth mentioning that vim can also be used in pipe, examples are as follows:

$ echo waht | Vim-
<ctrl+r\>

You must know that using the keyboard up and DOWN ARROW keys can find your history back and forth, so for example there is a long time ago command you may need to press on to find. In fact this time just enter a part and press <ctrl+r\> bash will help you search backwards. Continuous press <ctrl+r\> can be searched sequentially. (or just press <ctrl+r\> to enter). Then, in the example above, enter and echo press the <ctrl+r\> effect as follows:

(reverse-i-search) ' echo ': Echo waht | Vim-

There is a search in the future so generally there will be a search. Unfortunately, the next search shortcut is <ctrl+s\>, if you try to click on it will find ... It's like the machine's not responding. This is because <ctrl+s\> in most cases the default is XOFF, which represents a pause to receive input. Press <ctrl+q\> to recover. Of course you can bind the forward search to another key, please search by yourself.

Cloc

Although the number of lines of code does not indicate any problems, sometimes it is not known why you want to know. cloccan accurately calculate the number of lines of code, the comments and spaces are separated. If you are a legendary project manager, start today with cloc a salary for your men. The following screenshot is attached:

$ cloc /usr/include/    9628 text files.    9308  unique files.     434 files ignored. t=39.0 s  (227.6&NBSP;FILES/S,&NBSP;39948.2&NBSP;LINES/S)-------------------------------------------- -----language        files    blank   Comment      code-------------------------------------------------c/c++  header     8875   217366   287013    1053368teamcenter def      1       48         0       186---------------- ---------------------------------sum:              8876   217414   287013   1053554------------------------------------------------- 
Printenv

With the set ability to view all shell variables also includes shell functions, but some of them are only available in the current shell. And often you need to look for an export environment variable that is defined by. printenvIt's used to do this.

Set-o VI

bashOr perhaps the vast majority of common shells are actually supported vi in the way of command-line editing, such as set up set -o vi you can use familiar hjkl to move, use w , b to skip words and so on.

Similarly, if you set the EDITOR environment variable, the input fc can be put into the editor to edit the previous input command line, as long as the save will be executed. On the contrary, giving up saves is tantamount to giving up.

Find

One of the biggest gains I've ever looked at when I read the book above is that I finally learned to use it find . This has now become a command that I use almost every day. For example, I want to add all the files in the directory png to this git commit, I can use:

Find. -name ' *.png '-exec git add {} '; '

If you're familiar with find it, you'll know that the last thing you can do is ; + better, but use it for a purpose. This command, while seemingly simple, will fail with the single quotation mark omitted or the double quote command. These are the escape rules that involve "shell variable expansion" and quotes, although it's annoying but in fact these are just a few simple rules, and the consistency is very good. So if you take the time to figure things out, this simple problem can be easily done.

Type

If foo It is a program that can be run directly on the command line, you should know which foo where to find foo the executable path. But the commands that can be executed at the command line do not necessarily correspond to an executable file, it can be alias, the Shell's own function, and the user's own function, and so on. So sometimes which it makes people wonder when they can't find anything. You can actually use type foo it to see foo what the type is.

Help

As mentioned above, "BUILTIN command" is also built-in commands, which are some basic or impossible commands provided by the shell. Normally you can use it man to view the document, but for built-in commands you man jump to the Shell's own manpage, and in some systems it's a huge page. You need to find what you want to see, and some systems simply don't have the relevant information. This is the time to use help this built-in command to solve the problem: for example, the accepted options to be viewed set can be help set easily found.

Env

You should know that the function in the #! first line of the script (shebang) is to specify its ' runtime '. For example, you want to write a Python script, but you don't really care about its version, or you're not sure where the executable file is on a different machine. Then it env can come in handy here. It can be written so that it #!/usr/bin/env python will be executed with the current PATH found python . On the other hand this is also a give you a chance to re-select ' Runtime ' without modifying the code.

File

If you want to know exactly what type of file is on a path, then it's the right thing to do file . It can give a meaningful explanation of anything, and a lot of important information about the binaries will be listed.

Strings

"I put my secret in this program written in C + +. Run it to enter the correct password to see ". In fact, in case you run into this situation strings program-written-in-cxx , you can see it in nine to ten. It provides a more accurate list of C-style strings contained in binary files. It doesn't seem to make any sense, but it really does work for you, like knowing which version of GCC a program is compiled with the strings possible results.

Od

The whole process should be "object dump", which can be displayed as octal, hexadecimal, or otherwise. I think that in most cases this is all used od -c , and the files are released as ASCII code. One use case is what line ending is used to see the file. For example od -c foo.txt , execution displays the following results:

$ od-c foo.txt0000000 h l l o \ t w o r l d \ r \ n y e a0000020 h0000021

Can see clearly \t is the tab character, \r\n is a Windows-style line break



This article is from the "Home of Linux" blog, please be sure to keep this source http://pyhton.blog.51cto.com/8763915/1858180

A good thing under the Linux command line

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.