1. Execute commands in cli mode

1.1 Starting to Run commands

[user@localhost] $ command[-options] parameter1 parameter2 ... Option Parameter 1 Parameter 2Copy the code

Description:

  1. Commands, options, parameters, and so on are distinguished by Spaces. No matter how many empty Spaces the shell considers as one space, Spaces are very important special characters.

  2. A backslash (\) can be used to escape the return key so that the command continues to the next line. Note that the backslash is immediately followed by a special character to escape.

  3. Linux is case sensitive.

  • Language family support
# displays the currently supported language families
$ locale

The modified language group is called the English language group
$ LANG=en_US.utf8
$ export LC_ALL=en_US.utf8
Copy the code

1.2 Basic Command Operations

1.2.1 Display date and time command: date

# display date and time
$ date
--> Fri May 29 13:32:01 CST 2021

$ date +%Y/%m/%d
--> 2021/05/29

$ date +%H:%M
---> 14:33
Copy the code

1.2.2 Display calendar command: CAL

# Basic syntax
$ cal [month] [year]
# Current month
$ cal
# 2021 Calendar
$ cal 2021
# 2021.10 calendar
$ cal 10 2021
Copy the code

1.2.3 Easy to use calculator: BC

$ bc

# operator: + - * / ^ %
# quit: Leave this calculator
# scale=3: Set the decimal number to 3
Copy the code

1.3 Key Hot Keys [Tab], [Ctrl]-c, and [Ctrl]-d

  • [Tab] : [command completion], [file completion], [option/parameter completion]
  • [Ctrl]-c: Interrupts the current program
  • [Ctrl]-d: End Of File, EOF or End Of Input
  • [Shift] + {| [Page UP] [Page Down]} : in a pure command line interface, which can be used to turn pages

2. Linux Online help page man page and Info page

2.1 –help description of the command

# such as `date`
$ date --help.Copy the code

2.2 man page

Man is short for manual

# such as `date`
$ man date
...
Copy the code
Code name On behalf of the content
1 The userA command or executable that can be manipulated in a shell environment
. .
5 Configuration files or the format of certain files
. .
8 System administratorAvailable management commands
9 Kernel-related files

Again, the man page is divided into several sections to introduce this command:

Code name Content description
NAME Brief description of command and data names
SYNOPSIS A short introduction to command syntax
DESCRIPTION A more complete descriptionYou’d better look at this part carefully
OPTIONS All available options are explained in the SYNOPSIS section
COMMANDS Commands that can be executed in the program while it is executing
FILES Certain files to which this program or data is used or referenced or linked
SEE ALSO Refer to other instructions related to this command or data
EXAMPLE Some examples to look at

Common keys in man Page:

The keys For a working
Space Down the page
[Page Down] Down the page
[Page Up] Page up
[Home] Skip to the first page
[End] Skip to last page
/string Look for the string [down]
? string Look up for string
n,N Utilize/or? When looking up a string, you can use n to continue the next lookup and n to do the reverse lookup
q exit

Other [man] command related operations:

# list the description files that exactly match$man -f $man -f# as long as there is a keyword partial match, it will be listed$man -k $man -kCopy the code

2.3 the info page

Unlike the Man page, which outputs a bunch of information in one go, the Info page breaks the file data into paragraphs, each paragraph is written in its own page, and there are web-like hyperlinks in each page to jump to different pages. Each independent page is also called a node.

The files that support the info command are placed in the /usr/share/info/ directory by default.

The keys For a working
Space Down the page
[Page Down] Down the page
[Page Up] Page up
[Tab] Moving between nodes, where there are nodes, is usually shown as *
[Enter] When the cursor is over the node, press Enter to Enter the node
b Move the cursor to the first position in the INFO screen
e Move the cursor to the last position in the INFO screen
n Go to the next node
p Go to the last node
u Move up one level
S (/) Search in the info page
H,? Show help options
q exit

2.4 Other Useful Documents

/usr/share/doc (usr: Unix System Resource)

2.5 Summary (man, info, /usr/share/doc/)

  • In command line mode, if you know a command but forget its options and parameters, use it first--helpFunction to query relevant information;
  • When there is any command or file format you don’t know about this stuff, but you want to understand it, please use it quicklymaninfoTo query;
  • If you want to build some other service, or if you want to use a whole suite of software to do a particular thing, please go to /usr/share/doc/ and check the documentation for that service.

3. Super simple text editor: Nano

