Linux system directory structure & terminal

System directory structure

             In the Linux or Unix operating system, all files and directories are in an inverted tree structure starting from the root node. The top level of the file system is the root directory, which is represented by /. Under the root directory, there can be either directories or files, and each directory can contain subdirectory files. In this way, a huge file system is formed.

             Enter the command: ls / in the command window to display the files in the root directory:

             Tree directory structure:

Directory explanation

             Here's an explanation of these directories:

System startup requires:

  • /boot: Stored here are some core files used when starting Linux, including some connection files and image files.

  • /etc: Abbreviation for Etcetera (etc.). This directory is used to store all configuration files and subdirectories required for system management.

  • /sys : This is a big change in the Linux 2.6 kernel. A new file system sysfs that appeared in the 2.6 kernel is installed in this directory. The sysfs file system integrates information from the following three file systems: the proc file system for process information, the devfs file system for devices, and the devpts file system for pseudo terminals. The file system is a visual 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.

  • /lib : Abbreviation for Library. This directory stores the system's most basic dynamic link shared libraries, which function similarly to DLL files in Windows. Almost all applications require these shared libraries.

Instruction set:

  • /bin: Abbreviation for Binaries. This directory stores the most frequently used commands.

  • /sbin : s means Super User and is the abbreviation of Superuser Binaries (superuser binary files). The system management programs used by system administrators are stored here.

External file management:

  • /dev: Abbreviation of Device. This directory stores Linux external devices. The way to access devices in Linux is the same as the way to access files.

  • /media : The Linux system will automatically recognize some devices, such as U disks, optical drives, etc. After recognition, Linux will mount the recognized devices to this directory.

  • /mnt : The system provides this directory to allow users to temporarily mount other file systems. You can mount the optical drive on /mnt/, and then enter this directory to view the contents of the optical drive.

Temporary Files:

  • /run : is a temporary file system that stores information since the system started. When the system restarts, files in this directory should be deleted or cleared. If you have a /var/run directory on your system, it should point to run.
  • /usr : Abbreviation for Unix shared resources. This is a very important directory. Many of the user's applications and files are placed in this directory, similar to the program files directory under Windows.
  • /usr/bin: Applications used by system users.

  • /usr/sbin: More advanced management programs and system daemons used by super users.

  • /usr/src: The default placement directory for kernel source code.

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

  • /tmp : Abbreviation of temporary (temporary). This directory is used to store some temporary files.
  • /root : This directory is the user home directory of the system administrator, also known as the super privileged person.

  • /home : The user's home directory. In Linux, each user has his own directory. Generally, the directory name is named after the user's account, such as alice, bob and eve in the picture above.

During operation, use:

  • /proc : Abbreviation for Processes. /proc is a pseudo file system (that is, a virtual file system) that stores a series of special files in the current kernel running status. This directory is a virtual directory, which is a mapping of system memory. System information can be obtained by directly accessing this directory. The contents of this directory are not on the hard disk but in the memory. You can also directly modify some files in it. For example, you can use the following command to block the ping command of the host so that others cannot ping your machine:

    echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
  • /var : The abbreviation of variable (variable). This directory stores things that are constantly expanding. It is customary to place directories that are frequently modified in this directory. Includes various log files.

For extension:

  • /srv : This directory stores some data that needs to be extracted after the service is started.

  • /opt : Abbreviation of optional (optional). This is the directory where additional software is installed for the host. For example, if you install an ORACLE database, you can put it in this directory. The default is empty.

Redhat/CentOS specific directories:

  • /selinux : This directory is unique to Redhat/CentOS. Selinux is a security mechanism, similar to the Windows firewall, but this mechanism is more complicated. This directory stores selinux-related files.

Replenish

             There are several important directories in the Linux system that you need to pay attention to. Do not accidentally delete or change internal files at will.

  • /etc : This is the configuration file in the system. If a file in this directory is changed, the system may not start.
  • /bin, /sbin, /usr/bin, /usr/sbin : This is the system’s default directory for placing executable files. For example,  ls  is in the /bin/ls directory. It is worth mentioning that  /bin and /usr/bin  are commands for system users (general users except root), while /sbin and /usr/sbin are commands for root.
  • /var : This is a very important directory. There are many programs running on the system, so each program will have corresponding logs, and these logs are recorded in this directory, specifically in the /var/log directory. In addition, The default placement of mail is also here.

