Many common commands in Linux are required to master, here will share Linux entry often used basic commands, I hope to help you learn!!

Before we get started, I’d like to share with you a video about Linux

The video explains the origin and development of Linux, the installation and configuration of CentOS, a common Linux system used by enterprises.

This section describes the ten types of Linux commands and provides examples. Web applications developed with JAVA.

Build Web application running environment in Linux :JDK,MySQL,Tomcat installation, configuration, log view, etc.

Deploy the Web application as a WAR. Video learning can meet the actual combat requirements in the enterprise.

Watch online: www.bilibili.com/video/BV1Li.

Data download: www.bjpowernode.com/javavideo/1…

File directory instruction

The PWD command

Basic syntax: PWD

Displays the path of the current directory

Practical case:

The ls command

Basic syntax :ls [option] [directory or file]

Commonly used options

  • A: Displays all files and directories in the current directory, including hidden ones.
  • L: Displays information in a list, equivalent to LL

Practical case:

List all files and directories in the current directory:

The CD instruction

Basic syntax: CD [parameter]

Switch to a specified directory

Commonly used parameters

Absolute paths (directories starting with /) and relative paths (directories starting with a directory name, starting from the current directory)

CD ~ or CD: go to your home directory

cd .. Go back to the directory one level above the current directory

Practical case:

The mkdir command

Basic syntax:

Mkdir [option] Directory to create

Commonly used options

P: Create a multi-level directory

Practical case:

Rmdir commands

Basic syntax:

Rmdir directory

Delete an empty directory

Practical case:

Touch the instructions

Basic syntax:

Touch File name list

Create one or more empty files

Practical case:

The cp command

Basic syntax:

Cp [option] source dest

Common options:

R: Recursively copy the entire folder

Practical case:

The rm command

Basic syntax:

Rm [option] File or directory to be deleted

Common options:

  • R: Delete the entire folder recursively
  • F: Forcible deletion is not prompted

Practical case:

The mv command

Basic syntax:

Mv oldNameFile newNameFile

Mv /temp/ moveFile /targetFolder

Practical case:

The cat command

Basic syntax:

Cat [option] File name to view

Commonly used options

N: Displays the line number

Practical case:

More instructions

Basic syntax:

More Indicates the file name to view

Function description: The more command is a text filter based on the VI editor, which displays the content of the text file by page in a full-screen way.

Shortcut:

Practical case:

Less instruction

Basic syntax:

Less Indicates the name of the file to be queried

Less command is used to view file content in split screen. Its function is similar to more command, but more powerful than more command. It supports various display terminals. The less command does not load the entire file at one time, but loads the content according to the display requirements, which is efficient for displaying large files.

Shortcut:

Practical case:

The head instructions

Basic syntax:

  • Head file (default view the first 10 lines of the file)
  • Head -n 5 file (function description: View the first 5 lines of the file, 5 can be any number of lines)

Practical case:

Tail instruction

Basic syntax:

  • Tail file (View the last 10 lines of the file by default)
  • Tail -n 5 File (Function description: View the last 5 lines of the file. 5 can be any number of lines.)

Practical case:

The echo command

Basic syntax:

Echo [options] [output content]

Output variable or constant content to console

Practical case:

> instructions

Basic syntax: View Instructions > Target file

Function description: overwrite the result in the previous view command to the target file, if the target file does not exist, then create a new one.

Practical case:

> > instructions

Basic syntax: View instructions >> target file

Add the result of the previous view command to the target file. If the target file does not exist, create a new one.

Practical case:

Time date instruction

The date order

Basic syntax:

  1. Date (display current time)

  2. Date +%Y

  3. Date +%m

  4. Date +%d

  5. Date “+%Y-%m-%d %H:% m :%S”

  6. Date -s String time (set date)

Practical case:

CAL instruction

Basic syntax:

CAL [option] (No option, display calendar of this month)

Practical case:

Search search instruction

The find command

The find command recursively traverses the subdirectories from the specified directory and displays the files or directories that meet the conditions on the terminal.

Basic syntax:

Find [option]

