Experiment 2
Note: The student ID in the following content needs to be replaced with your own student ID
1. Use the SSH client to log in to the root account, check whether there is a subdirectory myshare in the /tmp directory, and if not, create the directory;
mkdir /tmp/myshare
2. Create a folder named "Student Number" and a file named exam2.txt in the myshare directory;
cd /tmp/myshare
mkdir 2018xxxx
touch exam2.txt
3. Create a new user named test and specify uid as 1024;
useradd test -u 1024
4. Add /etc/passwd and /etc/shadow lines containing user test information to the exam2.txt file;
Here it is recommended to open an additional session to dynamically observe the changes in the content of exam2.txt, and enter the command tail -f tmp/myshare/exam2.txt
tail -f /tmp/myshare/exam2.txt
Switch to the original session, enter cat /etc/passwd /etc/shadow | grep test >> exam2.txt command
cat /etc/passwd /etc/shadow | grep test >> exam2.txt
Switch to another session and find that the content of exam2.txt has changed
5. Append the contents of the first 13 lines of /etc/passwd to the file named exam2.txt in the myshare directory
head -13 /etc/passwd >> exam2.txt
6. Append the content of all files and subdirectories under the myshare directory to exam2.txt in long format
ls -laR ../myshare/ >> exam2.txt
7. Set the owner of the myshare directory and all files and subdirectories under it to the user test, and change the group to mail
chown -R test:mail ../myshare/
8. Append the content of all files and subdirectories under the myshare directory to exam2.txt in long format;
ls -laR ../myshare/ >> exam2.txt
9. Use the su command to switch to the user test account; enter the tmp/myshare/student number" directory, and use the vi editor to write the following program, the program name is hello.sh: #!/bin/bash echo "app start" echo
-e func (){ echo "hello linux"} func echo -e echo "app end"
su test
cd 2018xxxx
vi hello.sh
i
Enter the program in vi:
echo "app start"
echo -e
func() {
echo "hello Linux!"
}
func
echo -e
echo "app end"
After inputting, press ESC key to exit, press :wq to save
10. After saving hello.sh, give the owner of hello.sh readable, writable and executable permissions, and the same group can read and execute others.
chmod 751 hello.sh
11. View the file permission information of hello.sh in long format, and append the output to exam2.txt;
ls -l hello.sh >> ../exam2.txt
12. Enter ./hello.sh to execute the script and view the output results. And append the output result to exam2.txt;
./hello.sh >> ../exam2.txt
13. Enter the user home directory of user test, create a soft link myhello.sh of hello.sh in this directory, and copy hello.sh to this directory and rename it to hello.sh.bak;
cd /home/test
ln -s /tmp/myshare/2018xxxx/hello.sh myhello.sh
cp /tmp/myshare/2018xxxx/hello.sh hello.sh.bak
14. View all files in the main directory of user test in long format and append the results to exam2.txt
ls -l ../test/ >> /tmp/myshare/exam2.txt
15. Execute the myhello.sh file in the main directory of the user test to check whether the link is normal;
./myhello.sh
16. Exit the user test account and return to the root account
exit
17. View all files (including hidden files) in the user test home directory in long format and append the results to exam2.txt
ls -a -l /home/test/ >> exam2.txt
18. Search for all files (ordinary files) with the suffix .conf from /usr, and append the output to exam2.txt;
find /usr -name "*.conf" -type f >> exam2.txt
19. Find the file with the largest file capacity from the conf file found in the previous step, and append this file to exam2.txt in long format; (backquotes)
ls -lSh `find /usr -name "*.conf" -type f` | head -n 1 >> exam2.txt
20. Count how many user accounts there are in the system, and add the number to exam2.txt;
wc -l /etc/passwd >>exam2.txt
21. Convert the exam2.txt file to windows format.
unix2dos exam2.txt
22. Send exam2.txt to the window
sz exam2.txt
23. Delete all contents of user test (including home directory)
rm -rf /home/test/
24. Delete the tmp/myshare directory
rm -rf tmp/myshare/
25. Rename exam2txt to student number.txt and submit
Finally, thank you for your study~