Basic knowledge of Linux learning (vi)

Source: Internet
Author: User

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;

cp/etc/rc.d/rc.sysinit/tmp/

Vim/tmp/rc.sysinit

:%s/^[[:space:]]/#&/

:%s/\ (^ \)/#/g

match format: s/What to look for/what to replace/g global

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/

Vi/tmp/grub.conf

:%s/^[[:space:]]\+// This will match the blank characters at the beginning of the line, the beginning of the line can be dead any white space characters;

:%s/^[[:space:]]//g This expression will remove the first whitespace character from the beginning of the line;

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

Vi/tmp/rc.sysinit

:%s/^#[[:space:]]\+//g

4. Add # to the beginning of the first three lines in the/tmp/grub.conf file;

Vi/tmp/grub.conf

: 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;

Vi/etc/yum.repos.d/c

:%s/enabled=0/enabled=1/g

:%s/gpgcheck=0/gpgcheck=1/g

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

Crontab-e

XX */4 * * * root/bin/tar-cjf/backup/etc-' date +%y%m%d%h%m '/etc

Scheduled tasks: Time-sharing week

7, weekly 2,4,6 backup/var/log/messages file to/backup/messages_logs/directory, save the file name like messages-20160830

Crontab-e

* * * 2,4,6 root/bin/cp/var/log/messages/backup/messages_logs/messages-' date +%y%m%d '. bak

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

Crontab-e

XX */2 * * * cat/proc/meminfo | grep "^s*" >>/stats/memory/txt

9, working days of work time, every two hours to perform the echo "Howdy"

Crontab-e

XX 9-18/2 * * 1-5/usr/bin/echo "Howdy"



Script Programming Exercises

10, create the directory/tmp/testdir-the current date and time;

11. Create 100 empty files in this directory: file1-file100

#/bin/bash

Export dirtime= ' Date +%y%m%d%h%m '

mkdir/tmp/testdir-$dirtime

For f in {1..100};d o

touch/tmp/testdir-$dirtime/file$f

Done

12. Display the user name of the user who is located in the/etc/passwd file in the first even row;

#/bin/bash

Awk-f: ' nr%2==0 {print$1} '/etc/passwd


13. Create 10 user user10-user19, password and user name;

14, create 10 empty files file10-file19 in/tmp/;

15. Change the file10 and the genus to user10, and so on.

#/bin/bash

For I in {10..19};do

If ID user$i &>/dev/null;then

echo "User is Exit"

Else

Useradd user$i && echo "User$i" | passwd--sdin user$i &>/dev/null

Fi

Touch/tmp/file$i

Chown user$i:user$i/tmp/fule$i

Done


Basic knowledge of Linux learning (vi)

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.