Shell scripting, simple & Powerful

Source: Internet
Author: User

  from the Code Farm supplement Linus and Linux, Chapter: Shell you may not know.   recently finished reading this book, feel that there are a lot of good content, this is one of the shell small dessert, bring to share with you, add some of my own test content. The writer writes this essay to share and improve everyone's interest in the shell.       Read the following section, it is strongly recommended that the reader open a shell  experiment, these are not da Lu Huo in the shell  textbook:)      1. sudo  !!   Executes the previous command as root . Examples of scenarios: for example, when installing packages with apt- get  in ubuntu , it is necessary to root  identity, we often forget to add sudo before apt- get . Each time you have to add sudo  and re-type this line of command, it is convenient to use sudo !! Done.      2. cd –  go back to the previous directory. Scene Example: The current directory is/ home/ a, with cd  /b  Switch to/ home/ b. You can easily switch back and forth between/ home/ a  and/ home/ b  by repeatedly executing the cd – command.      3. ^ old^ new  Replace some of the strings in the previous command. Scene:echo  "Wanderful", actually want to output echo  "wonderful". Just need to ^ a^ o  on the line, a long command of the wrong spelling of a lot of help.      4. man ascii  show ascii  Code table. Scene: Forget ascii  code table when also need google ??  especially in the case of the celestial network so "  smooth"  , more trouble in the gwf  more application of the rule, directly with the local man  ascii  yes.       This function is very useful, often encounter coding memory blur, at the same time to find out.      5. ctrl- x e  Quick Start your default editor (set by variable $ editor ).      6. netstat –tlnp  lists the port numbers that the native process listens on.      7. tail -f /path/ to/file. log | sed  '/^finished:  success$/ q '   exit tail when finished: success  appears in file. log , this command is used for real-time monitoring and filtering log   Whether a record has occurred.      8. ssh [email protected] bash < /path/ to/ local/ script. sh  run a script on the remote machine. The biggest benefit of this command is that you don't have to copy the script to the remote machine.      9. screen -d -m -s some_ name ping my_ router   Run a program that does not terminate in the background and can view its status at any time. The- d -m  parameter starts   Detach   mode,- s  specifies a session  identity. You can use the- r  command to re-"  mount"   an identified session. For more details, refer to screen  usage man screen.      10. wget --random- wait -r -p -e robots= off -u mozilla http:// www. example. com  Download the entire www. example. com  website. 11. curl ifconfig. me  when your machine is in the net, you can use this command to view the IP of the external network.      12. lsof –i  Real-time view of the activity status of native network services.      13. python -m SimpleHTTPServer  One sentence implement a http server, set the current directory to http  Service directory that can be accessed via http:// localhost: 8000  this is perhaps the most simple http  server on the planet to implement.
1[email protected] httptest]$ python-m Simplehttpserver2Serving HTTP on0.0.0.0Port8000 ...3 192.168.153.128- - [ -/dec/ the  +:Ten: $]"get/http/1.1"  $-4 192.168.153.128- - [ -/dec/ the  +:Ten: $] Code404, message File not found5 192.168.153.128- - [ -/dec/ the  +:Ten: $]"Get/favicon.ico http/1.1" 404-6 192.168.153.128- - [ -/dec/ the  +:Ten: $] Code404, message File not found7 192.168.153.128- - [ -/dec/ the  +:Ten: $]"Get/favicon.ico http/1.1" 404-8 192.168.153.128- - [ -/dec/ the  +: A: A]"get/http/1.1"  $-9 192.168.153.128- - [ -/dec/ the  +: -:Geneva]"get/http/1.1"  $-Ten[Email protected] httptest]$ netstat-LNPT One(Not all processes could is identified, non-owned processInfo A Would is not being shown, you would has to be the root to see it all.) - Active Internet connections (only servers) -Proto recv-q send-q Local address Foreign address State Pid/Program name theTcp0      0 0.0.0.0: A                  0.0.0.0:* LISTEN- -Tcp0      0 127.0.0.1:631               0.0.0.0:* LISTEN- -Tcp0      0 127.0.0.1: -                0.0.0.0:* LISTEN- -Tcp0      0 0.0.0.0:8000                0.0.0.0:* LISTEN2574/python +Tcp0      0::: A:::* LISTEN- -Tcp0      0::1:631:::* LISTEN- +Tcp0      0::1: -:::* LISTEN-
View CodeIn the directory wrote a index.html display results as follows, it's fun.
1 <HTML>2     <Head> 3     <title>Test Python Web server</title>4     </Head>5     <Body>6This is a test Python Web server,<b>Hello!</b>7     </Body>8 </HTML>
View CodeHistory | awk ' {cmd[$ 2]++; count++;} END {for (a in CMD) print cmd[A] "" cmd[a]/count* "%" A} ' | Grep-v "./" | Column-c3-s ""-t | Sort-nr | NL | Head-n10 This line of script can output your most commonly used 10 commands, so you can even insight into what kind of programmer you are. Do you know the code? It doesn't matter, the system learns * nix shell script, recommend "Linux command line and Shell script programming Daquan".    And finally the Shell's Word of wisdom: "Where There is a shell,there is a way!" This command line is very interesting and inspires you to learn about awk, sed, and sort for a quick and easy way to do your daily work.

Shell scripting, simple & Powerful

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.