[title song] Linux from introduction to mastery (October 9, 2021)

Keywords: Linux CentOS vim Design Pattern

https://www.educoder.net/paths/43

Level 1: Linux initial experience

#!/bin/bash
#Write the command to complete the task in the following section
#*********begin*********#
cd /
ls -a
#********* end *********#

Level 2: common Linux commands

#!/bin/bash
#Write the command to complete the task in the following section
#*********begin*********#
touch newfile
mkdir newdir
cp newfile newdir/newfileCpy
#********* end *********#

Level 3: Linux query command help statement

#!/bin/bash
#Write the command to complete the task in the following section
#*********begin*********#
man 3 fopen
#********* end *********#

Chapter II

Level 1: create / delete new users

#!/bin/bash
#Write the command to complete the task in the following section
#***********begin*************#
useradd -m newUser
userdel -r oldUser
cd /home/newUser
pwd
#************end**************#

Level 2: Linux user password management

#!/bin/bash

#Create newUser new user

#Enter the command to set the user password before the symbol < < (the command remains on the same line as < < EOF), enter the password on the next line, and confirm that the password is entered on the next line
#For example:
#command << EOF
#password
#password
#EOF
#***********begin*************#
useradd newUser
passwd newUser << EOF
123456
123456
EOF
#************end**************#

Level 3: Linux user permission switching

#!/bin/bash

#Create newUser new user
#***********begin*************#
useradd newUser
#************end**************#

#Enter the command to set the user password before the symbol < < (the command remains on the same line as < < EOF), enter the password on the next line, and confirm that the password is entered on the next line
#For example:
#command << EOF
#password
#password
#EOF
#***********begin*************#
passwd newUser<< EOF
123123
123123
EOF
#************end**************#

#Use the su command to switch the current user identity to newUser, execute the whoami command, and then restore the original identity;
#Prompt to complete with the - c parameter of the su command
#***********begin*************#
su -c whoami newUser
# 123123
# whoami
exit
#************end**************#

Chapter 2: advanced user management of Linux

Off 1: create / delete user groups

#!/bin/bash

#Write the command to complete the task in the following section
# Create a new user group newGroup;
# Create a new user group newGroupID and set its ID to 1010;
# Delete the existing user group oldGroup.
# Note: the execution environment of this platform logs in as root account by default, so all commands executed are executed with root permission.

#***********begin*************#
groupadd newGroup
groupadd -g 1010 newGroupID
groupdel oldGroup
#************end**************#

Level 2: change of Linux user's group

#!/bin/bash

#Write the command to complete the task in the following section
# Create a new user newUser;
# Use the usermod command to add an existing user group oldGroup for user newUser.
#***********begin*************#
useradd newUser
usermod -a -G oldGroup newUser
#************end**************#

Level 3: Linux user / user group editing

#!/bin/bash

#Write the command to complete the task in the following section
# Modify the existing user oldName name of the system to newName;
# Modify the login directory of the modified newName user to the existing folder / home/newName;
# Modify the existing user group oldGroup name of the system to newGroup
#***********begin*************#
usermod -l newName oldName

usermod -d /home/newName newName

groupmod -n newGroup oldGroup
#************end**************#

Chapter III hard disk management of Linux storage system

Level 1: common storage architecture of Linux

1,Direct attached storage refers to( ),Storage area network refers to( ),Network attached storage refers to( ) A
A,
DAS,SAN,NAS
B,
SAN,DAS,NAS
C,
NASA,SAN,DAS
2,NAS Is storage consolidation through the network so that different types of clients can access at the () level. C
A,
Hardware
B,
system
C,
file

Level 2: use of fdisk in Linux

1. If you want to view only the partition of the hard disk sdb newly added to the Centos system in Linux, what command should you use? C

A,fdisk -l
B,fdisk sdb
C,fdisk /dev/sdb
D,fdisk /dev/sda

2. The function of fdisk is () ACD

A. Establish DOC partition or logical partition
B. Format partition
C. Delete DOC partition or logical partition
D. Display partition information

3. The following statement about the fdisk command is correct (). AC

A. Manage all partitions and be able to format each partition
B. Be able to create all partitions and format each partition
C. All partitions can be created, but each partition cannot be formatted
D. Only the primary partition can be created, and all partitions except the primary partition can be formatted in windows

4. After creating a partition using fdisk, you can exit directly? B

A. Right
B. Wrong

Level 3: the use of mkfs in Linux

1. Does mkfs itself perform the work of establishing a file system? A

A. Do not execute
B. Execute

2. The command to format / dev / sda1 into ext4 format is mkfs.ext4/dev/sda1. A

A. Right
B. Wrong

3. The command to format / dev/sdb2 into ext3 format partition with mkfs command is (). D

A,fdisk /dev/sdb2
B,mkfs.ext4 /dev/sdb2
C,mount/dev/sdb2
D,mkfs.ext3 /dev/sdb2

4. What formats can the partition be formatted with the mkfs command? ABC

A,ext2
B,xfs
C,ext4
D,txt

Chapter IV

1, Linux file / directory management

Level 1: file creation / deletion of Linux

