Linux Operating System Final Exam Questions

1. Operational questions Give operation commands and screenshots as required (screenshots must be given for the command operation process and command results) (25 points in total)

1. Log in to the Linux system as the root user, create the exam.sh script in the current directory, edit the content of the following commands in the script, set the execution authority of the current user to the script, and test the execution result of the script . (5 points)

1) Output "Hello Linux"

vim exam.sh

#!/bin/bash

echo "Hello Linux"

2) Display online users

who

3) Statistically count the content of this script, displaying the number of lines, words, and bytes

wc exam.sh

2. Create a pinyin user with your own name (such as wangqiang), and force the establishment of a home directory with the same name, and set the password to 123. Move the exam.sh script to the new user's home directory, and replace the script owner with the new user. (8 points)

useradd -m -d /home/liwenlong -s /bin/bash liwenlong

passwd liwenlong

mv exam.sh /home/liwenlong

chown liwenlong:liwenlong /home/newuser/exam.sh

3. Switch to a new user, jump to the new user's home directory, and test to see if the current directory is the user's home directory.

Check the permission information of the exam.sh script file. If you have the execution permission, please execute the script. If you do not have the permission, set the execution permission and execute the script. (5 points)

ls -l exam.sh

pwd

ls -l exam.sh

./exam.sh

4. Create a symbolic link file examlink for exam.sh. (2 minutes)

ln -s /home/liwenlong/exam.sh /home/liwenlong/examlink

5. Dynamically monitor all processes of all users and refresh every 3 seconds. (2 minutes)

top -d 3

6. Combined with the pipeline, find the command to count the number of ordinary files in /etc. (3 points)

find /bin -type f| wc -l

2. Programming questions (15 points in total)

Create a script user.sh, add a new group as newgroup, and then add 10 users belonging to this group. The user name is in the form of userxx, where xx is from 01 to 10. Please give the script creation command, program code, and script execution command And screenshots of execution results (terminal or graphical interface screenshots are acceptable).

#!/bin/bash

groupadd newgroup

for i in $(seq 1 10);

do

if [ $i -lt 10 ];

then

username="user0$i"

else

username="user$i"

fi

useradd -m -s /bin/bash -G newgroup $username

echo "Welcome $username"

done

chmod u+x user.sh

bash user.sh

Guess you like

Origin blog.csdn.net/qq_64314976/article/details/131447387