Learn Shell notes (day1)

Source: Internet
Author: User

Recently the company is not very busy, so the idle time to read more about the shell of some things, because in the development test under Linux, know something about the shell is very helpful to yourself.

about what a shell is, a shell of Linux that is responsible for interacting with the user, then interpreting the user's input to the operating system and processing the output of a wide variety of operating systems, returning the final result to the user.

The shell script is when the command or statement is not executed in the command line, but through a program file execution, the program is a shell script, shell program is similar to the DOS system under the batch program (*.bat),

The user can use a series of commands or command-line statements in a script, and these commands, variables, and process Control statements organically combine to form a powerful shell script.

Widnows the backup site and the data script that was developed using the batch program bat:

1 @echo  off2date=%date: ~0,4%-%date: ~5,2%-%  Date: ~8,2%3 mysqldump-uroot-p  -a-b >d:\bak\ "%date%".  SQL4 rar.exe a-k-r-s-ml D:\bak\ "%date%". Sql.rar D:\bak\ "%date%". SQL 5 del d:\bak\*. SQL 6 7 rar.exe a-k-r-s-ml D:\bak\ "%date%" Htdocs.rar D:\work\phpnow\htdocs

Example one: Clear a simple command script for messages log files under/var/log

1Root_uid=02Log_dir ="/var/log/"3 #要使用root身份的用户来进行4 if["$UID"-ne"$ROOT _uid" ]5  Then 6    Echo "must is the root to run this script!"7Exit1  8 fi 9 TenCD $LOG _dir | | { One     Echo "cannot change to this dir!" AExit1 - }     -  the Cat/dev/NULL> ${log_dir}/Messages -  - Echo "logs Clean up!"

Three ways to empty the log:

1 Echo " " >/var/log/a.log2 >/var/log/a.log3cat /dev/null >/var/log/a.log

Shell scripts are good at handling plain text types of data, while almost all of the configuration files in Linux, log files are plain text files

Learn Shell notes (day1)

Related Article

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.