A few brief explanations:

  • The exponent symbol (^) represents the [Ctrl] key on the keyboard
  • M stands for the [Alt] key
  • [Ctrl] -g: Get help
  • [Ctrl] -x: Leave the nano software, if there is a modified file will prompt whether to save
    • If you simply want to save, directly press [Enter] to save and leave the nano program
  • [Ctrl] -w: Query string
$ nano text.txt
...
Copy the code

4. Proper shutdown method

On Windows (non-NT kernel) systems, since it is a single-player, multi-task situation, even if your computer shuts down, there should be no impact on others.

But with Linux, because every program (or service) is executed in the background, there can be quite a few people working on your host at the same time behind the screen you can’t see.

An abnormal shutdown can cause file system corruption (some services have file problems because there is no time to write data back to the file)

  • Observe the status of the system
# View current online users
$ who

Check the network status
$ netstat -a

# Check the background execution of the program
$ ps -aux
Copy the code
  • Data is synchronized to disks
$ su - 		Change the identity to root
# sync 		The root user synchronizes data to the disk
Copy the code
  • Common Shutdown commands
#/sbin/shutdown [-krhc] [time] [Warning]Options and parameters: -k: does not shut down the system, but sends a warning message. -r: restarts the system after stopping the service. -h: stops the system after stopping the service. Shutdown now (common) -c: cancels the shutdown command in progress. Time: specifies the shutdown time. If this option is not available, the shutdown starts one minute later by default
# /sbin/shutdown -h 10 'I will shutdown after 10 mins'
# shutdown -h now
# shutdown -h 20:25
# shutdown -h +10
# shutdown -r now
# shutdown -r +30 'The system will reboot'
# shutdown -k now 'This system will reboot'
Copy the code
  • Restart and shut down
# reboot		# to restart
# halt			The screen may retain the message that the system has stopped
# poweroff		# System shutdown, so no extra power provided, screen blank
# init 0		# to turn it off
# init 6		# to restart

## systemctl [command] :
# systemctl reboot
# systemctl poweroff
Copy the code

5. Configure Linux file permissions and directories

One of the best things about Linux is its multi-tasking environment. And in order to let each user have confidential file data, so file permission management becomes very important.

Linux generally classifies file read and write identities into three categories: owner, group, and others. The three identities have read, write, and execute permissions respectively.

5.1 Modifying File Properties and Permissions

5.1.1 CHGRP: Changes the owning user group of a file

# chgrp [-R] groupName dirname/filename ...Options and parameters: -r: Performs recursive modification, that is, updates all files and directories in the subdirectory to the user group. Example:# chgrp users initial-setup-ks.cfg
Copy the code

5.1.2 CHown: Modify the file owner

#Chown [-r] Account name file or directory
#Chown [-r] Account name: user group name file or directoryOptions and parameters: -r: Performs recursive modification. That is, all files and directories in the subdirectory are updated as the user.Copy the code

In fact, chown can also use chown user.group file, but it is recommended to use a colon [:] to separate the owner from the user group. In addition, chown can simply change the owning user group, for example, chow.sshd initial-setup-ks.cfg.

5.1.3 CHmod: Modifies file permissions, such as SUID, SGID, and SBIT

1. Modify file permissions for numeric types

R: 4

W: 2

X: 1.

#Chmod [-r] xyz file or directoryOptions and parameters: xyz: RWX the sum of property values -r: changes recursively, that is, along with all files in subdirectories. Example:# chmod 761 .bashrc
Copy the code

2. Change file permissions for symbol types

U (user), G (group), O (Others), A (all) + (Join), – (Remove), = (set)

Here's an example:# chmod u=rwx,go=rx .bashrc

# chmod a+w .bashrc

# chmod a-x .bashrc
Copy the code

5.2 Permission Meaning of Directories and Files

5.2.1 Importance of Permissions to Files

  • R (read) : The actual contents of this file can be read

  • W (write) : you can edit, add, or modify the content of the file (but not delete the file).

  • X (execute) : this file has permissions that can be executed by the system

File [w] does not have permission to delete the file itself!

Whether a file can be executed depends on whether it has the [x] permission, and has no absolute relationship with the file name.

5.2.2 Importance of Permissions to Directories

  • R (read contents in directory) : has the permission to read the directory structure list (ls can find the file name, but ls -al cannot find the file name! Because there is no [x] permission!

  • Modify contents of directory (W) : has the permission to modify the directory structure

    • Create new files and directories
    • Delete existing files and directories (regardless of their permissions)
    • Rename a file or directory
    • Move files and directories in this directory
  • Access Directory (x) : indicates whether a user can access this directory