Shell Programming in 24 hours
前言
1.shell responsibility
read your command and ask Unix kernel to execut
creat scripts-------> files contains a list of command
Hour 1 Shell basic
1.simple commands
2.complex commands
3.compound commands
$command1;command2;command3......
Hour 2 Script Basics
1.Unix System
Utilities------> programs and programs you can run
Kernel ------->connect utilites and hardware
2.Shell 初始化
check /etc/profile exists
check .profile in your home directory
两个都read后,display $
3.Interactive and Nonteractive Shell
1. mode---->inetractive 交互 input command >execute
---->noninteractive 非交互 read command stored in a file >execute them
2.start shell
/bin/sh -----> interactive mode
/bin/sh filename ------> noninteractive mode
3.Making a shell Script executable
开头加入一行 #!/bin/sh -------> cause a new shell to execute the script
Hour3 Working with files
1.files
ordinary files ; directories ; special files
2.Listing files
$ ls -F -----> 区分文件夹、文件与特殊文件
-l -----> 分行显示文件
-a
3.view the content of the file
$cat files
files1, files2, files3
-n ---------->标明行号
-b ---------->标明行号 并且跳过空白行
4.counting words
$wc files ---------->行数,单词数,字符数
file1 file2 file3
-l lines
-w words
-m or -c characters
5.Manipulating Files (操作文件)
1.coping files(cp)
$ cp source destination ------> destination是目标文件地址以及文件名,如果名字不变,
直接文件地址即可
source 是源文件名,不能为文件夹
**默认覆盖写入目标文件
-i sour dest ------->会询问是否覆盖写入
file1 file2 file3 dest ------->同时复制多个文件到文件夹中
2.Renaming file(mv)
$mv sour dest --------> 在同文件夹中remove也可以实现重命名的效果
-i --------> 询问是否覆盖写入
3.Removing files(rm)
$rm files
file1 file2 file3
-i file1 file2 ---------> 询问是否删除
Hour 4 Working with directories
1.pathname
/home/range/docs/ch5.doc
filename 为characters and (.) (-) (_)
Absolute pathname ---------> $pwd
Relative pathname ---------> (..) 代表上级文件目录
(.) 代表当前文件目录
2.cd
3.ls
4.Manipulating directories
1. mkdir
$mkdir dir
dir1 dir2 dir3
2.创建一系列文件夹
$mkdir -p /tmp/ch04/test1
如果目录中,没有中间文件夹,那么就可以通过-p选项直接创建
create all required parent directories
**不能创建文件夹与文件同名
3.复制文件夹coping directories
cp -r sour dest 将sour复制到dest 文件夹下(也可用于复制文件)
4.moving directories
$mv sour_dir dest_dir
5.Removing directories
$rmdir ----->remove empty directories
$rm -r ----->remove with their contents
Hour 5 Manipulating file attributes
1.File type
$ls -l
2.Symbolic Links
软连接(类似快捷方式)
$ln -s source destination 用ls -l可以查看链接
3.Device Files
1.character special files
crm-------
2.block special files
brw--rw----
4.change permission (chmod)
1.symbolic method
chmod u + r file
g - w
o = x
a s
chmod guo+rx *
-R 选项作用于下面所有文件与文件夹
2.octal Method(八进制方法)
Read 4
Write 2
Execute 1
5.change owners and groups
chown
chgrp option group files