Shell is also called the command line interface, which is the interaction interface between users and computers in * nix operating systems. Shell refers to the program that provides access to the kernel service in the operating system.
This article introduces Shell to some of the less widely known but practical and interesting things. Let's taste the dessert of shell staple food.
Popular Science
First, you may not know the following facts:
5. In Github, the world's largest source code warehouse, shell-related projects accounted for 8%, ranking among the top 5 and Java. It can be seen that in actual engineering projects, shell is a treasure. Image Source, see here
Some powerful commands
Share some shell usage and scripts that you may not know, simple and powerful!
Before reading the following sections, we strongly recommend that you open a shell experiment, which is not a major commodity in shell textbooks :)
1 ,! $ <! $ Is a special environment variable, which represents the last string of the previous command. For example, you may:
$ Mkdir mydir $ Mv mydir yourdir $ Cd yourdir |
You can change it:
$ Mkdir mydir $ Mv! $ Yourdir $ Cd! $ |
2. sudo !! Run the previous command as root.
Scenario example: for example, if you use apt-get In Ubuntu to install the software package, you need the root identity. We often forget to add sudo before apt-get. Every time you have to add sudo and re-type this line of command, you can easily use sudo !! Complete.
Chen Hao: cool shell blogger @ left ear mouse) Note: In shell, sometimes you enter a long command, you can use it! Xxx to repeat the latest command. For example, if you have previously entered vi/where/the/file/is, you can use it next time! Vi re-obtains the last vi command .]
3. cd-Return to the last directory.
Scenario example: the current directory is/home/a. Use cd ../B to switch to/home/B. In this case, you can execute the cd-command repeatedly to switch back and forth between/home/a and/home/B.
Chen Hao Note: cd ~ Is to return to your Home directory, cd ~ User is used to enter the Home directory of a user)
4. 'alt +. 'or' <ESC>. 'hot ALT +. or esc +. You can repeat the parameters of the last command line.
5. ^ old ^ new replaces some strings in the previous command.
Scenario: echo "wandreful", in fact, is to output echo "wonderful ". You only need ^ a ^ o, which is helpful for spelling long commands. Chen Hao Note: You can also use it !! : Gs/old/new)
6. du-s * | sort-n | tail
List the top 10 files in the current directory.
7.: w! Sudo tee %
Save a file that can only be written by root in vi
8. date-d @ 1234567890
Time cut-off time
9.> file.txt
Create an empty file, which is shorter than touch.
10. mtr coolshell.cn
Mtr commands are better than traceroute commands.
Add a space before the command line. The command will not enter history.
11. echo "ls-l" | at midnight
Run a command at a certain time.
12. curl-u user: pass-d status = "Tweeting from the shell" http://twitter.com/statuses/update.xml
Use the command line method 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 emails
14. ps aux | sort-nk + 4 | tail
List the top 10 processes that consume the most memory
15. man ascii
Displays the ascii code table.
Scenario: Do I still need google when I forget the ascii code table? Especially when the tianchao network is so "smooth", it is more troublesome to apply the rules once in GWF. Use local man ascii.
16. ctrl-x e
Quick Start of your default EDITOR is set by the variable $ EDITOR ).
17. netstat-tlnp
Lists the port numbers listened to by local processes. Chen Hao Note: netstat-anop can display the process listening on this port number)
18. tail-f/path/to/file. log | sed '/^ Finished: SUCCESS $/Q'
When Finished: SUCCESS occurs in file. log, tail is exited. This command is used to monitor and filter logs in real time.
19. ssh user @ server bash </path/to/local/script. sh
Run a script on a remote machine. The biggest advantage of this command is that you do not need to copy the script to a remote machine.
20. ssh user @ host cat/path/to/remotefile | http://images.51cto.com/files/uploadimg/20121123/1109370.png-gravity NorthWest-background transparent-extent 720 × 200 output.png
Change the size of a piece
21. lsof-I
View the activity status of the local network service in real time.
22. vim scp: // username @ host // path/to/somefile
Vim Remote File
23. python-m SimpleHTTPServer
To implement an HTTP service in one sentence and set the current directory as the HTTP service directory, you can access it through http: // localhost: 8000. This may be the simplest HTTP server implementation on the planet.
24. history | awk '{CMD [$2] ++; count ++;} END {for (a in CMD) print CMD [a] "" CMD [a]/count * 100 "%" a} '| grep-v ". /"| column-c3-s" "-t | sort-nr | nl | head-n10
(Chen Hao Note: It's a bit complicated, history | awk '{print $2}' | awk 'BEGIN {FS = "|"} {print $1}' | sort | uniq-c | sort-rn | head- 10)
This line of instinct outputs the ten most commonly used commands, which can even gain insight into what type of programmer you are.
25. tr-c "[: digit:]" </dev/urandom | dd cbs = $ COLUMNS conv = unblock | GREP_COLOR = "1; 32 "grep-color" [^]"
Want to see the screen effect of Marix? Not very similar, but also Cool !)
Can't read the line of code? It doesn't matter. Let's take a look at * nix shell script. We recommend "Linux Command Line and Shell script programming".
Finally, let's talk about Shell's best saying: (Chen Hao note: the mug below is very good, and 404null.com is quite interesting ).
"Where there is a shell, there is a way !"
Unix Shell color changing mug