You may not know the shell (interesting knowledge) _linux Shell

Source: Internet
Author: User
Tags curl mkdir

The shell is also called a command-line interface, which is the interface between the user and the computer under the *nix operating system. The term shell refers to programs in the operating system that provide access to kernel services.

This article introduces some of the shell's not-so-well-known, but practical and interesting knowledge, the right to taste the shell staple after the dessert bar.

Science

First, a few facts you may not know:

    The
      Shell was born almost together with the UNIX operating system, and the first Unix shell was Ken Thompson (Ken Thompson) Multics the shell for the 1971-year rewrite and named Thompson Sh. Even the later popular bash (a variant of the shell), which is actually older than all of the Linux kernel currently in vogue, can be described as having a shell and kernel on a Linux system. Most of the current default shells in the *nix and MacOS operating systems are Bash,bash created by Brian Fox in 1987, the full name Bourne Again Shell (bash). You may have heard that in addition to bash, there are Bourne shell (SH), Korn Shell (ksh), C shell (including csh and tcsh), but do you know that there are about 50 different kinds of shells on the planet altogether? To get to know them, please refer to http://www.freebsd.org/ports/shells.html. Each month Tiobe a programming language ranking to show the popularity of various languages. The ranking index synthesizes the number of engineers who use the language globally, the number of courses taught and the number of third-party vendors. As of November 2012, Tiobe's list of programming languages, Bash's index was 0.56% ranked 22 digits. If you count its awk 0.21% and Tcl 0.146%, you'll probably be able to line up to 14. Note that it does not include Bash's homologous siblings csh, ksh, etc., and that the Shell family is expected to be close to the top ten. It is worth mentioning that the shell has always been ranked stable, unlike some "nouveau riche" languages, such as Objective-c, the popularity of these languages is entirely due to the current rise of the apple system, but the upsurge is likely to come faster.

5. The world's largest source code warehouse GitHub, the number of shell-related projects accounted for 8%, among the top 5 and Java equivalent, visible in the actual combat project, the shell is Paulto. Picture sources, see here

Some mighty commands.

Share some of the shell usages and scripts that you may not know, simple & powerful!

Before reading the following sections, it is strongly recommended that the reader open a shell experiment, which is not da Lu Huo in the shell textbook Oh:

1.!$<!$ is a special environment variable that represents the last string of the previous command. Such as: You may be like this:

$mkdir Mydir
$MV Mydir Yourdir
$CD Yourdir

Can be changed to:

$mkdir Mydir
$MV!$ Yourdir
$CD!$

2, sudo!! Executes the previous command as root.

Scenario Examples: For example, Ubuntu uses Apt-get to install software packages that require root identity, and we often forget to add sudo before apt-get. Each time you have to add sudo and retype this line of command, it is convenient to use sudo!! Done.

Chenhao: Cool shell blogger (@ Left ear mouse) Note: Under the shell, sometimes you will enter a very long command, you can use!XXX to repeat the last command, for example, you previously entered, vi/where/the/file/is, next time you can use!vi The last VI command was heavy. 】

3, cd– back to the previous directory.

Examples of scenarios: 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.

(Chenhao Note: cd ~ is to go back to your home directory, CD ~user, is to enter a user's directory)

4. ' Alt +. ' or ' <ESC> ' Jechin ALT +. or esc+. You can repeat the arguments to the last command line.

5. ^old^new replaces a partial string in the previous command.

Scene: Echo "wanderful" is actually trying to output the echo "wonderful". It only takes a ^a^o to have a lot of help with the wrong spelling of a long command. (Chenhao Note: You can also use!!:gs/old/new)

6, Du-s * | Sort-n | Tail

Lists the largest 10 files in the current directory.

7.: w!sudo Tee%

Save a file in vi that only root can write

8, date-d@1234567890

Time Cut Time

9, > File.txt

Create an empty file that is shorter than the touch.

10, MTR coolshell.cn

MTR command is better than traceroute.

Add a space before the command line, and the command does not go into the history.

11, echo "Ls-l" | At midnight

Run a command at some time.

12, Curl-u user:pass-d status= "Tweeting from the shell" Http://twitter.com/statuses/update.xml

command line to update Twitter.

13, Curl-u username–silent "Https://mail.google.com/mail/feed/atom" | Perl-ne ' print ' \ t ' if/<name>/; Print "$2\n" if/< (Title|name) > (. *) <\/\1>/; '

Check your Gmail unread messages.

14, ps aux | Sort-nk +4 | Tail

Lists the first 10 most memory-consuming processes

15, man ASCII

Displays the ASCII code table.

Scenario: Do you still need Google when you forget your ASCII code table? Especially if the celestial network is so "smooth", it is even more troublesome to apply the rule more often in GWF, directly using the local man ASCII.

16, Ctrl-x E

Quickly start your default editor (set by the variable $editor).

17, NETSTAT–TLNP

Lists the port numbers on which the native process listens. (Chenhao Note: Netstat-anop can display the process listening on this port number)

18, Tail-f/path/to/file.log | Sed '/^finished:success$/q '

Exit tail when finished:success occurs in the File.log, which is used to monitor and filter the log for real time to see if a record appears.

19, SSH User@server Bash </path/to/local/script.sh

Run a script on the remote machine. The best thing about this command is that you don't have to copy the script to the remote machine.

20, ssh user@host cat/path/to/remotefile |http://files.jb51.net/files/uploadimg/20121123/1109370.png-gravity Northwest-background transparent-extent 720x200 Output.png

Change the size of the picture

21, Lsof–i

View the active state of the local network service in real time.

22, Vim Scp://username@host//path/to/somefile

Vim a remote file

23, Python-m Simplehttpserver

One word implementation of an HTTP service, the current directory as the HTTP service directory, can be accessed through http://localhost:8000 this is perhaps the planet's simplest HTTP server implementation.

24, History | awk ' {cmd[$2]++;count++;} End {to (a in CMD) print Cmd[a] "cmd[a]/count*100"% "A}" | Grep-v "./" | Column-c3-s ""-t | Sort-nr | NL | Head-n10

(Chenhao Note: A bit complicated, History|awk ' {print $} ' |awk ' BEGIN {fs= ' |} {print $} ' |sort|uniq-c|sort-rn|head-10)

This line of script can output the 10 commands you use most often, and you can even gain insight into what kind of programmer you are.

25, Tr-c "[:d igit:]" "" </dev/urandom | DD cbs= $COLUMNS Conv=unblock | Grep_color= "1;32″grep–color" [^] "

Want to see the Marix screen effect? (not very much alike, but also very cool!)

Don't know the code? It doesn't matter, system learn *nix shell script, recommend "Linux command line and Shell script programming encyclopedia".

Finally, the words of the shell: (Chenhao Note: The following the mug is very good ah, 404null.com very interesting).

"Where There is a shell,there is a way!"

Unix Shell Color Mug

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.