Topic connection and analysis of Linux operating system (2)

1. View file content

1. Check line 6 of the /etc/passwd file

Use head and tail to operate. "head -n 6" means to view the contents of the first 6 lines, and "tail -n 1" means to view one line from back to front.
Insert image description here

2. View the lines starting with SELINUX in /etc/selinux/config

Use groups to operate
Insert image description here

3. Find the line ending with no in /etc/ssh/sshd_config

Using group representation, "group n$" means finding lines ending with n
Insert image description here

4. Filter /etc/ssh/sshd_config lines containing numbers

Use "group [0,9]" to find numbers from 0 to 9
Insert image description here

2. Text processing commands

1. View the contents of the first column of the /etc/passwd file with: as the delimiter, and sort them in reverse alphabetical order.

"cut" delimits the character, "-d:" defines the delimiter character, here is ":", "-f1" needs to take which field, here is the "first line".
"sort -r" sorts in reverse order.
Insert image description here

2. Use the cut command to cut and display the IP address of the current host.

Insert image description here

3. Copy and move

1.

(1) Create a subdirectory dir in the /test directory and copy /etc/passwd to the directory
(2) Copy the /etc/ssh/sshd_config file to the /test directory
(3) Copy /etc/yum.repos. Copy the d/ directory to the /test directory
(4) Copy the /etc/hosts file to the /test directory
(5) Copy the /etc/hostname file to the /test directory
(6) Move the /test/sshd_config file to /test/ dir directory and renamed it to sshd.conf.

These questions all have the same purpose, so I wrote them together.
It's all a "cp" copy and move.
Insert image description here

4. File search

1. In the $HOME directory and its subdirectories, search for files that were changed 2 days ago

Through the "find" method, "-mtime" indicates the time when the content was modified, and "-2" indicates the file name within 2 days or less.
Insert image description here

2. Look for files starting with host in the /etc/ directory

Use "-name" under "find" to match names, and "host*" indicates files starting with host.
Insert image description here

3. Find directory files under /test/

Insert image description here

4. In the /test directory and subdirectories, search for files exceeding 2KB

"-size" means the file size
"+2k" means greater than 2KBPlease add image description

5. Packaging and compression

1. Compress all files and folders in the /test directory into the myfile.zip file

Use "zip" to compress
Please add image description
and view the results:
Please add image description

2. Unzip the myfile.zip file to /opt

Unzip using "unzip".
Please add image description

3. Pack all the files in the /opt directory and compress them with gzip into /test/newfile.tar.gz

First use "cd" to enter the "/opt" directory, and then use "tar" to package.
Please add image description

4. Check what files are in the /test/newfile.tar.gz file?

View via "tvf".
Please add image description

5. Download newfile.tar.gz to the windows client host

6. In the /test directory, back up all files under /etc and retain their permissions

Backup via "-cvf".
Please add image description

Guess you like

Origin blog.csdn.net/Nirvana92/article/details/127478666