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)