免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 690 | 回复: 0
打印 上一主题 下一主题

SHELL [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-05-31 12:01 |只看该作者 |倒序浏览
第一章 shell 简介
-什么是shell
-存取权限和安全
-shell简单脚本
-shell特性
1.1  什么是shell

  -shell是核心程序(kernel)之外的指令解析器,是一个程序,同时是一种命令语言和程序设计语言。
-shell的类型ash、bash、ksh、csh、tcsh
  -/etc/shells
  -/echo $SHELL
-程序在shell中运行
-shell中可运行子shell
#ls
#cat /etc/shells
#echo $SHELL 显示当前的shell
#/bin/csh 进入到csh
#exit  退出当前shell
#ls  两个tab键,帮助功能,补全以ls开头的命令
#help   显示shell命令
1.2  存取权限与安全
-文件和名录的权限(-rwxr--r--)
-setuid(suid/guid)(chmod u+s,g+s file)
-chown和chgrp(chown user file/chgrp group file)
-umask (umask nnn)
-符号链接(ln [-s] source_path target_path)
#ls -l  显示文件权限及空间
#ls -lh  注意h的区别
  -、d、l、b(块文件)、c(字符文件)、p(管道文件)、s(socket文件 如:ls -l /tmp/.X11-unix/XO)
chmod [who] operator [permission] filename
- who (u,g,o,a)
- operator (+,-,=)
- permission (r,w,x,s,t)
#mkdir testfile
#chmod u=rwx,g+w,o+r testfile
#ls -l
#chmod u+s testfile  s位涉及安全问题
#chmod g+x,o+x testfile  这个文件所属的组或其它用户会获得属主的权限
#chown root.antiy testfile         s位:其它用户会拥有root的权限
#ls -l
#chmod g+s testfile  这个文件所属的组或其它用户会获得属组的权限
#ls -l
#chmod o+t testfile  运行时放到swap里
#ls -l
#ls -l /bin | grep '^...s'
s位有安全隐患,但为什么还需要s位呢?
chmod mode filename
- mode
  r 4 w 2 x 1
chmod 644 filename
chmod 740 filename
#chmod 4744 filename
#chmod 6744 filename
#chmod 7744 filename
chown和chgrp
注意-R的作用,子目录也随之更改
#chown root testfile
#ls -l
#chown -R root testfile
#ls -l testfile
#chgrp antiy testfile
#chown root.antiy testfile -R
#ls -l
umask 缺省权限
#umask
022
#touch filename
#ls -l filename
#mkdir direactory
#ls -lda direactory
自己找一下umask的值与目录和文件的规律
#umask 000
#umask
000
#touch filename1
#ls -l filename1
#mkdir direactory1
ls -lda direactory1
#umask 022
-注意安全性问题
/etc/profile ($HOME/.profile
$HOME/.bash_profile)
-umask
#cat /etc/profile | grep "umask"

***********************************************************************************************************
-符号链接
  -硬链接
  -软连接
  -ln [-s] source_path  target_path
-shell教本
  -使用shell脚本的原因
   功能强大,节约时间。
  -shell脚本基本元素
   #!/bin/bash
   -第一行
   #
   -表示注释
   变量
   流程控制结构
例子:
helloworld.sh
#!/bin/bash
#输出一个hell world的shell
printchar="hello world"
echo $printchar
echo $HOME
#chmod u+x helloworld.sh
#./helloworld.sh

  shell特性
  别名,命令替换,后台处理,变量,管道,重定向,
  模式匹配,特殊字符
别名:
-alias
-alias ll='ls -alh'
#alias
#alias ll='ls -alh'
#alias ll='ls -l --color=tty'
#cat $HOME/.bashrc 每个用户自己定义的别名
命令替换:
myfile的内容:
parm
findfile
#cat myfile
#ls `cat myfile` -al
后台处理:
-什么是后台?
-一个终端可以同时运行多个程序
-nohup command &

#nohup tar -czf enerco.tar.gz enerco &
#job -l  可以查看后台正在运行的程序
变量:

管道:
-把一个命令的输出连接到另一个命令的输入
-ls | sort
#ls -l | sort
#ls | sort

重定向():
-与管道相关,可以改变程序运行的输入来源和输出地点
-sort myfile_sort.txt
#vi myfile.txt
#sort myfile_sort.txt

模式匹配:
-显示以txt为扩展名的文件或显示以a开头的文件,这种能力就称为模式匹配
-正则表达式

特殊字符
-双引号("):用来使shell无法认出空格、制表符和其他大多数特殊字符,如
"David Medinets"表示一个值,而不是2个。同样"David &:表示重定向。
-* ? [] ! :表示模式匹配。
-$:变量名的开头。
-#:表示注释(第一行除外)。
-空格,制表符,换行符:当作空白。


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/97478/showart_1950081.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP