This article was written 1801 days ago and last revised 1773 days ago. Some of the information may be outdated.

Common Linux operations

Since the blogger bought the ubuntu server last year, he has actively forced himself to use command line linux In fact, it is found that the efficiency is very high after a little proficiency. After all, you don't need to use a mouse

Of course, if you use a touch pad, such as the force touch touch pad, it is also very convenient. Let's talk about it Apple Macbook Pro

Common Linux/shell commands

First, look at this Linux commands This is quite complete, and of course more complicated. Here we only introduce the simple grammar we have used

ssh

SSH is a basic statement, through which we can use the command line to remotely connect to our server The default port of ssh is 22. If you change it, you need to go through -P Port number To select the corresponding port Specific syntax

 ssh  username@192.168.1.1 #User login name @ server address

If you want to exit, use ctrl+D perhaps exit You can exit ssh

scp

Scp is a command used to transfer files. It works well without an FTP client. Don't confuse scp with the scp foundation

The basic syntax of scp is scp A B Copy A to B If you need to copy the directory, use -r Recursive directory processing. If the port is changed, use -P Port number

Specific syntax

1) Local replication to remote server

 scp local_file  remote_username@remote_ip :remote_folder  #Copy directory scp -r local_folder  remote_username@remote_ip :remote_folder

2) Replicate from remote to local It can be replaced in sequence

 scp local_file  remote_username@remote_ip :remote_folder  #Copy directory scp -r  remote_username@remote_ip :remote_folder local_folder

mv

Mv instruction As the name suggests Move instruction , which can be used to move and rename files Basic grammar

 #Rename File mv [option] file1 file2 #Move files mv [option] file1 destination #Move the directory file. If the directory moved to does not exist, rename the directory name mv [option] destination1 destination2

The options of option are

 -i: If a file with the same name already exists in the specified directory, first ask whether to overwrite the old file; -f: No instructions are given when the mv operation wants to overwrite an existing target file;

touch

What is touch? It is a command created out of nothing. That is, you can create a blank file, and you can also modify the attributes of the file through the touch command. Unfortunately, I can't understand how to modify the attributes

Too basic grammar:

 #Create a readme markdown file touch README.md

mkdir

The so-called make directory is to create a folder This command seems to work in DOS

 mkdir mynekopara #Create a folder named mynekopara cd mynekopara

rm

Rm means remove. Delete the file

 Rm [option] filename rm -r mynekopara #Traverse and delete all files in the mynekopara folder

-I Ask for confirmation one by one before deleting. -F Even if the original file attribute is set as read-only, it will be deleted directly without confirmation one by one. -R Delete the directory and the following files one by one.

as for rm rf /* Now we can understand this command, that is, traversing and deleting all files under the linux directory/without making a selection is equivalent to formatting, so it is dangerous. Do not use this command.

cat

As the name implies, it is a cat????, With the cat's soft body, you can see all the documents Actually, I lied to you, this cat wrong neko this cat , not to mention Chocolate and vanilla this cat

It's concatenate Abbreviation of, similar to type command This command is used to connect files and print them to the standard output device

Basic syntax:

 cat a.md

Then there will be no highlighted code output

man

Manual is the operation method of viewing the instructions of the corresponding command

 man vim #You can view how to use the vim command

vim

This is too difficult. I can't finish the article. Write some common operations. Note that Vim is case sensitive Most people learn how to quit this program when they first use VIM

 I-input input mode. If you want to type in vim, you must first use i to enter input mode Esc - Press this key in the upper left corner of the keyboard to launch the input mode U - Undo the command, equivalent to Ctrl+z . - Repeat the command, which is equivalent to Ctrl+shift+z if you know the Photoshop shortcut key Hjkl corresponds to the direction keys V - Enter visual mode, i.e. selected mode Y - Press y to copy the selected text in the selected mode Y - Copy the current line P-Paste : w - Save File : q - Exit : wq - Save and Exit :q!- Exit without saving

You can also see this picture

chmod

Authorization command

 chmod [-cfvR] [--help] [--version] mode file...

Mode: permission setting string, the format is as follows:

 [ugoa...][[+-=][rwxX]...] [,...]

Including:

 U refers to the owner of the file, g refers to the person who belongs to the same group as the owner of the file, o refers to other people, and a refers to all three. +Means to add permissions, - means to cancel permissions, and=means to set unique permissions. R means readable, w means writable, x means executable, and X means only when the file is a subdirectory or has been set as executable.

Other parameter descriptions:

 -C: If the file permission has been changed, the change action will be displayed -F: Do not display an error message if the file permissions cannot be changed -V: Display details of permission changes -R: Make the same permission changes to all files and subdirectories under the current directory (that is, change one by one in a recursive manner) --Help: Display auxiliary instructions --Version: Display version

Chmod can also use numbers to indicate permissions, such as:

 chmod 777 file

The syntax is:

 chmod abc file

Where, a, b, and c are a number respectively, representing the permissions of User, Group, and Other.

 r=4,w=2,x=1 If rwx attribute is required, 4+2+1=7; If rw attribute is required, 4+2=6; If r-x attribute is required, 4+1=5.

So I often use chmod -R 777 file Give full permissions to file and its internal files

htop

Linux task manager, which can view CPU memory and other conditions

ifconfig

The device manager of Linux can view the specific situation of the network card, much like the ipconfig under DOS, but with more device information

reboot

Linux restart

grep

Sorry for the complexity, the Linux grep command is used to find the strings that meet the conditions in the file. Look at this Linux grep command

netstat

Link with the previous one to view the port command

 Netstat - ntlp//View all current TCP ports· Netstat - ntulp | grep 80//View the usage of all 80 ports· Netstat - ntulp | grep 3306//View the usage of all 3306 ports·

curl

Command to send network request I often use this function to log in to the school gateway with one click, which is very convenient. In addition, the shortcut application in Apple iOS devices also comes with a similar tool, which can be used to connect data. Of course, you can also log in to the gateway with one click to pull Too many, put a link and leave Curl Common Commands

ls

List command, the most commonly used command to view folders Input ls directly

tree

Tree view, traversing the structure and relationship inside the output folder in the form of tree view

 tree file

In short, I'm curious!

Recommend several websites to facilitate learning more

  1. It's almost 0202, and you don't know basic Linux commands yet?
  2. Tencent Cloud Developer Lab You can learn how to operate Linux