Linux Study First month quiz

Source: Internet
Author: User

1, the configuration and use of Yum source (5 points)
1) Create a local Yum source [base]
Mount/dev/cdrom/mnt
Name=local_base
baseurl=file:///mnt/
Gpgcheck=0

2) Install the development pack Group

Yum Grouplist
Yum Groupinstall Development Tools

2, copy/etc/ssh/sshd_config to/tmp/and renamed to Sshd_config.bak. Save all lines in the/tmp/sshd_config.bak file that begin with a non-# number and contain whitespace characters to/tmp/sshd_config. (5 points)

Cp/etc/ssh/sshd_config/tmp/sshd-config.bak
Cd/tmp
Cat Sshd_config.bak | Egrep "^[^#". [[: space:]]+.] > Sshd_config

3, scripting/root/bin/sysinfo.sh display the current host system information, including hostname, operating system version, kernel version, CPU model, memory size, hard disk partition (5 points)

#!/bin/bash
Echo '----------------------------------'
Echo ' System infomation '
Echo ' hostname: 'hostname
Echo ' System-release: 'cat /etc/centos-release
echo ' Kernel: 'uname -r
echo ' CPU: 'lscpu | egrep -i "型号名称" | tr -s ‘ ‘ | cut -d‘ ‘ -f2-7
Echo ' mem: 'free -h | egrep -i "mem" | tr ‘:‘ ‘ ‘ | tr -s ‘ ‘ | cut -d‘ ‘ -f2
Echo ' HD: 'lsblk | egrep "sda\>" | tr ‘:‘ ‘ ‘ | tr -s ‘ ‘| cut -d‘ ‘ -f5
Echo '----------------------------------'

4, the root user-defined alias command vimnet, equivalent to Vim/etc/sysconfig/network-scripts/ifcfg-ens33, and the root to perform the history command, show the specific time of each command execution. (5 points)

Vim. BASHRC
Alias vimnet= ' Vim/etc/sysconfig/network-scripts/ifcfg-ens33 '
. . BASHRC
Vim. Bash_profile
histtimeformat= "%F%T"
. . bash_profile

5. Point out the similarities and differences between soft links and hard links (at least around) (5 points)

One, soft links can be for folders, hard links do not
Second, hard links and source files have the same inode code, soft links and source files are different Inode code (Inode is the index byte, used to store data information, the system can find the corresponding file by the Indoe value fastest)
Third, hard links cannot span partitions, soft links can span partitions
Four, delete soft link source file Soft link will expire, delete hard link source file Hard link can be used normally

6, download the compilation installation HTTPD 2.4 The latest version, write out the installation process (5 points)
Cd
TAR–XF httpd-2.4.25.tar.bz2
CD httpd-2.4.25
Vim README
: Q
Vim INSTALL
: Q
Yum Groupinstall Development Tools
Mkdir/app/apache24
./configure--prefix=/app/apache24
Make&&make Install

7, Filter ifconfig command results in all more than 0 and less than 255 three digits (5 points)

Ip A | Egrep-o "\<[0-2][0-9][0-9]\>" | Egrep-v "2[5-9]{2}"

8, the user mage deleted by the home directory to restore, copy/etc/shadow to mage home directory. and set only user Shixintao can read/home/mage/shadow (5 points)
Cp–r/etc/skel/home/mage #cp-r recursive processing, processing all files under the specified directory with subdirectories
Cd/home/mage
Chown–r Mage:mage Mage
Cp/etc/shadow.
Chmod Shadow
Setfacl–m U:shixintao:r Shadow
Setfacl–m U:shixintao:rx/home/mage

9, Statistics/var/log/httpd/access.log log access frequently top ten addresses, and from large to small sort (5 points)

Cat/var/log/httpd/access_log | Egrep-o "(\<[0-2][0-9]{1,2}.) {3}\<[0-2][0-9]{1,2}\> "| Sort | uniq-c | Tr-s ' | Sort-t '-k2-rn | Head-n10

10. Open two terminals, output the execution result of input command in Terminal 1, and output to Terminal 2 (5 points) at the same time.

Open terminal can be opened locally with ctrl+alt+f1-6, Xshell can be opened directly new terminal
Terminal 1 for pts/0 Terminal 2 for PTS/1
LS/|TEE/DEV/PTS/1

11, mistakenly delete/lib64/libc.so.6 system library files, how to restore, experimental description (5 points)

One, reboot in case of CD mount
Second, press ESC while reading the progress bar and start with the CD-ROM
Third, choose to enter the rescue mode "Rescue"
Four, after entering rescue mode, copy a libc.so.6 from the current/lib64 to/mnt/sysimage/lib64.
Five, exit rescue mode restart machine to complete recovery

12, mistakenly delete rpm Package command, how to recover, experimental description (5 points)

One, reboot in case of CD mount
Second, press ESC while reading the progress bar and start with the CD-ROM
Third, choose to enter the rescue mode "Rescue"
Iv. enter MKDIR/CD after entering rescue mode create a folder
Five, MOUNT/DEV/SR0/CD to hang the CD on the/CD
Six, rpm-ivh/cd/packages/rpm-4.11.3-21.e17.x86_64.rpm--root=/mnt/sysimage/install the RPM package on the CD based on the original root
Seven, exit rescue mode restart machine to complete recovery

13, calculate the sum of 2+4+6+...+96+98+100 (5 points)

