Chinese News Feed

Some basic knowledge of Linux entry

EEPWweixin @ 2019/08/22

Switching mode between graphic mode and text mode

The Linux preset provides six command window terminals to let us login.

  • By default, we login the first window, that is, tty1, the six windows are tty1 and tty2 respectively. Tty6, you can press Ctrl + Alt + F1 ~ F6 to switch them.

  • If you install a graphical interface, you can enter the graphical interface by default. At this point, you can enter one of the command window interfaces by pressing Ctrl + Alt + F1 ~ F6.

  • When you enter the command window interface and then return to the graphical interface, just press Ctrl + Alt + F7 to come back.

  • If you use the VMware virtual machine, the shortcut key to switch command window is Alt + Space + F1~F6.

  • If you are in the graphical interface, press Alt + Shift + Ctrl + F1~F6 to switch to the command window.

Learn to use shortcut keys

  • Ctrl + C: This is the shortcut key used to terminate the current command. Of course, you can enter a large string of characters, do not want it to run directly Ctrl + C, and the cursor will jump into the next line.

  • Tab: This key is the most useful key, and it is also the key that many people tap the highest probability. Because when you hit a command halfway, it will help you complete. Not only is the order, when you play a directory, you can also complete, do not believe you try.

  • Ctrl + D: You can also enter exit if you quit the current terminal.

  • Ctrl + Z: Suspending the current process, such as you are running a command, suddenly feel there is something wrong, you want to pause, you can use this shortcut key. After pause, you can use FG to restore it.

  • Man + command: The input man LS is in the form of man + command, and you will see the relevant help document. From the introduction of the command to the parameters and usage of the command are very detailed, not bad.

  • Ctrl + L: Clear screen enables the cursor to move to the first line.

Directory structure of Linux system

After entering the system, type LS under the current command window / you will see it.

Learn to query help document - man

This man is usually used to see a command's help document. For example:

The following is an explanation of these catalogues:
  • /bin:bin is the abbreviation of Binary, which stores the most frequently used commands.

  • /usr: This is a very important directory. Many users' applications and files are placed in this directory, similar to the program files directory under windows.

  • /usr/bin: application for system users.

  • /usr/sbin: advanced management programs and system daemons for super users.

  • /usr/src: the kernel source code places the directory by default.

  • /boot: Here are some core files that are used when starting Linux, including some connection files and mirrored files.

  • /dev:dev is the abbreviation of Device (device). The directory stores the external devices of Linux, and the way to access devices and access files is the same in Linux.

  • /etc: this directory is used to store all the configuration files and subdirectories needed for system management.

  • /home: the user's main directory, in Linux, each user has a directory of its own, usually the directory name is named by user account.

  • /lib: this directory contains the most basic dynamic link shared library of the system, which is similar to the DLL file in Windows. Almost all applications need to use these shared libraries.

  • /mnt: the system provides this directory to allow users to mount other file systems temporarily. We can mount the CD-ROM on /mnt/ and then enter the directory to view the contents of the CD drive.

  • /opt: This is a directory placed to install additional software on the host computer. For example, if you install a ORACLE database, you can put it in this directory. The default is empty.

  • /proc: this directory is a virtual directory. It is a mapping of system memory. We can access system information directly by accessing this directory. The contents of this directory are not on the hard disk, but in the memory. We can also directly modify some of the files. For example, you can shield the host's ping command through the following commands, so that others can't ping your machine: echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all.

  • /root: this directory is the user directory of the system administrator, also known as super permissions.

  • /sbin s: the meaning of Super User, which is the system administrator used by the system administrator.

  • /selinux: this directory is a unique directory of Redhat/CentOS. Selinux is a security mechanism, similar to windows firewall, but this mechanism is more complex. This directory is to store SELinux related files.

  • /srv: this directory stores some data that needs to be extracted after service starts.

  • /sys: This is a big change in the linux2.6 kernel. A file system sysfs newly installed in the 2.6 kernel is installed under the directory. The sysfs file system integrates the following 3 kinds of file system information: the proc file system for process information, the devfs file system for the device, and the devpts file system for pseudo terminal. The file system is an intuitive reflection of the kernel device tree. When a kernel object is created, the corresponding files and directories are also created in the kernel object subsystem.

  • /tmp: this directory is used to store some temporary files.

  • /var: this directory contains things that are constantly expanding, and we are used to placing those frequently modified directories in this directory. Including various log files.

  • /lost+found: This directory is usually empty. When the system is shut down illegally, some files are stored here.

  • /media:linux system will automatically identify some devices, such as U disk, CD driver and so on. When it is identified, Linux will mount the identified device to this directory.

In Linux system, there are several catalogues which are more important. You should pay attention not to delete them or change the internal files at will. /etc: as mentioned above, this is the configuration file in the system. If you change a file in that directory, it may cause the system to fail to start. /bin, /sbin, /usr/bin, /usr/sbin: are placed directories for preset executable files, such as LS in /bin/ls directory.

It is worth mentioning that /bin, /usr/bin are instructions for system users (except for root users), while /sbin and /usr/sbin are instructions for root. /var: This is a very important directory. There are many programs running on the system, so every program will have corresponding log generation, and these logs will be recorded in this directory. Specifically, under the /var/log directory, the preset placement of mail is also here.

How to turn off the machine correctly

In fact, in the field of Linux, most of them are used on servers and seldom encounter shutdown operations. After all, running a service on the server is endless. Unless it is in special circumstances, it will not be shut down until it is too late.

Linux and windows are different. Under Linux, as every program (or service) is executed in the background, there may be quite a lot of people working on your host at the same time behind the screen you can't see, such as browsing web pages, sending letters, sending files by FTP, and so on. If you press the power switch directly to turn off the data, other people's data may be interrupted. In addition, the biggest problem is that if the shutdown is not normal, it may cause damage to the file system (because there is too little time to write the data back to the file, so some service files will have problems).

If you want to turn off the machine, you must ensure that there are no other users in the current system online. You can give the WHO instruction, and if you want to see the online state of the network, you can give the netstat -a instruction, depending on the background execution procedure, you can execute the PS -aux instruction. Using these instructions can give you a little understanding of the current usage state of the host.

  • Sync: synchronize data from memory to hard disk.

  • Shutdown: shutdown command, you can man shutdown to look at the help document, for example, you can run the following commands

  • Shutdown – h 10: "This server will shutdown after 10 mins" this command tells you that the computer will be switched off in 10 minutes and will be displayed in the current screen of the login user.

  • Shutdown – h now: shut down immediately.

  • Shutdown – h 20:25 : The system will be switched off at 20:25 today.

  • Shutdown – h +10: shut down in ten minutes.

  • Shutdown – r now : The system will be restarted immediately.

  • Shutdown – R +10: the system will be restarted in ten minutes.

  • Reboot: just restart, equate to shutdown – r now

  • Halt: closing the system is equivalent to shutdown – h now and poweroff.

Finally, it is concluded that, no matter whether the system is restarted or shut down, it is necessary to run the sync command to write the data in memory to disk. The commands for shutdown are shutdown - h now halt poweroff and init 0, and the commands for restarting the system are shutdown r now reboot init 6.

Click click Read the original text View More news