1. Create file command exercises
1. Create a temporary directory test under the / directory
This is relatively basic, that is, test creation, which can be completed using mkdir, such as:
2. Create five files in the temporary directory test. The file names are passwd, group, bashrc, profile, sshd_config.
Before creating these five files, the most basic thing is to return to the current directory, use "cd" to return to the "test" directory, and then use "touch" to create the files.
3. Create a soft link to /etc/motd in /test with the file name motd.soft; create a hard link to /etc/motd as motd.hard
Use "ln" to create, and pay attention to the location of "target" and "content". For example, when creating a soft link to /etc/motd, the file name is motd.soft, then the file name is placed on the right and the soft link is on the left.
The method of creating hard links is similar to that of soft links.
2. Redirect Exercise
1. Write the system kernel version information and release version information to the /test/motd.soft file
First of all, you need to know how to find the kernel version information and release version information. The kernel version information is found through "uname -r", and the release version information is found through "cat /etc/redhat-relear", such as: Writing is relatively simple
, Just use ">>" followed by the file name. As shown in the figure above,
note: ">" can also be followed by the file name, but using ">" will overwrite the content of the original file, while ">>" appends (after the file content write content)
2. Append the current host name and the shell information used by the current user to the /test/motd.hard file
Same, first understand how to find the host name.
There are two methods: 1. Directly "cat /etc/hostname".
2. Use "echo $HOSTNAME", where "hostname" must be capitalized.
The same goes for the "current user's information search" method.
The method of adding information is the same as the previous question.
If you want the written content to look better, use "-e" and "\n" to achieve line breaks, such as:
3. Write the file name of the file in the root directory to the /test/file file
First, search for the root directory through "ls /". The writing method is still the same, use ">>" to write. After
each writing, you can "cat" the file name to see if the operation of the question is achieved.
4. Check whether the current working directory is the /test directory, and append the detailed information of the current working directory to the /test/file file
Check whether the current working directory is the /test directory by using "pwd". Details of the current working directory can be viewed with "ll -d". The method of appending information is the same.
3. tee command practice
1. Add the current time to the passwd, group, bashrc, profile, sshd_config files in the /test directory
The time can be viewed through "data" as follows:
2. Append the current user’s username to the passwd, group, bashrc, profile, sshd_config files in the /test directory
First of all, there are two ways to find the username of the current user:
1. "echo $USER"
2. View it through "whoami"
To add information, add "-a" to the added information, such as:
4. vim command practice
1. Read the contents of the /etc/passwd file into /test/passwd, and modify the root character in the file to admin
First enter "vim /test/passwd" to enter passwd
and then enter ": r /etc/passwd" to enter the following page and enter "%s/root/admin/g":
"g" means all, "/" It is only used for separation. Other symbols can also be used, such as "#", "@", etc.
Finally enter "wq" to save and exit.
2. Read the contents of the /etc/group file into /test/group, and only retain the contents of the lines starting with root.
The same steps as before, except that "passwd" is replaced by "group" and
only the beginning of "root" is saved. Then just enter "g!/^root/d", "d" means delete.
result:
3. Read the contents of the /root/.bashrc file into /test/bashrc and delete the lines starting with #
Start the same way, then enter "g/^#/d"
4. Read the contents of the /etc/ssh/sshd_config file into /test/sshd_config, and add a line of content Port 22 after line 17 of the file.
The start is still the same.
Then enter the following page: Enter "set nu" to view the number of lines.
You can move the cursor after line 17, and then press "O" to directly insert content. Just enter "port 22".
5. Change yes to no in lines 40-50 in the /test/sshd_config file
Method: "40,50s/yes/no/g", 40,50 represents the row number range. "g" means all. As shown
in the figure:
The modification is completed as shown in the figure:
6. Save the /test/sshd_config file as /test/sshd.conf
The method is simple: enter "w /test/sshd.conf"
as shown in the figure:
7. Copy the first line of the passwd, group, and bashrc files in the /test directory to the last line of the document
It's very simple. First, move the cursor to the beginning of the first line, then press "YY" to copy the first line, then move the cursor to the last line, and press P to paste.
You can also press a number before pressing "YY" to indicate the number of rows. For example; 2YY means copying two lines.
Another way: represented by the code "1 co $", where the special symbol "dollar sign" represents the last line.
8. Copy the first two lines of the profile and sshd_config files in the /test directory to the second to last line of the document.
The same as the second method of the previous question:
except that the first two lines are represented by "1,2" and the last line is represented by "$-1", that is, the code is "1,2 co $-1".
Tips: When deleting a directory, you cannot delete it directly. You need to use "-r" in "rm" to delete it level by level.