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

  1. use--helpGets the command parameters and parameter definitions
  2. usemanGet 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 directory
  • cd: Goes to the specified directory
  • rm: Deletes the specified file
  • mkdirCreate a directory
  • less: View files
  • head: Look at the first few lines of the file
  • tail: Look at the last few lines of the file
  • stat: 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 version
  • free: Viewing memory information (MAC not applicable)
  • du: Displays hard disk information
  • top: Displays process information in an interactive manner
  • uptime: Startup time and average load
  • who: Viewing users

1.4 Be familiar with network commands

  • dig: DNS
  • curl: HTTP request. It is used frequently and must be mastered
  • netstat: Indicates network statistics
  • lsof -i:3000: Lists the processes corresponding to port 3000
  • ifconfig

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

  1. How to intelligent automatic completion
  2. How to indicate the current Git state
  3. 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:

  1. Disable up, down, left, and right movement
  2. 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 useb, B, w, WInstead of
  • usef, F, t, TFor more refined left-right movement control
  • use0, $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
  • usegg, GMake a head and tail move

3.2 High-frequency Operations

Here are the high-frequency actions I use countless times a day using Vim

  • :wThe fast preservation
  • <C-[>Exit insert mode, andescsimilar
  • ggQuickly move to the top of the file
  • GMove quickly to the end of the file
  • <c-o>Move to the last position
  • zzMove the cursor to the middle of the screen
  • : 12Move quickly to a particular row
  • ddShear line
  • yyCopy the bank
  • yi{Copy the contents of the parentheses
  • =i{Automatic indentation
  • *Find keywords quickly, similar to sublime/vscodeCommand + d
  • :nohUnhighlight keyword
  • oQuickly get into INSERT mode and navigate to the next row
  • uundo

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.

  1. Use plug-in GUI mode to run the code in the editor
  2. 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.

  1. Check the process memory and CPU information on the terminal
  2. Maintain multiple items on the terminal, one TAB for each item. Open a separate panel to run the project in the terminal. usecode .(in vscode) open the project to develop in the editor.
  3. Submit code at the terminal (integration terminal)