Thinking about the Ubuntu20.04 file system

problem arises

When using the electron framework to develop desktop-side cross-platform software, when the developed program is deployed to Ubuntu, the system cannot generate log files. In view of the
above problems, I began to think that the electron program did not have root permissions, so it could not be created; later I thought it might be the Ubuntu file system. Permissions issue

Ordinary users can read and write addresses in the Ubuntu file system

  • Because it is impossible for users to modify the permissions of the file system after installing the software, the first solution is to find the address of the folder that ordinary users can operate
  • /home/用户名/Ordinary users can read and write under this path, but /logswe can’t be sure 用户名what the file addresses of the logs generated in the program are, so we give up this method first (there should be a way to get the user name)
  • The following lists the paths that ordinary users can read and write
    • /tmp/
    • /var/tmp/
    • /var/crash
    • /var/cap
    • /var/metrics
  • varNext, we need to think about the role of folders in the Ubuntu system: this directory is similar to usr, first of all it is a subdirectory under the root directory, and can also be used as a separate file system for storing various variable-length data files (such as log files), staging files, or pending temporary files
  • Ubuntu file system reference below
  • So we can store the log files generated by the software in the above-mentioned common user readable and writable directory
  • In fact, the best option is to save the log files to /tmpa directory, because ordinary users in this directory have permission to create and delete folders

Ubuntu file system

insert image description here
The size of the permissions marked in the above figure: None < List files only < Access files < Create and delete files; the maximum permission is Create and delete files

  • None: No operation can be performed
  • List files only: can only display all the contents of this folder, and cannot enter the lower-level directory
  • Access files: You can enter all directories under this folder
  • Create and delete files: the highest authority, you can create and delete files arbitrarily in this folder

Detailed explanation of Ubuntu file system

First level directory
  • /bin: Contains various common programs that can be shared by ordinary users and system administrators, such as bash, dd, gzip, grep, mv, mkdir and other commonly used basic commands.

  • /boot: Contains important boot files such as the system boot program GRUB and its configuration files, the linux kernel file vmlinuz, and the disk memory image file initrd.img.

  • /dev: Contains all device files supported by the system. Specifically, console represents the console, lp0 represents the printer, mem represents the physical memory of the system, sda represents the first disk connected to the main controller, and ttyXX represents the serial port device.

  • /etc: Contains all configuration files for system management and maintenance.

  • /home: Contains the home directory of all ordinary users.

  • /lost+found: Used to store files and directories deleted by the fsck command when detecting and repairing the file system.

  • /media: contains the mount point of the removable storage medium, insert the U disk, the system will automatically mount the U disk to a subdirectory of this directory.

  • /mnt: contains all custom file system mount points, which can be mounted on any file system, including NFS or CIFS network file systems.

  • /opt: The installation directory of additional software such as applications, similar to the Program Files directory in the windows system.

  • /proc: virtual file directory, empty directory when the system is shut down, the root directory of the process file system when the system is running, and part of the file system corresponds to the currently running process, which can be used to access the address space of the current process.

  • /root: The home directory of the superuser root

  • /sbin: Common tools for superuser administrators, such as administration and maintenance, system boot, and collection of recovery commands.

  • /srv: Shares some functions of the var directory and saves some data files required by network services.

  • /sys: The same virtual directory as proc, the root directory of various device information in the system, such as the block subdirectory contains configuration information of disks and disk partitions.

  • /tmp: Temporary file directory, used to store temporary files generated during system operation, and also for users to store their own temporary files. It should be noted that only the creator of the file can delete the response file.

  • /usr: It can be used as a subdirectory under the root directory, which stores various shared data provided by the system (user commands, library functions, header files, documents, etc.), and can also be used as a separate file system, which can be considered as a A recursive directory for rootwood, allowing for greater flexibility in the file system.

  • /var: This directory is similar to usr. First, it is a subdirectory under the root directory. It can also be used as a separate file system to store various variable-length data files (such as log files), temporary files or pending files. Temporary Files.

Secondary directory
  • /boot/grub: There are GRUB configuration files, three different types of initial boot programs at the first level.

  • /etc/apt: Contains configuration files used by software management tools, such as sources.list.

  • /etc/cron.d: Used to store configuration files and control files used by the cron process to schedule and run background processes. Other related directories cron.hourly, cron.daily, cron.weekly, cron.monthly four directories.

  • /etc/init.d: ​​Used to store script files that need to be scheduled and executed by init during the system boot process.

  • /etc/network: Contains the configuration file interfaces of the network interface, and the first-level related configuration files.

  • /etc/X11: Contains various configuration files used by the X server, such as xorg.conf, etc.

  • /usr/bin contains various commands frequently used by users

  • /usr/include is used to store various C language header files. This directory and its subdirectories are files frequently referenced by developers. Among them, the data structures defined in subdirectories such as sys, linux and bits have great reference value for in-depth study, understanding and mastering of Linux systems

  • /usr/lib Contains various shared library functions, which can be used by programmers to link their own programs statically or dynamically

  • /usr/sbin Contains various system administration and maintenance commands frequently used by system administrators after the system has booted

  • /usr/share The shared directory contains man (the root directory of the online documentation), info (the root directory of the GNU info documentation), doc (various package-specific documents), locale (language environment), vim (user guide), zoneinfo (time zone definition) and other subdirectories

  • /usr/src stores the source code and documents of the Linux system kernel, etc.

  • /var/lib stores package-specific dynamically linked shared libraries, configuration files, data files, status information, etc.

  • /var/log Storage directory for system daemon log files, including lastlog (the last login time of each user), messages (log messages of all kernel and system programs recorded by syslogd) and wtmp (system registry /logout record) and other important files. The files located in /var/log will continue to grow, so regular backup or deletion is required. Usually, the Linux system uses daily, weekly or monthly as the time period to perform routine checks on a regular basis, and delete obsolete data in a cyclic interception manner , keep the latest data for a certain time range, and keep the file size at a moderate scale. In the Ubuntu Linux system, the logrotate program will be executed once a day to check and process the system log files.

  • /var/lock is used to store lock files set when various service processes or applications access specific devices or files

  • /var/run The root directory of the system's running information files, including the PID of the daemon process stored in various .pid files. Another most typical file is /var/run/utmp, which contains user registration information in the current system

  • /var/spool is used to cache various files waiting to be processed, such as printing services, etc. Usually each type of cache file to be processed is located in its own subdirectory, such as /var/spool/cups, etc.

  • /var/tmp is used to store various temporary files

Find where software is installed in Ubuntu

You can try the following command

// 方式1
type 软件名
// 方式2
ps aux | grep 软件名
// 方式3
使用文件搜索命令 find 、locate、whereis查找
// 方式4
使用which命令查看运行文件所在的路径
// 方式5
dpkg -L 软件名 #显示包含此软件包的所有位置

Ubuntu modify file permissions

insert image description here

Guess you like

Origin blog.csdn.net/baidu_38493460/article/details/129080758