---------Transferred from http://www.runoob.com/linux/linux-shell-array.html----------Copyright belongs to the original! Shell some 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:)
!$
!$是一个特殊的环境变量,它代表了上一个命令的最后一个字符串。如:你可能会这样:
$mkdir mydir
$mv mydir yourdir
$cd yourdir
可以改成:
$mkdir mydir
$mv !$ yourdir
$cd !$
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)
- ' ALT +. ' or ' <ESC>. '
Jechin ALT +. or esc+. You can repeat the arguments for the last command line.
^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)
- Du-s * | Sort-n | Tail
Lists the largest 10 files in the current directory.
- : w!sudo Tee%
Save a file in vi that only the root can write
- Date [email protected]
Time cut-off time
- > file.txt
Create an empty file that is shorter than touch.
- MTR coolshell.cn
The MTR command is better than traceroute.
- Add a space before the command line, and the command will not enter the 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
Command-line way 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 messages
- PS aux | Sort-nk +4 | Tail
List the first 10 most memory-consuming processes
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.
ctrl-x e
Quickly launch your default editor (set by variable $editor).
netstat –tlnp
Lists the port numbers that the native process listens on. (Chenhao Note: Netstat-anop can show the process listening on this port number)
tail -f /path/to/file.log | sed ‘/^Finished: SUCCESS$/ q‘
Exit tail when Finished:success appears in File.log, this command is used to monitor and filter log for a record in real time.
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.
- SSH [email protected] 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
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
.
wget --random-wait -r -p -e robots=off -U mozilla http://www.example.com
Download the entire www.example.com website. (Note: Not too much, most sites have anti-crawling features:))
curl ifconfig.me
When your machine is in the net, you can use this command to view the IP of the external network.
- Convert input.png-gravity northwest-background transparent-extent 720x200 output.png
Change the size of a piece
lsof –i
View the active status of a native network service in real time.
- Vim Scp://[email Protected]//path/to/somefile
Vim a remote file
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.
- Tr-c "[:d igit:]" "" </dev/urandom | DD cbs= $COLUMNS Conv=unblock | Grep_color= "1;32″grep–color" [^] "
Want to see Marix's screen effect? (not very similar, but also very cool!)
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:
"Where There is a shell,there is a way!"
---------Transferred from http://www.runoob.com/linux/linux-shell-array.html----------Copyright belongs to the original!
<< reprint >>shell Some mighty commands