1. Copy the/etc/rc.d/rc.sysinit file to the/tmp directory and add # to the beginning of the line with at least one whitespace character in the/tmp/rc.sysinit file;
Only CentOS 6 has this file.
# cp/etc/rc.d/rc.sysinit/tmp/# Vim/tmp/rc.sysinit
Input: (enter the last line mode)
:%s/^[[:space:]]/#&/
s/what to look for/replace with content/modifiers
%: Full text, equivalent to 1,$
&: Referring to the entire content found in the previous lookup
2, copy/boot/grub/grub.conf to/tmp directory, delete the blank character of the beginning of the/tmp/grub.conf file;
# cp/boot/grub/grub.conf/tmp/# Vim/tmp/grub.conf
Last-line mode
:%s/^[[:space:]]\+//
3. Remove the # and white space characters from the/tmp/rc.sysinit file that begin with # and followed by at least one white-space character
Topic unintelligible
# Vim/tmp/rc.sysinit
Last-line mode
:%s/^#[[:space:]]\+//
4. Add # to the beginning of the first three lines in the/tmp/grub.conf file;
# vim/tmp/grub.conf
Last-line mode
: 1,3s/^/#&/
5. Change the last 0 of all enabled=0 or gpgcheck=0 in the/etc/yum.repos.d/centos-media.repo file to 1;
# Vim/etc/yum.repos.d/centos-media.repo
Last-line mode
: s/=0/=1/
6, every 4 hours to perform a backup of the/etc directory, back up to the/backup directory, save the directory named Shape etc-201608300202
7, weekly 2,4,6 backup/var/log/messages file to/backup/messages_logs/directory, save the file name like messages-20160830
8, every two hours every day to take the current system/proc/meminfo file in the beginning of all the information in the S./stats/memory.txt file
9, working days of work time, every two hours to perform the echo "Howdy"
# date +%y%m%d%h%m201609101425
# crontab-e #编辑定时任务 # crontab-l #查询 # crontab-l #移除所有任务
crontab file format: minutes hours Sun moon Day Day commands
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "border=" 0 "style=" Background:url ("/e/u261/ Lang/zh-cn/images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650) this.width=650 ; "Src=" Http://s4.51cto.com/wyfs02/M00/87/17/wKioL1fUAnjwKmFGAAAk7GtRFpE441.png "title=" Dc9c632d-fa74-4b5d-9631-02548b9d9d44.png "alt=" Wkiol1fuanjwkmfgaaak7gtrfpe441.png "/>
*: On behalf of each time unit is executed once, the first "*" represents the execution of every minute (here and the specific time unit is easy to confuse)
*/n: Execute once every n time unit
N-M: Continuous Time range
Cp-a: Equivalent to-DR--preserv=all replication, all attributes are retained, and if the source file is the attribute of the linked file, the link file property is copied instead of the file itself
+: Specify the time format, %y represents the year,%m represents the month, and%d represents the day,%h represents the hour, and%m represents minutes
' Command ': Back quotes inside for command
Note: Need to be clear * meaning, from small to large for specific time units (seconds, minutes) defined
Script Programming Exercises
10, create the directory/tmp/testdir-the current date and time;
# mkdir-pv/tmp/testdir-' Date ' +%f%T "' mkdir: Directory Created"/tmp/testdir-2016-09-10 "
-P: exists in no error, and can automatically create the required directories;
-V: Show more information
11. Create 100 empty files in this directory: file1-file100
#/bin/bash# The first line specifies the program that interprets the script command for I in ' seq ';d o touch file$i Done
Syntax 1
For variable name in list;
Loop body
Done
Syntax 2
For (variable initial value; loop control condition; variable change expression); Do
Loop body
Done
12. Display the user name of the user who is located in the/etc/passwd file in the first even row;
#!/bin/bash
#
Sed-n ' n;p '/etc/passwd | Cut-d ': '-f1
SED options
-N: Use Quiet (silent) mode. In the usage of general sed, all data from STDIN is generally listed on the terminal. However, if you add the-n parameter, only the line (or action) that is specially processed by SED is listed.
SED command
N: Reads the next line of matching rows to the pattern space
P: Display the contents of the mode space
Cut command
-d ': '-f1 takes the 1th field with a colon delimiter
13. Create 10 user user10-user19, password and user name;
#!/bin/bash
#
For i in {10..19};d o
ID user$i &>/dev/null && echo "The user is exists" | | Useradd user$i && echo "user$i" |passwd--stdin user$i &>/dev/null
Done
Output redirection
&>: Overwrite redirection ( merge standard output and error output redirect for the same data stream)
&>/dev/null: standard output redirects to an empty device file, does not output any information to the terminal
Logical operations
&& Logic and
Command 2 does not execute when command 1 is executed correctly
Command 2 does not execute when command 1 is not executed correctly
|| Logical OR
Command 2 does not execute when command 1 is executed incorrectly
Command 2 does not execute when command 1 is executed correctly
Modify user passwords in a non-interactive manner
echo "PASSWORD" | Passwd–stdin USERNAME
14, create 10 empty files file10-file19 in/tmp/;
Script
#!/bin/bash
#
For i in {10..19};d o
Touch/tmp/file$i
Done
Command line
# Touch File{10..19}
15. Change the file10 and the genus to user10, and so on.
#/bin/bash
#
For i in {10..19}; Do
if [-e/tmp/file$i];then
Chown user$i:user$i/tmp/file$i
else echo "No such file."
Fi
Done
Grammar
If double Branch statement
If [conditional judgment]
Then
Conditions for the establishment of implementation
Else
Conditions do not set up the implementation
Fi
Week six Homework