HR: The linux questions that interviewers love to ask, see how many you can answer correctly

Summary

This article introduces common interview questions for Linux systems, mainly including file system management, environment configuration, process management, system resource usage, network settings, task scheduler, software package management, and system log viewing. I hope it will be helpful to you. Of course, in the interview, you may encounter more job-specific and position-specific questions, so you must be fully prepared. Good luck with your interview!

What does the Linux file system look like? How to access and manage files and directories?

The Linux file system is a hierarchical tree structure, which starts from the root directory (/) and contains a series of subdirectories and files respectively. The Linux file system supports various file system types, such as ext4, NTFS, FAT32, etc.

Accessing and managing Linux filesystems can be done through a command line interface (terminal) or a graphical interface.

In the command line interface, users can use commands such as cd, ls, mkdir, rm, etc. to access and manage files and directories. For example, to enter a directory named "documents", you can use the command "cd documents", and to view the files and directories under the current directory, you can use the command "ls".

In the graphical interface, users can use the file manager to access and manage files and directories. Common file managers include Nautilus, Thunar, Dolphin, etc. Users can use the mouse to click to open folders, view the properties of files and directories, create and delete files and directories, and other operations.

Whether using the command-line interface or a graphical interface, the basic operations for managing files and directories include creating, deleting, moving, copying, renaming, viewing and modifying permissions, and more. It should be noted that in Linux, the permissions of files and directories are very important. Users need to modify the permissions of files and directories through the chmod command to ensure that the access and modification permissions of files and directories are correct.

How to view and manage processes in Linux?

In Linux, you can use a series of commands to view and manage processes. Here are some commonly used commands:

  1. ps command: Used to view the processes currently running on the system. Commonly used parameters are as follows:
  • ps -ef: Display detailed information of all processes;
  • ps -aux: Display detailed information of all processes, including users and CPU usage;
  • ps aux | grep process name: Find process information based on process name.
  1. top command: Used to monitor the running status of processes in the system in real time. You can view the CPU and memory usage, as well as the CPU usage, memory usage and other information of each process.

  2. kill command: used to terminate the process. Commonly used parameters are as follows:

  • kill process number: terminate the process according to the process number;
  • killall process name: terminate the process according to the process name;
  • kill -9 process number: forcefully terminate the process.
  1. pkill command: used to terminate the process according to the process name. Commonly used parameters are as follows:
  • pkill process name: terminate all processes named process name;
  • pkill -9 process name: Forcefully terminate all processes whose process name is process name.
  1. renice command: used to modify the priority of the process. Commonly used parameters are as follows:
  • renice -n process priority process number: Change the priority of the process whose process number is the process number to the process priority.

How to use Linux command line tools to view system resource usage?

In the Linux system, you can use command line tools to view the usage of system resources. Here are some commonly used commands:

  1. top command: Used to monitor the running status of processes in the system in real time. You can view the CPU and memory usage, as well as the CPU usage, memory usage and other information of each process.

  2. free command: used to view the usage of system memory. You can view the total system memory, used memory, free memory and other information. Commonly used parameters are as follows:

  • free: display the system memory usage, the unit is KB;
  • free -m: Display system memory usage in MB;
  • free -g: Display system memory usage in GB.
  1. df command: used to view the usage of disk space. You can view information such as the total capacity, used capacity, and available capacity of the file system. Commonly used parameters are as follows:
  • df: display the file system usage, the unit is KB;
  • df -h: Display filesystem usage, displaying units in a human-readable manner.
  1. du command: Used to view the disk space usage of files or directories. You can view information such as the total size and actual size of a file or directory. Commonly used parameters are as follows:
  • du file or directory: display the size of the file or directory in KB;
  • du -h file or directory: Displays the size of a file or directory in human-readable units.

The above are commonly used Linux command line tools to check the system resource usage. It should be noted that these commands can only provide snapshot information of system resource usage, but cannot provide historical information of system resource usage. If you need to view historical information of system resource usage, you can use some monitoring tools, such as sar, sysstat, etc. .

How to configure the network settings of the Linux system?

In a Linux system, network settings can be configured in several ways:

  1. Using the ifconfig command: The ifconfig command can be used to configure network interfaces. Use the following command to view all network interfaces on the system:
ifconfig -a

The network interface can be configured with the following command:

ifconfig <接口名> <IP地址> netmask <子网掩码>

For example, to configure eth0 with an IP address of 192.168.0.100 and a subnet mask of 255.255.255.0, the following command can be used:

ifconfig eth0 192.168.0.100 netmask 255.255.255.0
  1. Use the ip command: The ip command is a replacement for the ifconfig command, which is more powerful and flexible. Use the following command to view all network interfaces on the system:
ip addr show

The network interface can be configured with the following command:

ip addr add <IP地址>/<子网掩码> dev <接口名>

For example, to configure eth0 with an IP address of 192.168.0.100 and a subnet mask of 255.255.255.0, the following command can be used:

ip addr add 192.168.0.100/24 dev eth0
  1. Use the nmtui command: nmtui is a text-based user interface that can be used to configure network settings. nmtui can be started with the following command:
nmtui

