It is simple and powerful to share shell usage and scripts that you may not know!
Before reading the following sections, we strongly recommend that you open a shell experiment, which is not a major commodity in Shell textbooks :)
! $
! $ 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! $
-
sudo !!
run the previous command as root.
scenario example: for example, when installing a software package with apt-Get
In ubuntu, the root identity is required, we often forget to add sudo
before apt-Get
. Each time you have to add sudo
and re-type this line of command, you can easily use sudo !!
finished.
(Chen Hao 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 .)
CD-
Return to the last directory.
Scenario example: the current directory is/Home/
, UseCD ../B
Switch/Home/B
. In this case, you can executeCD-
Command in/Home/
And/Home/B
Switch back and forth.
(Chen Hao Note: Cd ~ Is to return to your home directory, Cd ~ User is used to enter the home directory of a user)
- 'Alt +. 'or' <ESC> .'
Hot Alt +. Or ESC +. You can repeat the parameters of the last command line.
^ Old ^ new
Replace some strings in the previous command.
Scenario:Echo "wandreful"
In fact, it is intended to outputEcho "wonderful"
. Only^ A ^ o
That's all. It can be of great help for spelling long commands. (Chen Hao Note: it can also be used!! : GS/old/new)
- Du-S * | sort-N | tail
List the top 10 files in the current directory.
- : W! Sudo tee %
Save a file that can only be written by root in VI
- Date-d @ 1234567890
Time cut-off time
- > File.txt
Create an empty file, which is shorter than touch.
- MTR coolshell.cn
MTR commands are better than traceroute commands.
- Add a space before the command line. The command will not enter history.
- Echo "LS-L" | at midnight
Run a command at a certain time.
- Curl-u User: Pass-D status = "tweeting from the shell" http://twitter.com/statuses/update.xml
Use the command line method to update Twitter.
- 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
- PS aux | sort-NK + 4 | tail
List the top 10 processes that consume the most memory
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 difficult to apply the rules once in gwf, and directly use the localMan ASCII
Right.
CTRL-x e
Quickly start your default editor (set by the variable $ editor ).
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)
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.
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.
- SSH user @ host CAT/path/to/remotefile | diff/path/to/localfile-
Compare a remote file with a local file
- Net RPC shutdown-I ipaddressofwindowspc-u username % Password
Remotely shut down a Windows machine
Screen-D-m-s some_name Ping my_router
Running a segment in the background is not terminatedProgramAnd you can view its status at any time.-D-m
The parameter starts the "separation" mode,-S
Specifies the ID of a session. You can use-R
Command to re-mount a session ID. For more details, refer to screen usageMan Screen
.
Wget -- random-wait-r-p-e robots = OFF-u Mozilla http://www.example.com.
Download the entire www.example.com website. (Note: Do not go too far. Most websites have anti-crawling functions :))
Curl ifconfig. Me
When your machine is on the Intranet, you can use this command to view the Internet IP address.
- Convert input.png-gravity northwest-Background transparent-extent 720x200 output.png
Change the size of a piece
Lsof-I
View the activity status of the local network service in real time.
- Vim SCP: // username @ host // path/to/somefile
Vim Remote File
Python-M simplehttpserver
To implement an HTTP service in one sentence, set the current directory as the HTTP service directory.Http: // localhost: 8000
Access may be the simplest HTTP server implementation on the planet.
-
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: A little complicated, history | awk '{print $2}' | awk 'begin {FS = "|"} {print $1}' | sort | uniq-c | sort-Rn | head- 10)
This line outputs the ten most commonly used commands, In this way, you can even find out what type of programmer you are.
- 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 !)
Unable to readCode? It doesn't matter. Let's take a look at * nix shell script. We recommend "Linux Command Line and shell script programming".