Options:

  • Name: Search by name. Wildcard characters are supported.
  • User: Search by user name
  • Size: Search by file size

Practical case:

The locate command

Basic syntax:

Locate Specifies the name of the file to search for

The Locate directive can quickly locate file paths throughout the system. The Locate directive quickly locates a given file using the LOCATE database of all file names and paths established in the system. The Locate command does not need to traverse the entire file system, resulting in faster queries. To ensure the accuracy of query results, administrators must periodically update locate time.

Practical case:

The grep command

Basic syntax:

Grep [option] The content of the source file to search for

Common options:

  • N: Displays the matching line and its number
  • I: Ignore case

Description: grep filters lookup, pipeline operators, “|”, said it would before the processing of a command output is passed to the back of the order processing results.

Practical case:

Compression and decompression instructions

Gzip command

Basic syntax: Gzip file

Function Description: Compress a file to a *. Gz file and store it in the directory where the original file resides. After the compression is successful, the original file will be deleted. Used to compress a single file.

Practical case:

Gunzip command

Basic syntax: Gunzip file

Function Description: This command is used to decompress files. After the decompression is successful, the files are stored in the directory where the original compressed files are located, and the original compressed files are deleted.

Practical case:

Zip instruction

Basic syntax:

Zip [option] xxx. zip The content to be compressed

Function description: Compress a specified file or directory into XXX. Zip file, used to compress all file structures.

R: indicates recursive compression, that is, compressed directories

Practical case:

Unzip the instructions

Basic syntax:

Unzip [option] xxx.zip

Common options: d Directory: Specifies the directory for storing decompressed files

Practical case:

The tar command

Basic syntax:

Tar [option] xxx.tar. gz [packaged content]

Function description: Package or decompress files

Options:

  • C: Generate the.tar.gz package file
  • V: Displays detailed information
  • F: Specifies the compressed file name
  • Z: Package and compress
  • X: Decompress the.tar.gz file
  • C: Specify the directory to decompress

Practical case:

Group management instruction

Basic introduction to Linux group:

In Linux, each user must belong to a group. The user group can be changed.

In Linux, each file has an owner, a group to which it belongs, other groups, and you can change the group.

The owner of the file/directory

By default, the owner belongs to the same group that the file belongs to.

View file owner and group directives

Basic syntax:

Ls - AHl File name

(a-all,h-human,l-list)

Practical case:

Modify the file owner directive

Basic syntax:

Chown new owner file name

Chown newowner:newgroup file Changes both the owner and all groups of the user

R Recursively applies to all subfiles or directories if it is a directory

Modify the file owner to the specified user.

Practical case:

Modify the group command of a file

Basic syntax:

CHGRP Indicates the name of the new group

R Recursively applies to all subfiles or directories if it is a directory

Change the group where a file resides to a specified group

Practical case:

Permission management instruction

Basic Introduction to Permissions

All permissions mentioned here are file and directory permissions. In Linux, each file and directory has its own access rights, which can be viewed in the file list.

RWX permission details

RWX applies to files

  1. [r] stands for read: to read, to view

  2. [w] indicates Write: A file can be modified but cannot be deleted. A file can be deleted only when you have the write permission on the directory where the file resides.

  3. [x] indicates execute: can be executed

RWX applies to directories

  1. [r] stands for read: the directory can be read

  2. [w] indicates Write: you can create, delete, and rename directories in a directory

  3. [x] indicates execute: The directory can be accessed

RWX is represented by numbers

R =4(2 ^ 2),w=2(2 ^ ¹),x=1(2º)

Permission management instruction

Command to modify file/directory permissions chmod

The first method is to change the permission through r, W, or X

  1. Chmod u= RWX,g=rx,o=x File directory name

  2. Chmod o+w Specifies the name of the file directory

  3. Chmod a-x Specifies the name of the file directory

Note: u, G, O, and A respectively represent the file owner, the user in the file owning group, the user in other groups, and all users. =, +, and – respectively indicate setting permission, adding permission, and removing permission

The second way: change permission through numbers

Chmod Directory name of a group of three digital files

R =4 w=2 x=1 RWX =4+2+1=7

Practical case: