This paper is participating in the30 years of Linux”Topic essay activity
This article is intended for Windows(WSL), MacOS(all differences for individual commands), Ubuntu, and various Linux distributions.
This article is suitable for both beginners and engineers with five years of experience.
Command line basics
1.1 Use help documents and search well
- use
--help
Gets the command parameters and parameter definitions - use
man
Get the help manual for the command
$ ls --help
$ man ls
Copy the code
What if a command is too long?
$ for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l 2>/dev/null; done
Copy the code
Don’t panic, Yamato will help you with a big kill: ExplainShell. Each argument on the command line is explained word by word.
1.2 Use command line to manage files and directories instead of file manager
Use the following commands frequently on the terminal to manage your own directory rather than through the file manager
ls
: Lists all files in the directorycd
: Goes to the specified directoryrm
: Deletes the specified filemkdir
Create a directoryless
: View fileshead
: Look at the first few lines of the filetail
: Look at the last few lines of the filestat
: Obtain details about the file
1.3 Be familiar with the commands related to the local device status
uname -a
: Displays information such as the kernel versionfree
: Viewing memory information (MAC not applicable)du
: Displays hard disk informationtop
: Displays process information in an interactive manneruptime
: Startup time and average loadwho
: Viewing users
1.4 Be familiar with network commands
dig
: DNScurl
: HTTP request. It is used frequently and must be masterednetstat
: Indicates network statisticslsof -i:3000
: Lists the processes corresponding to port 3000ifconfig
1.5 be familiar with the Glob
How do I list all.js files in the current directory?
So that’s glob
$ la -lah **/*.js
Copy the code
1.6 familiar with Braces
As the name suggests, this is an expression wrapped in braces
$ echo{2.. 10.. 2} 2 4 6 8 10 $echo{a.. e} a b c d e $echo {a, c, z}
a c z
Copy the code
1.7 Understanding environment Variables
Know how to set and read environment variables
List all environment variables
$ env
Output the HOME environment variable
$ echo $HOME
# PATH indicates the PATH of the global command
$ echo $PATH
Set an environment variable
$ export NAME=shanyue && echo $NAME
This can also set an environment variable
$ NAME=shanyue && echo NAME
Copy the code
Choose your favorite shell tool
If nothing else, Bash will be our default shell tool. Bash is powerful, but requires a lot of power to pull off and is not cool enough.
PS: Linux for production does not need to be cool, nor do you recommend installing extra shells. Linux based on development, cool features
- How to intelligent automatic completion
- How to indicate the current Git state
- Choose a wide variety of shell themes
Based on these considerations, the following shells can be selected.
zsh
fish
Note: When you switch shells, the default configuration of your shell will change from ~/.bashrc to ~/.zshrc (if ZSH).
oh-my-zsh
Powerful, theme rich, plug-ins, can greatly improve the development experience, is my terminal theme and configuration of the only choice.
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Copy the code
3. Familiar with VIM
What editor are you using now?
VS Code, Eclipse, Sublime, or Vim?
There are countless more powerful editors than Vim, none more powerful than Vim shortcuts.
At the end, in a production environment, VIM is the only option. Moreover, the Vim plug-in is one of the most popular plug-ins among all the editors, and its power is evident.
To improve your VIM skills, do the following two things:
- Disable up, down, left, and right movement
- Use Vim as the edit mode for your editor
3.1 Fast Movement
- Up (k) down (j) left (H) right (L) movement, it should be noted that the use of up, down, left and right arrows is prohibited
- Reduce the left and right movement of the previous step, which is too inefficient to use
b, B, w, W
Instead of - use
f, F, t, T
For more refined left-right movement control - use
0, $
Move the first row and the last row - use
%
Move quickly to match characters - use
< Ctrl - d >, < Ctrl - u >
Move up and down a wide range - use
gg, G
Make a head and tail move
3.2 High-frequency Operations
Here are the high-frequency actions I use countless times a day using Vim
:w
The fast preservation<C-[>
Exit insert mode, andesc
similargg
Quickly move to the top of the fileG
Move quickly to the end of the file<c-o>
Move to the last positionzz
Move the cursor to the middle of the screen: 12
Move quickly to a particular rowdd
Shear lineyy
Copy the bankyi{
Copy the contents of the parentheses=i{
Automatic indentation*
Find keywords quickly, similar to sublime/vscodeCommand + d
:noh
Unhighlight keywordo
Quickly get into INSERT mode and navigate to the next rowu
undo
4. Be familiar with TMUX (optional)
You may not have heard of TMUX, but if you know what it does, you’ll love it.
It is a special tool for managing multiple Windows in Linux!
It can open multiple tabs in the terminal, each TAB page to open multiple panels, development or debugging are very convenient.
If you are using a MAC, you might consider using Iterm2 to achieve the same functionality.
Install software dependencies
$ yum install -y gcc automake libevent-devel ncurses-devel glibc-static
# Download source code
$ git clone [email protected]:tmux/tmux.git
Switch to version 2.8$git checkout $2.8cd tmux
# compile source code
$ sh autogen.sh && ./configure && make
Check the version number$./tmux -v tmux 2.8Copy the code
Five, the terminal as a necessary tool for development
Because of the power of the editor, it is possible to do the work without using a terminal at all.
- Use plug-in GUI mode to run the code in the editor
- Submit code in the editor using the plug-in GUI
But as a developer who aspires to learn Linux command-line tools, I highly recommend using terminals. In particular, most editors are integrated with terminals, and integrated terminals can also be used.
- Check the process memory and CPU information on the terminal
- Maintain multiple items on the terminal, one TAB for each item. Open a separate panel to run the project in the terminal. use
code .
(in vscode) open the project to develop in the editor. - Submit code at the terminal (integration terminal)