Chinaunix首页 | 论坛 | 博客
  • 博客访问: 469975
  • 博文数量: 164
  • 博客积分: 4024
  • 博客等级: 上校
  • 技术积分: 1580
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-10 16:27
文章分类

全部博文(164)

文章存档

2011年(1)

2010年(108)

2009年(55)

我的朋友

分类:

2009-10-18 21:40:46

一。什么是Shell
1.Shell是核心程序之外的指令解析器,是一个程序,同时是一种命令语言和程序设计语言
2.Shell的类型:ash,bash,ksh,csh,tcsh
 -/etc/shells
 -echo $SHELL显示所运行的Shell
3.程序在Shell中运行
4.Shell中可以运行子Shell
 
二。存取权限与安全
1.文件和目录的权限(-rwxr--r--)
2.setuid (suid/guid) (chmod u+s,g+s file)
3.chown和chgrp(chown user file/chgrp group file)
4.umask(umask nnn)
5.符号链接(ln -[-s] source-path target-path)
 
1.(1)chmod [who] operator [permission] filename
  who(u,g,o,a)
  operator(+,-,=)
  permission(r,w,x,s,t)
 (2)chmod mode filename
  mode r--4  w--2  x--1
  chmod 644 myfile
2.chown和chgrp
chown [-R] owner myfile
chown owner.group myfile
chown .group myfile
chgrp [-R] group myfile
3.umask
/etc/profile($HOME/.profile $HOME/.bash_profile))
umask 文件 目录
0      6     7
1      5     6
2      4     5
3      3     4
4      2     3
5      1     2
6      0     1
7      0     0
4.符号链接
硬链接
软连接
ln [-s] source-path target-path
 
三。Shell脚本
1.使用Shell脚本的原因
  功能强大
  节约时间
2.基本元素
 #!/bin/bash第一行
 #表示注释
 变量
 流程控制结构
3.运行方式
列如:helloworld.sh
#!/bin/bash
echo "hello world"
 
chmod u+x helloword.sh
./helloworld
4.shell特性
(1)别名
alias
alias ll="ls -alh"
 
$HOME/.bashrc
(2)命令替换
myfile的内容:
parm
findfile
 
ls `cat myfile` -al
(3)后台处理
什么是后台?
一个终端可以同时运行多个程序
nohup command &
 
jobs-l
(4)变量
例子:helloworld.sh
#!/bin/bash
printchar="hello world"
echo $printchar
变量用来存储信息
(5)管道(|)
把一个命令的输出链接到另一个命令的输入
ls|sort
(6)重定向(<>)
与管道相关,可以改变程序运行的输入来源和输出地点
sort
sortmyfile_dort.txt
(7)模式匹配
显示以txt为扩展名的文件或显示以a开头的文件,这种能力就称为模式匹配
正则表达式
(8)特殊字符
双引号(“):用来使Shell无法认出空格、制表符和其他大多数特殊字符。
单引号(‘):用来使Shell无法认出所有特殊字符
反引号(`):用来替换命令
反斜杠(\):用来使Shell无法认出其后的特殊字符,使其后的字符失去特殊含义
分号(;):允许在一行上放多个命令
&:命令后台执行
括号():创建成组的命令
大括号{}:创建命令块
竖杠(|):管道标示符
<>&:表示重定向
*?【】!:表示模式匹配
$:变量名的开头
#:表示注释(第一行除外)
空格、制表符、换行符:当做空白
 
阅读(1124) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~