#!/bin/bash

#Write the command to complete the task in the following section
#***********begin*************#
touch file1 file2
rm oldFile1 oldFile2
#************end**************#

Level 2: Linux directory creation / deletion

#!/bin/bash

#Write the command to complete the task in the following section
# Create two new empty directories newDir1 and newDir2.
# Delete the two existing directories oldDir1 and oldDir2,
# The oldDir1 directory is empty and the oldDir2 directory is not empty.
#***********begin*************#
mkdir newDir1 newDir2
rmdir oldDir1 
rm -r oldDir2

#************end**************#

Level 3: file copy / rename of Linux

#!/bin/bash

#Write the command to complete the task in the following section
# Copy the files file1 and file2 in the current directory to the directory Dir;
# Copy the file file1 in the current directory to the directory Dir and rename it file1Cpy;
# Move the files file3 and file4 in the current directory to the directory Dir;
# Rename the file file5 in the current directory to file6.
#***********begin*************#
cp file1 file2 Dir
cp file1 Dir/file1Cpy
mv file3 file4 Dir
mv file5 file6
#************end**************#

Level 4: Linux directory copy / redo command

#!/bin/bash

#Write the command to complete the task in the following section
# Copy Dir1 and Dir2 in the current directory to Dir;
# Copy the directory Dir1 under the current directory to the directory Dir and rename it Dir1Cpy;
# Move Dir3 and Dir4 in the current directory to Dir;
# Rename the directory Dir5 under the current directory to Dir6.
#***********begin*************#
cp -r Dir1 Dir2 Dir
cp -r Dir1 Dir/Dir1Cpy
mv Dir3 Dir4 Dir
mv Dir5 Dir6
#************end**************#

Level 5: Linux file / directory content viewing

#!/bin/bash

#Write the command to complete the task in the following section
# View all contents of the file file1 in the current directory;
# View the first 5 lines of file2 in the current directory;
# View the last 5 lines of file file2 in the current directory;
# View all contents (including hidden contents) under the directory / home directory.
#***********begin*************#
cat file1
head -n 5 file2
tail -n 5 file2
ls -a /home
#************end**************#

2, Linux file / directory advanced management I

Level 1: Linux file permission modification

#!/bin/bash

#Write the command to complete the task in the following section
# Set the owner permission of the existing system file oldFile1 to executable;
# Delete writable permissions for the same group of user permissions of the existing file oldFile2 in the system;
# Add executable permissions for other group user permissions of the existing file oldFile3 in the system;
# Set the permission of the existing file oldFile4 in the system to the owner permission to be readable,
# The permissions of users in the same group are writable, and the permissions of other users are executable;
#***********begin*************#
chmod u=x oldFile1
chmod g-w oldFile2
chmod o+x oldFile3
chmod u=r,g=w,o=x oldFile4 
#************end**************#

Level 2: Linux directory permission modification

#!/bin/bash

#Write the command to complete the task in the following section
# 1 set the owner permission of the existing directory oldDir1 in the system to executable;
# 2 delete writable permissions for the same group of user permissions of the existing directory oldDir2 in the system;
# 3 add executable permissions for other group user permissions of the existing directory oldDir3 in the system;
# 4 set the permission of the existing directory oldDir4 in the system to the owner permission to be readable,
#   The permissions of users in the same group are writable, and the permissions of other users are executable;
# 5 set the permission of the existing directory oldDir5 in the system to the owner permission to be readable,
#   The permissions of users in the same group are writable, and the permissions of other users are executable,
#   At the same time, all subdirectories or file permissions under the directory are processed together.
#***********begin*************#
chmod u=x oldDir1
chmod g-w oldDir2
chmod o+x oldDir3
chmod u=r,g=w,o=x oldDir4
chmod -R u=r,g=w,o=x oldDir5
#************end**************#

Level 3: modifying file / directory owners for Linux

#!/bin/bash

#Write the command to complete the task in the following section
# Set the owner of the existing system file oldFile to oldUser;
# Set the owner of the existing system directory oldDir1 to oldUser;
# Set the owner of the existing system directory oldDir2 and all its subdirectories and sub files to oldUser.
#***********begin*************#
chown oldUser oldFile
chown oldUser oldDir1
chown -R oldUser oldDir2 
#************end**************#

Level 4: modification of Linux file / directory group

#!/bin/bash

#Write the command to complete the task in the following section
# Set the group of the existing system file oldFile to oldGroup;
# Set the group of the existing system directory oldDir1 as oldGroup;
# Set the existing system directory oldDir2 and the group of all its subdirectories and sub files to oldGroup.
#***********begin*************#
chgrp oldGroup oldFile
chgrp oldGroup oldDir1
chgrp -R oldGroup oldDir2
#************end**************#

3, Linux file / directory advanced management II

Level 1: Linux file / directory related command operations (df, du)

#!/bin/bash

#Write the command to complete the task in the following section
# Display the disk size occupied by the existing system file oldFile in a highly readable manner;
# List the total capacity of all files in the existing directory. / oldDir of the system, and list the size of each file
#*********begin*********#
du -h oldFile
du -a oldDir
#********* end *********#

