The shell is also called the command line interface, which is the interface between the user and the computer under the *nix operating system. The word shell refers to the program in the operating system that provides access to the kernel service.
This article introduces some of the shell's non-well-known, but useful, and interesting knowledge, and the right to taste the dessert after the shell staple.
A few powerful commands
Share some shell usages and scripts that you may not know about, simple & powerful!
Before reading the following sections, it is strongly recommended that the reader open a shell experiment that is not da Lu Huo in the shell textbook:)
sudo !!
Executes the previous command as root.
Examples of scenarios: for example apt-get
, when installing a package in Ubuntu, you need root, and we often forget to add it in front of you apt-get
sudo
. Each time you have to add sudo
and re-type this line of command, it is very convenient to use the sudo !!
finished.
(Chenhao Note: Under the shell, sometimes you will enter a very long command, you can use!XXX to repeat the last command, for example, you have previously entered, Vi/where/the/file/is, the next time you can use the!vi to the last time the VI command. )
cd –
Go back to the previous directory.
Scenario Example: The current directory is /home/a
, with the cd ../b
switch to /home/b
. You can cd –
/home/a
switch between and fro conveniently by repeatedly executing commands /home/b
.
(Chenhao Note: cd ~ is to go back to their home directory, CD ~user, is to enter a user's home directory)
^old^new
Replaces a partial string in the previous command.
Scene: echo "wanderful"
, actually want to output echo "wonderful"
. Just the right amount of time, a lot of help with the misspelling of ^a^o
a long command. (Chenhao Note: !!:gs/old/newcan also be used)
man ascii
Displays the ASCII code table.
Scenario: Do I need Google to forget the ASCII code table? Especially in the celestial network so "smooth" situation, it is more trouble in GWF more application of a rule, directly with the local man ascii
bar.
screen -d -m -S some_name ping my_router
The background runs a program that does not terminate and can view its status at any time. The -d -m
parameters start "Detach" mode, -S
specifying the identity of a session. You can -R
re-mount the session of an identity by command. Please refer to screen usage for more details man screen
.
python -m SimpleHTTPServer
One sentence to implement an HTTP service, the current directory is set to the HTTP service directory, you can http://localhost:8000
access this is perhaps the most simple HTTP server on the planet implementation.
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
(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 your most commonly used 10 commands, so you can even gain insight into what kind of programmer you are.
Do you know the code? It doesn't matter, learn the *nix shell script, recommend the Linux command line and Shell script programming encyclopedia.
Finally, the shell's Words of wisdom: (Chenhao Note: The mug below is very good ah, 404null.com very interesting)
You may not know the shell