terminal

Introduction

             The Linux terminal is a powerful and flexible tool in the Linux operating system. It is a command line interface, also known as a command line terminal, Shell or console. Provides ways to interact with the system. In the Linux terminal, users can use text commands to perform various tasks, such as file management, process management, software installation, network configuration, etc.

             The core component of the Linux terminal is the Shell, which is an interpreter that parses the commands entered by the user and passes them to the operating system program, and outputs feedback information from the operating system. There are multiple shells available in Linux, the most common of which is Bash (Bourne Again Shell), which is the default shell for many Linux distributions. Other common Shells include Zsh (Z Shell), Fish (Friendly Interactive Shell), etc.

Basic form of terminal command:

command  [-options ]  parameter1  parameter2

             The first input part of the command is definitely a command (command) or an executable file. Pressing the Enter key means starting to execute this command. If the entered command line is too long, you can use a backslash (\) to escape the Enter symbol (note: a special character must be followed immediately after the backslash to escape.), so that the entered command line can continue to the next line; If there are several commands to be executed together, each command can be separated by a semicolon (;), and then press Enter to execute them together (for example: ls -a;ls -al).

Ordinary user & root user

             There are two types of users in the Ubuntu system, one is the ordinary user (chen in the picture below), and the other is the root user (super user with administrator rights).

             After opening the terminal, the command prompt is $, indicating that you have logged in to the terminal as an ordinary user. If you log in as root, you can enter the following command: sudo su or su root, press Enter and enter the password (note: you cannot see the password when entering the password), you can log in to the terminal as the root user. If you do not know the password or cannot install Ubuntu properly, you need to set the root password first. First enter the command: sudo passwd root, press Enter and enter the password of the currently logged in user, and then enter the customized root password twice. The root password will be After the setting is completed, you can use the su root command to log in to root.

             Log in to the terminal as the root user and the command line prompt will change to: #. Enter exit or CTRL+D to exit the root user, return to the normal user, and then enter exit or CTRL+D to exit the terminal.

Note: $: Command line prompt for ordinary users; #: Command line prompt for root user.

Graphic mode & Text mode

             The Ubuntu system has two usage modes. One is the graphics mode, with 6 text interface terminals tty1 ~ tty6 preset. The second is text mode.

             The switching method between graphics mode and text mode is as follows:

  • CTRL+ALT+F1 ~ F6: Text interface to log in to tty1 ~ tty6 terminals
  • CTRL+ALT+F7: graphical interface desktop

Commonly used shortcut keys & terminal commands ( commands  ) 

shortcut key

  • Ctrl+Alt+T: Enter the Ubuntu terminal;
  • Ctrl+C: Stop the program running in the terminal;
  • Ctrl+Z: Pause the program running in the terminal. If you want to continue executing the program, enter the percent sign %;
  • TAB: Complete directory or command. For example, enter tou in the terminal, and then press TAB, the completion command will appear touch;
  • CTRL+SHIFT+T: Create a new tab;
  • CTRL+D: Close the tab (terminal);
  • Ctrl+A: Move the cursor to the beginning of the line;
  • Ctrl+E: Move the cursor to the end of the line;
  • Ctrl+U: Clear the characters from the cursor to the beginning of the line;
  • Ctrl+W: Clear the word before the cursor;
  • Ctrl+K: Clear the characters from the cursor to the end of the line;
  • Ctrl+S: suspend the current shell;
  • Ctrl+Q: Re-enable;
  • Ctrl+L: clear the terminal;
  • Ctrl+Shift+C/V: Copy and paste operations in the terminal;
  • CTRL+ALT+F1 ~ F6: Text interface to log in to tty1 ~ tty6 terminal;
  • CTRL+ALT+F7: Graphical interface desktop.