Level 2: Linux file / directory links

#!/bin/bash

#Write the command to complete the task in the following section
 A file already exists for the system oldFile Create hard link oldFileHardLink ;
A file already exists for the system oldFile Create soft link oldFileSoftLink ;
Directory already exists for the system oldDir Create soft link oldDirSoftLink . 
#***********begin*************#
ln oldFile oldFileHardLink
ln -s oldFile oldFileSoftLink
ln -s oldDir oldDirSoftLink
#************end**************#

4, Linux file / directory advanced management III

Level 1: Linux file / directory setuid and setgid

#!/bin/bash

#Write the command to complete the task in the following section
# Readable r=4, writable w=2, executable x=1
# Use mnemonic syntax to set setuid permission for the existing system file oldFile1 (default permission: rw_rw_r_);
# Use mnemonic syntax to set setgid permission for the existing directory oldDir1 (default permission: rwxrwxrwx);
# Use mnemonic syntax to cancel setuid permission for the existing system file oldFile2;
# Use mnemonic syntax to cancel setgid permission for the directory oldDir2 that already exists in the system.
#***********begin*************#
chmod u+x,u+s oldFile1
chmod g+s oldDir1
chmod u-s oldFile2
chmod g-s oldDir2
#************end**************#

Level 2: Linux directory stick bit

#!/bin/bash

#Write the command to complete the task in the following section
# Use mnemonic syntax to set stick bit permission for the existing directory oldDir1 (default permission: rwxrwxrwx);
# Use mnemonic syntax to cancel the stick bit permission for the existing directory oldDir2 in the system.
#***********begin*************#
chmod o+t oldDir1
chmod o-t oldDir2
#************end**************#

Level 3: Linux file / directory special properties

#!/bin/bash

#Write the command to complete the task in the following section
# Add the i attribute for the existing file / root/oldFile1 in the system;
# View the special attributes of the existing file / root/oldFile2 in the system;
# Remove the i attribute for the file / root/oldFile3 that already exists on the system.
#***********begin*************#
chattr +i /root/oldFile1
lsattr -a /root/oldFile2
chattr -i /root/oldFile3
#************end**************#

Chapter 5 Linux compressed and archived files

1, Linux file packaging and decompression

Off 1: tar packaging command

#!/bin/bash

#Write the command to complete the task in the following section
# Use the tar command to package the oldFile1 and oldFile2 files in the current directory into a newFile.tar file;
# Use the tar command to unzip the oldFile.tar file in the current directory to the current directory.
#*********begin*********#
tar -cvf newFile.tar oldFile1 oldFile2
tar -xvf oldFile.tar
#********* end *********#

Level 2: file compression command

#!/bin/bash

#Write the command to complete the task in the following section
# Use the tar command to package and compress the oldFile1 and oldFile2 files in the current directory into a newFile.tar.gz file;
# Use the bzip2 command to compress the oldFile.tar file in the current directory;
# Use the zip command to compress all files / directories in the oldDir directory under the current directory to generate oldDir.zip.
#*********begin*********#
tar -zcvf newFile.tar.gz oldFile1 oldFile2
bzip2 oldFile.tar
zip -r oldDir.zip oldDir
#********* end *********#

Level 3: file decompression command

#!/bin/bash

#Write the command to complete the task in the following section
# Use the tar command to unzip the oldFile.tar.gz file in the current directory;
# Use the bunzip2 command to unzip the oldFile.tar.bz2 file in the current directory;
# Use the unzip command to unzip oldDir.zip in the current directory.
#*********begin*********#
tar -zxvf oldFile.tar.gz
bunzip2 oldFile.tar.bz2
unzip oldDir.zip
#********* end *********#

Chapter 6 Linux file location commands

File / directory search for Linux

Off 1: query command - locate

#!/bin/bash

#Write the command to complete the task in the following section
# Use the locate command to find the total number of all files or directories including group letters in the system;
# Use the locate command to locate the newly created file newFile in the system.
#*********begin*********#
locate -c group
updatedb
locate newFile
#********* end *********#

Off 2: query command - which/whereis

#!/bin/bash

#Write the command to complete the task in the following section
# Use the which command to locate the location of the useradd command;
# Use the where is command to query all the information of the useradd command, including binary file location, description file location and source file location;
# Use the where is command to find only the useradd command description file location.
#***********begin*************#
which useradd
whereis useradd
whereis -m useradd
#************end**************#

Off 3: query command - find

#!/bin/bash

#Write the command to complete the task in the following section
# Use the find command to find all files / directories ending in. conf in the current directory;
# Use the find command to find all directories starting with my in the current directory;
# Use the find command to find files larger than 1M in the / root directory;
# Use the find command to find all Link details in the / root directory with the type of symbolic Link and the file name ending with Link
# (prompt to use ls -l to view file details).
#***********begin*************#
find -name "*.conf"
find -name "my*" -a -type d
find /root -size +1M
find /root -name "*Link" -a -type l -exec ls -l {} \;
#************end**************#

Posted by slipperyfish on Sat, 09 Oct 2021 12:11:29 -0700