Then follow the prompts for network settings.

  1. Modify the configuration file: The network configuration file of the Linux system is located in /etc/network/interfaces or /etc/sysconfig/network-scripts/ifcfg-*. These configuration files can be modified using an editor to configure network settings.

The above are some common ways to configure the network settings of the Linux system. It should be noted that when configuring network settings, it is necessary to ensure the correctness of the network environment and network topology, so as to ensure the normal and safe network connection.

How to use the cron task scheduler of Linux to execute scheduled tasks?

In the Linux system, you can use the cron task scheduler to execute scheduled tasks. cron is a time-based task scheduler that executes specified commands at specified time intervals. The following are the steps to perform scheduled tasks using the cron task scheduler:

  1. Edit cron tasks: You can use the following commands to edit cron tasks:
crontab -e

This will open a text editor where you can add cron jobs.

  1. Add cron tasks: cron tasks consist of time information and commands to be executed. The format of a cron job is as follows:
* * * * * command
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday is both 0 and 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Among them, an asterisk (*) means to match any value, you can use a comma (,) to separate multiple values, use a hyphen (-) to indicate an interval, and use a slash (/) to indicate how often to execute. For example, the following is a cron job that executes every day at 2:00 AM:

0 2 * * * command
  1. Save cron task: After editing, save the cron task. You can use the following command to view cron tasks for the current user:
crontab -l
  1. Restart the cron service: The cron service needs to be restarted to take effect after editing or modifying the cron task. The cron service can be restarted with the following command:
systemctl restart cron

The above are the steps to execute scheduled tasks using the cron task scheduler. It should be noted that the execution time of the cron task is relative to the system time. If the system time is inaccurate, the cron task will also be affected. In addition, you need to ensure the correctness of the commands when editing cron tasks to avoid unnecessary errors.

How to install and manage software packages in Linux?

In Linux systems, you can use the package manager to install and manage software packages. Different Linux distributions use different package managers, here are some common package managers and how to use them:

  1. Debian/Ubuntu: Debian and Ubuntu use the dpkg and apt package managers. Packages can be installed using the following command:
sudo apt-get install <软件包名>

The package can be uninstalled with the following command:

sudo apt-get remove <软件包名>

The package list can be updated with the following command:

sudo apt-get update

Installed packages can be updated with the following command:

sudo apt-get upgrade
  1. CentOS/RHEL: CentOS and RHEL use the yum package manager. Packages can be installed using the following command:
sudo yum install <软件包名>

The package can be uninstalled with the following command:

sudo yum remove <软件包名>

The package list can be updated with the following command:

sudo yum check-update

Installed packages can be updated with the following command:

sudo yum update
  1. Arch Linux: Arch Linux uses the pacman package manager. Packages can be installed using the following command:
sudo pacman -S <软件包名>

The package can be uninstalled with the following command:

sudo pacman -R <软件包名>

The package list and installed packages can be updated with the following command:

sudo pacman -Syu

Above are some common package managers and how to use them. It should be noted that when installing and managing software packages, it is necessary to ensure that the source of the software packages is reliable, and it is best to back up the system data before installing new software packages to avoid unnecessary losses.

How to View and Manage Linux System Logs?

In the Linux system, you can check the system log to understand the system operation status and problems. System logs are generally stored in the /var/log directory, including the following files:

  1. /var/log/messages: System message log file, recording all messages of the system.

  2. /var/log/syslog: System log file, recording all logs of the system.

  3. /var/log/auth.log: System authentication log file, which records logs related to user login and authentication.

  4. /var/log/kern.log: Kernel log file, which records kernel-related logs.

  5. /var/log/boot.log: Startup log file, which records the logs during system startup.

Here are some common commands to view and manage Linux system logs:

  1. View system log files: Use the following command to view system log files:
sudo cat /var/log/messages
sudo cat /var/log/syslog
sudo cat /var/log/auth.log
sudo cat /var/log/kern.log
sudo cat /var/log/boot.log
  1. View recent logs: Use the following command to view recent logs:
sudo tail /var/log/messages
sudo tail /var/log/syslog
sudo tail /var/log/auth.log
sudo tail /var/log/kern.log
sudo tail /var/log/boot.log
  1. View logs for a specific period of time: Use the following command to view logs for a specific period of time:
sudo grep '关键字' /var/log/messages
sudo grep '关键字' /var/log/syslog
sudo grep '关键字' /var/log/auth.log
sudo grep '关键字' /var/log/kern.log
sudo grep '关键字' /var/log/boot.log

Among them, 'keyword' is the keyword to be searched.

  1. Clear log file content: Use the following command to clear the log file content:
sudo echo > /var/log/messages
sudo echo > /var/log/syslog
sudo echo > /var/log/auth.log
sudo echo > /var/log/kern.log
sudo echo > /var/log/boot.log
  1. Restart the rsyslog service: rsyslog is a commonly used log service in the Linux system. Use the following command to restart the rsyslog service:
sudo systemctl restart rsyslog

The above are some common commands to view and manage Linux system logs. It should be noted that when viewing and managing system logs, you need to ensure that you have sufficient permissions, and when problems occur, you must deal with them according to the log information.

おすすめ

転載: blog.csdn.net/qq_27575627/article/details/130181432