instruction 

  • sudo reboot: used to restart the Linux system, which is the same as restart in Windows system
  • sudo shutdown -r now: Restart immediately
  • sudo shutdown -r 10: Automatically restart after 10 minutes
  • sudo shutdown -r 20:35: Restart at 20:35

Note: You can use the command: shutdown -c to cancel the restart set by the command: shutdown.

  • sudo halt: shut down immediately (usually add -p to turn off the power)
  • sudo poweroff: shut down immediately 
  • sudo shutdown -h now : Shut down immediately
  • sudo shutdown -h 10: Automatically shut down after 10 minutes 
  • exit: Exit the terminal 

Note: You can use the command: shutdown -c to cancel the shutdown set by the command: shutdown.

  • ls: List all explicit files in the current directory
  • ls -a: List all files in the current directory, including hidden files starting with a dot (.)
  • ls -l: List all explicit files in the current directory, as well as file-related attribute information
  • ls -al: List all files and related file attributes in the current directory, including hidden files
  • Note: Two special directories (current directory and parent directory), as well as hidden directories or files.

Current directory: The current working directory of the user, represented by a dot "  .  " or " ./ ";

Parent directory: the upper-level directory of the current directory, represented by two dots " .. ", or " ../ ";

Hidden directory or file: A directory or file name starting with a dot indicates a hidden directory or file (such as .bashrc). That is, the directory or file is not displayed when searching in the default way. You can use the ls command in the command window to view hidden files and directories in the current directory.

  • date: output the current system time
  • date +%Y/%m/%d: Output the current system date: year/month/day (/ is optional, it mainly acts as a separator)
  • date +%H:%M: Output the current system time: hour:minute (the function of: is the same as above)
  • cal: displays the current system’s calendar for this month
  • cal [[moth] year]: Displays the calendar of a certain year and month. For example, cal 10 1993 will display the calendar of October 1993.
  • bc: Enter a simple calculator, the operators can be: + - * / ^ %, etc.

Note: In this calculator, just enter the calculation formula and press the Enter key to output the calculation result. For example, input: 1+2, and then Enter, the output result is 3. If you enter 1/2 and then Enter, the result is 0. The reason is that the calculator performs integer division calculations by default, that is, the result only outputs the integer part and not the decimal part. If you enter 9/2 again, the result is 4. If you want to output decimals, you can enter the command: scale=number, where number represents the number of decimal places to be retained. For example, enter the command scale=3, and then enter 9/2, the result will be 4.500, with three decimal places retained. The command to exit the calculator is: quit.

  • pwd: displays the current path
  • touch file_name: Create a file named filename in the current path
  • mkdir new_folder: Create a folder named folder in the current path
  • rm file_name: Delete the file named filename in the current path. This command can only delete files, not folders.
  • rmdir empty_folder_name: Delete empty folders (folders with files cannot be deleted)
  • rm -r folder: delete a folder with files
  • rm -rf dir_name/file_name: Delete the folder named dir_name or the file named file_name in the current path
  • cd ..: Return to the previous directory
  • cd absolute path: enter a certain directory. For example: cd .. or cd /home/chen or cd ~

.. // Represents the upper level directory
. // Represents the current directory
- // Represents the previous directory
~ // Represents the current user's home directory
// Represents the root directory of the Ubuntu system

* // refers to all files - universal matching type

  • apt-get: used to install and uninstall software online in ubuntu. To install vim: apt get install vim, to uninstall vim: apt get remove vim. The installation must be online, that is, the Ubuntu system must be online to use this command.
  • Check the cpu temperature: (1) Install acpi command: sudo apt-get install acpi; (2) Enter the command: acpi -t, output the cpu temperature
  • free -m: View memory usage separately
  • top: Check memory and cpu usage
  • gnome-system-monitor: Open the task manager under ubuntu
  • clear: Equivalent to: Ctrl+l. Refreshing the screen essentially just turns the terminal display page back one page. If you scroll up the screen, you can still see the previous operation information. This command is generally used.
  • reset: Completely refresh the terminal screen. All previous terminal input operation information will be cleared. Although this is more refreshing, the entire command process is a bit slow and less used. 

Guess you like

Origin blog.csdn.net/weixin_60461563/article/details/132916763