Linux Basic Knowledge 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# Sed-i ' s/\ (^[[:space:]]\) '/#\1/g/tmp/rc.sysinit

2. Copy the/boot/grub/grub.conf to/tmp directory and delete the white space characters from the beginning of the/tmp/grub.conf file.

# cp/boot/grub/grub.conf/tmpsed-i ' s/^[[:space:]]\+//g '/tmp/grub.conf

3. Delete the # and white space characters in the/tmp/rc.sysinit file that begin with # and followed by at least one white-space character in the line.

# sed-i ' s/^#[[:space:]]\+//g '/tmp/rc.sysinit

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

# sed-i ' 1,3s/\ (^.\)/#\1/g '/tmp/grub.conf

5. Change the last 0 of all enabled=0 or gpgcheck=0 in the/etc/yum.repos.d/centos-media.repo file to 1.

# sed-i ' s/enabled=0/enabled=1/g;s/gpgcheck=0/gpgcheck=1/g '/etc/yum.repos.d/centos6-01.repo

6, every 4 hours to perform a backup of the/etc directory, back up to the/backup directory, the saved directory name is the shape of etc-201608300202.

writing a script backupetc.sh

tar-czf/backup/etc-$ (date +\%y\%m\%d\%h\%m)/etc >/dev/null 2>&1# crontab-e* */4 * * * SH backupetc.sh

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/bin/cp/var/log/messages/logs/messages-$ (date +\%y\%m\%d)

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 * */2 * * * grep "^s"/proc/meminfo>>/stats/memory.txt

9. During working days, echo "Howdy" is executed every two hours.

* */2 * * 1-5/bin/echo "Howdy"

Script Programming Exercises

10. Create a directory/tmp/testdir-the current date and time.

#!/bin/bashdir_name=testdir-$ (date +%f%t) mkdir/tmp/$dir _name

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

#!/bin/bashfor ((i=1;i<101;i++));d otouch/tmp/$dir _name/file$idone

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

Sed-n ' n;p '/etc/passwd | Cut-d:-f1

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

#!/bin/bashfor i in ' seq ';d ouseradd user$iecho "User$i" | passwd--stdin User$i;done

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

#!/bin/bashfor i in ' seq ';d o touch/tmp/file$idone

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

#!/bin/bashfor in ' seq ';d ochown user$i:user$i/tmp/file$idone


This article is from "Bo Zi in the Water" blog, declined to reprint!

Linux Basic Knowledge 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.