Some powerful shell commands use basic tutorials

  
 

Share some shell usage and scripts that you may not know, simple & powerful!

Before reading the following sections, readers are strongly encouraged to open a shell experiment. These are not the big roads in the shell textbooks :)

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 !! Execute the previous command as root.

Scenario example: For example, when Ubuntu uses apt-get to install a package, it needs to be rooted. We often forget to add sudo before apt-get. Every time you have to add sudo and re-type this line of commands, then you can easily use sudo!!

[Note: In the shell, sometimes you will enter a long command, you can use !xxx to repeat the most recent command, for example, you have previously entered, vi /where/the/file/Is, next time you can use !vi to regain the last vi command. 】

3, cd – back to the previous directory.

Scenario example: The current directory is /home/a, use cd ../b to switch to /home/b. At this time, you can easily switch back and forth between /home/a and /home/b by repeatedly executing the cd – command.

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

4,‘ALT+.’ or ‘< ;ESC> .’Hot build alt+. or esc+. You can repeat the parameters of the last command line.

5, ^old^new replaces some of the strings in the previous command.

Scene: echo "wanderful", actually wants to output echo "wonderful". It only needs ^a^o, which is very helpful for the mis-spelling of long commands. (Note: You can also use !!:gs/old/new)

6, du -s *

Copyright © Windows knowledge All Rights Reserved