Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities.

This paper has participated inProject DigginTo win the creative gift package and challenge the creative incentive money.

preface

In the last article, we set up the basic Linux operating environment, so we can begin to learn Linux in earnest

Power on and off

When Linux starts up, it goes through the basic startup process, which I won’t go into here, and then it goes into the application, and eventually we get to a login screen, or a command line page

Depending on whether or not we have a graphical interface installed, there are generally three ways to access Linux:

  • SSH remote connection access, the previous article has been implemented
  • You can directly enter the account password on the cli
  • Enter the account password on the GUI

In a real production environment, shutdown operations are rarely done, except in exceptional circumstances, because our services run 24/7 on Linux servers

Let’s take a look at the basic shutdown instructions:

It’s definitely not pushing the off button by hand, manual head

  • shutdown

Let’s go straight to the help documentation in Linux

# shutdown --help shutdown [OPTIONS...]  [TIME] [WALL...]  Shut down the system. --help Show this help -H --halt Halt the machine -P --poweroff Power-off the machine -r --reboot Reboot the machine -h Equivalent to --poweroff, overridden by --halt -k Don't halt/power-off/reboot, just send warnings --no-wall Don't send wall message before halt/power-off/reboot -c Cancel a pending shutdownCopy the code

Some common practices:

  • shutdown -h 20

Shut down the server in 20 minutes

  • Shutdown -r now or reboot

Restarting the Server

  • Shutdown -h now or halt

Shut down the machine immediately.

  • shutdown -h 12:00

Shut down the server at 12 noon

  • shutdown -r 20

The server will be restarted after 20 minutes

A very important reminder:

Before restarting or shutting down the system, use the sync command to synchronize data in the memory to the disk. If you do not run this command, data in the memory will not be synchronized to the disk before the shutdown, and data will be lost

What is in the root directory of the system?

Everything in Linux is a file, and all directories are mounted under this node

Let’s ls/see what’s in the root directory

Let’s use the tree command to look at the tree structure below

# tree -L 1. ├─ bin // Binary ├─ data // Store data files ├─ dev // store data files ├─ dev // Store Data files ├─ dev // Store Data files ├─ dev // Store Data files ├─ dev // Store Data files ├─ dev // Store Data files ├─ dev // Store Data files ├─ dev // Store Data files ├─ dev // Store Data files ├─ dev // Store Data files ├─ dev // Store Data files ├─ dev // │ ├─ lost+ Found │ ├─ lost+found │ ├─ lost+found │ ├─ lost+found │ ├─ lost+found ├─ Media // Linux will automatically recognize some add-on devices and put them in this directory. ├─ MNT // ├─ opt // ├─ proc // is a virtual directory for memory mapping. We can go directly to this directory to get system information ├─ root // Super administrator directory ├─ sbin // Executable program directory for Super administrators To use ├─ SRV // To store some data to be extracted after the service starts up ├─ sys // Install Linux 2.6 New file system sysfs ├─ TMP // Usr/important Users' applications and files will be stored in this directoryCopy the code

Take a look at the directory /usr that is important to users

/usr# ls
bin  games  include  lib  libexec  local  sbin  share  src
Copy the code

Check /usr/bin for a list of user executables that can be disastrous if files in this directory are deleted by mistake

Common Basic Commands

  • ls

Ls command, in Linux must be able to use the command, parameters are also a lot of, let me tell you what we often use

-l: lists all files without hiding them, including file attributes and file permissions

-a Lists all files, including hidden files

-h presents data in a human-readable way

All Linux commands can be combined

  • cd

Switch directory

The CD command is followed by either an absolute path (beginning with /), or a relative path (./ or.. /), depending on your needs

Linux commands are familiar by typing, not by memorizing

CD /usr/local/ is the absolute path of the preceding operations

cd .. / Operates relative paths

CD – Switches to the previous path

CD ~ switch to home directory, I am the root user, so switch to /root

PWD Displays the current path

  • The mkdir and rmdir

Mkdir Creates a directory

-p Creates a directory if it does not exist

-m Sets the file permission mode

# mkdir a/b/c -p
root@iZuf66y3tuzn4wp3h02t7pZ:/home/admin
# mkdir testa
Copy the code

Rmdir Deletes a directory

Delete a directory. If the directory is not empty, an error message is displayed

# rm a
rm: cannot remove 'a': Is a directory
Copy the code

Let’s check the help file

# rmdir --help
Usage: rmdir [OPTION]... DIRECTORY...
Remove the DIRECTORY(ies), if they are empty.
​
      --ignore-fail-on-non-empty
                  ignore each failure that is solely because a directory
                    is non-empty
  -p, --parents   remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is
                    similar to 'rmdir a/b/c a/b a'
  -v, --verbose   output a diagnostic for every directory processed
      --help     display this help and exit
      --version  output version information and exit
​
Copy the code

This nesting of directories can be removed with the -p argument

conclusion

In this issue, we will learn about the common commands in Linux system, such as shutdown, CD, mkdir, etc.

That’s the content of this episode. Please give us your thumbs up and comments. See you next time