Linux study notes (1) - basic system configuration and power on and off commands

Table of contents

0. start

0-1) Command usage guidelines

0-2) View historical command records

0-3) Clear window contents

0-4) Obtain the internal network IP address of the machine

0-5) Obtain the public network ip address of the machine

0-6) Remotely connect to linux in the command line window of window

0-7) Modify the system time

0-8) Configure a static ip address for the virtual machine

1. Use scp to upload and download files

1-1) Upload local files to the server

1-2) Download the file from the server to the local

2. Basic knowledge of file system

3. Linux startup level

3-1) View the default operating level of the current system:

 3-2) Modify the system default startup level

3-3) Use the init command to switch the startup level

4. Shutdown and restart commands

4-1) Shutdown command

4-2) Restart command

4-3) Cancel shutdown and restart commands


0. start

0-1) Command usage guidelines

查看命令具体用法的几种方式:
命令 --help
命令 -h

如果 --help 和 -h 都不行
则使用: man 命令        查看手册

0-2) View historical command records

history        可以查看历史的命令记录,最多一千条

0-3) Clear window contents

clear

0-4) Obtain the internal network IP address of the machine

ip addr
或
ifconfig -a

lo: indicates local connection;

eth0: indicates the first Ethernet interface;

0-5) Obtain the public network ip address of the machine

curl ip.sb

0-6) Remotely connect to linux in the command line window of window

        The premise is that the remote connection service is enabled

ssh -l 用户名 IP地址
或
ssh 用户名@IP地址


如:
ssh -l root 123.45.6.7
ssh [email protected]

0-7) Modify the system time

date -s "2023-08-03 18:13:40"

0-8) Configure a static ip address for the virtual machine

       The purpose of configuring a static ip address is to enable the connection information saved when logging in to the ssh remote connection software to be used for a long time (if it is a dynamic ip, the connection needs to be re-established when it is changed)

        There are several possible reasons why the IP address of the LAN will change automatically:

        - Dynamic Host Configuration Protocol (DHCP): On most local area networks, a DHCP server automatically assigns IP addresses to devices connected to the network. These IP addresses are temporary, and the device gets a new IP address each time it connects to the network. This way can manage IP addresses more effectively and ensure that all devices in the network can obtain an available IP address.

        - Network Address Translation (NAT): When a device in the LAN needs to access the Internet, NAT will convert the private IP address inside the LAN to a public IP address. This saves the use of public IP addresses and increases the security of your network. Since public IP addresses are a limited resource, ISPs (Internet Service Providers) periodically change the public IP addresses assigned to users.

        - Network failure or reboot: In some cases, devices on the LAN may experience network failure or need to reboot. When a device reconnects to the network, it may get a new IP address.

        If you want to use a fixed IP address in the LAN, you can manually configure a static IP address on the device, which can ensure that the device always uses the same IP address.

        Use the vi editor to modify the file:

vi /etc/sysconfig/network-scripts/ifcfg-ens33

        After the configuration is complete, use the ping command to check whether the configuration is successful and whether the network status is normal.

ping www.baidu.com

1. Use scp to upload and download files

1-1) Upload local files to the server

        Upload the test.png image of the local D disk to the opt directory of the server

scp D:\test.png [email protected]:/opt

1-2) Download the file from the server to the local

         Download the test.png image in the opt directory of the server to the local desktop

scp [email protected]:/opt/test.png C:\Desktop

2. Basic knowledge of file system

The main directories in the Linux file system are:

1. ` / `: root directory.

2. `/ bin` : Contains the most frequently used commands, such as `ls`, `cd`, `echo`, etc.

3. `/ boot` : Store the files required for booting, such as the Linux kernel image, startup configuration files, etc.

4. `/ dev` : Device file system, which stores various device files in the system, such as serial port, CD-ROM drive, USB device, etc.

5. `/ etc` : System configuration files and directories, storing some configuration files and directories of the system, such as `/etc/passwd`, `/etc/hosts`, `/etc/profile`, etc.

6. `/ home` : The user's home directory, which stores the user's home directory and files.

7. `/ lib` : System library files, storing system shared library files, such as common `libc.so`, `libpthread.so`, etc.

8. `/ lost+found` : When the system crashes, abnormally uninstalled files will appear here.

9. `/ media` : The directory used when mounting external devices, such as U disk, mobile hard disk, etc.

10. `/ mnt` : directory for temporarily mounting other file systems.

11. `/ opt` : An optional directory, storing some optional software and tools.

12. `/ root` : The home directory of the superuser (root).

13. `/ sbin` : System administration tool for superuser (root).

14. `/ tmp` : Temporary file directory, store some temporary files.

15. `/ var` : System operation log and variable directory, storing some log files and variable files of system operation.

16. `/ run` : Store running programs and user-related data.

17. `/ usr` : The location where the user's applications and files are stored.

        Normally, users can use the /opt and /home directories (or create new directories by themselves), neither of which contains sensitive files. Programs can be installed in the /opt directory. By default, the program installation path is /usr/bin or /var directory.

3. Linux startup level

        There are 7 levels, numbered from 0 to 6:

0 shutdown operation
1 Single-user mode, only one user can log in, only root user is supported, it is used for system maintenance, and remote login is prohibited
2 Multi-user mode, no network file system support
3 Fully multi-user mode, command line interface. There are network file systems. The default startup mode in general
4 system reserved
5 Graphical interface, default startup mode with GUI
6 restart operation

3-1) View the default operating level of the current system:

systemctl get-default

 3-2) Modify the system default startup level

systemctl set-default multi-user.target       # 设置默认启动级别为 3
systemctl set-default graphical.target        # 设置默认启动基本为 5

 The default startup level cannot be changed to 0 or 6! Otherwise, the system will fail to boot or keep restarting.

3-3) Use the init command to switch the startup level

        like:

init 0

It will shut down the system (shutdown is recommended to use the shutdown command, and restart is recommended to use the reboot or shutdown command, and it is not recommended to use the init command to operate)

4. Shutdown and restart commands

4-1) Shutdown command

shutdown -h now shut down immediately
shutdown -h 15:30       15:30 Scheduled shutdown
halt         shutdown
init 0 shutdown
shutdown -h +30 Shut down after 30 minutes

4-2) Restart command

shutdown -r now restart now
shutdown -r 13:30 13:30 Scheduled shutdown
reboot reboot
shutdown -r +1         restart after 1 minute
init 6 reboot

4-3) Cancel shutdown and restart commands

shutdown -c

Guess you like

Origin blog.csdn.net/hao_13/article/details/132643373