echo {2..100..2} | Tr ' + ' | Bc

14, take/ETC/SYSCONFIG/NETWORK-SCRIPTS/IFCFG-ENS33 base name, use two methods to achieve (5 points)

1.echo/etc/sysconfig/network-scripts/ifcfg-ens33 | Egrep-o "\<[_0-9a-za-z-]+/?$" # \?: matches its preceding character 1 or 0 times
2.echo/etc/sysconfig/network-scripts/ifcfg-ens33 | Rev | Egrep-o "^/? [0-9a-za-z-]+\> "| Rev
Note: The Rev command outputs each line of the file in characters, that is, the first character is the last output, the last character is output first, and so on.
3.basename/etc/sysconfig/network-scripts/ifcfg-ens33
4..echo/etc/sysconfig/network-scripts/ifcfg-ens33 | Egrep-o "\<[[:alpha:]]*\>$"

15, the/etc/directory, the execution of the command, the following functions (5 points)
(1) Display file list from large to small order-s to file size.
Ll–s/etc
(2) Show hidden files only
L./etc
Ls–d. / etc
(3) Show only directory-D displays directories like files, not files under them
ls–d/etc/
/
(4) Show file list by mtime time-T is sorted by time.
Ls–t/etc
(5) Press Atime time to display the file list-U is sorted by the time the file was last accessed.
Ls–u/etc
16, write/root/bin/excute.sh, to achieve interaction with users, to determine whether the parameters given by the user can be read, writable, executable (5 points)

Vim excute.sh
#!/bin/base
Read-p "Please input file:" File
If [-E "$file"]; Then
[-R "$file"] && [-W "$file"] && [-X $file "] && echo" parameter readable writable executable "&& exit
[-R "$file"] && [-W "$file"] && echo "parameter readable writable cannot be executed" && exit
[-R "$file"] && [-x $file] && echo "parameter readable executable cannot write" && exit
[-R "$file"] && echo "parameter readable cannot write cannot execute" && exit
[-W $file] && [-x $file] && echo "parameter writable executable unreadable" && exit
[-W "$file"] && echo "parameter writable cannot be performed unreadable" && exit
[-X $file] && echo "parameter can not be read or write" && exit
echo "This parameter does not have any permissions"
Else
echo "The file does not exist"
Exit
Fi

17, write/root/bin/create.sh can generate a new script including author, contact, version, time and description, and can directly edit it, after editing automatically add Execute permission (5 points)

vim/root/bin/create.sh
[-a ' $ '] && echo "file is exist" && exit
Touch "$"
Echo ' #!/bin/bash ' >> ' $ '
echo "#name: $" >> "$"
Echo ' #author: SXT ' >> ' $ '
Echo ' #email: [email protected] ' >> ' $ '
Echo ' #version: 1.0 ' >> ' $ '
Echo ' #number: ">>"
Echo ' #time: ' >> ' $ ' date +%F
chmod u+x "$"
Vim + "$"
Exit

18, write a script, so that it can pass two parameters, the implementation of the parameter addition, subtraction, multiplication, divide operation and output operation value (5 points)
(There is no space between subtraction equals and arguments)
#!/bin/bash
Read-p "Input your Number1:" Num1
Read-p "Input your Number2:" Num2
add=$[$Num 1+ $Num 2]
sub=$[$Num 1-$Num 2]
rid=$[$Num 1$Num 2]
div=$[$Num 1/$Num 2]
echo "$Num 1 + $Num 2 = $ADD"
echo "$Num 1-$Num 2 = $SUB"
echo "$Num 1
$Num 2 = $RID"
echo "$Num 1/$Num 2 = $DIV"
Exit

19, write/root/bin/wcfile.sh statistics/etc directory of the number of directories, the number of files, and find out the/etc/directory and the total number of files (5 points)
#!/bin/bash
dnum=find /etc -type d | wc -l
The number of directories in ECHO/ETC is "$dnum"
fnum=find /etc -not -type d | wc -l
The number of files in the echo/etc is "$fnum"
Num=$[dnum+fnum]
The total number of files and directories in the ECHO/ETC is "$num"
Unset Dnum
unset num
Unset Fnum
Exit

20. Write/root/bin/baketc.sh to find files that have not been modified in the/etc/directory for more than 1 days, and compress them back into the/bakup directory. If there is no previous backup, then backup, if the backup file exists more than 2 minutes to back up, otherwise quit. The format of the backup is Yyyy-mm-dd-hh-mm-ss.xz (Y for year, M for month, D for Day, h for, M for minutes, s for seconds) (5 points)
(#. XZ Compression Package format)
Vim/root/bin/baketc.shbr/>#!/bin/bash
#name: baketc.sh
#author: Chenjingyu
#email:[email protected]

#number: 02
#time: 2017-06-15
A=find /bakup -name *.xz
b=find /bakup -mmin +1 -name *.xz
shijian=date +%F‘ ‘%T

If [-Z ' $a '];then
Find/etc-mtime +0 |xargs tar-cjf/bakup/"$shijian". XZ 2&>/dev/null
echo "Backup creation succeeded"

elif [-N "$b"];then
Rm-f "$b"
Find/etc-mtime +0 |xargs tar-cjf/bakup/"$shijian". XZ 2&>/dev/null
echo "Backup created successfully, old backup deleted"

Else
echo "Last backup not more than two minutes"
Fi

Linux Study First month quiz

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.