第一天 shell 简介 - 技术文档 - 程序开发 Linux时代
已有 222 次阅读2013-9-7 07:16
第一天 shell 简介 来源: ChinaUnix博客 日期:2007.03.20 18:00 (共有条评论)
N年前学习shell编程的笔记,粗劣了点!就当是个大纲了!
这几天有空拿出来看看,顺便就放到blog上了(比放我硬盘里安全*_*)!
大家有空来我的blog踩踩:
第一天 shell 简介
-什么是shell
-存取权限和安全
-shell简单脚本
-shell特性
-什么是shell
-shell是核心程序(kernel)之外的指令解析器,是一个程序,同时是一种命令语言和程序设计语言,guangzhou020.angelfire。
-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开头的命令
-存取权限与安全
-文件和名录的权限(-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
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 testfiles位涉及安全问题
#chmod g+x,o+x testfile
#chown root.antiy testfile
#ls -l
#chmod g+s testfile
#ls -l
#chmod o+t testfile
#ls -l
#ls -l /bin grep `"...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_pathtarget_path
-shell教本
-使用shell脚本的原因
功能强大,节约时间。
-shell脚本基本元素
#!/bin/bash
-第一行
#
-表示注释
变量
流程控制结构
例子:
helloworld.sh
#!/bin/bash
#输出一个hell world的shell
printchar="hello world"
echo $printchar
#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博客,如果查看原文请点: (共有条评论)