Some basic topics and analysis of Linux operating system

1. Create file command practice

1. Create a temporary directory under the / directory

insert image description here

2. Create five files under the temporary directory test, the file names are passwd, group, bashrc, profile, sshd_config

insert image description here

3. Create a soft link of /etc/motd in /test, the file name is motd.soft; create a hard link of /etc/motd as motd.hard, the method of creating a hard link is similar to that of a soft link, the difference is that the soft link has a - the s

insert image description here

Title 2. Redirection Exercises

1. Write the system kernel version information and release version information into 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:
insert image description here

Note: ">" can also be followed by the file name, but using ">" will overwrite the content of the original file, while ">>" is appending (writing content after the file content)

2. Add the host name of the current host and the shell information used by the current user to the /test/motd.hard file

Again, first learn how to find a hostname.
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 Information Lookup" method. -e and \n means newline
insert image description here

3. Write the file name of the file in the root directory to the /test/file file

First of all, search for the root directory and use "ls /" to find it. The writing method is still the same and use ">>" to write.
Every time you finish writing, you can "cat" the file name to see if the operation of the topic is realized.
insert image description here

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, and check it through "pwd". The details of the current working directory can be viewed through "ll -d". The method of adding information is the same.
insert image description here

Three, tee command practice

1. Add the current time to the passwd, group, bashrc, profile, sshd_config files in the /test directory

The time is viewed through "data", as follows:
insert image description here

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 user name of the current user:
1. "echo $USER"
2. View it through "whoami"
Additional information should be added with "-a" on the basis of the added information, such as:
insert image description here

Title 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
insert image description here
and then enter ": r /etc/passwd", enter the following page, and enter "%s/root/admin/g": "
insert image description here
g" means all, "/" It is only used for separation, and other symbols such as "#" "@" and so on can also be used.
Finally, enter "wq" to save and exit.

2. Read the content of the /etc/group file into /test/group, and only keep the content of the line 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.
insert image description here
insert image description here

3. Read the content of the /root/.bashrc file into /test/bashrc, and delete the line content starting with #

insert image description here

4. Read the content 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

insert image description here
Move the cursor to the end of line 17, then press "O" to insert the content directly, just enter "port 22".
insert image description here

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 line number range. "g" means all
insert image description here
the modifications are completed as shown in the figure:
insert image description here

6. Save the /test/sshd_config file as /test/sshd.conf

The method is simple: enter "w /test/sshd.conf"
insert image description here

7. Copy the contents of the first line in 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 lines. Such as; 2YY, said to copy two lines.
insert image description here
Another way: by the code "1 co $", where the special symbol "dollar sign" means the last line.

8. Copy the content of the first two lines in the profile and sshd_config file in the /test directory to the penultimate line of the document

insert image description here
insert image description here
It's just 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".

Guess you like

Origin blog.csdn.net/Zombie_QP/article/details/127485082