《03linuxshell专题讲座-王保明》由会员分享,可在线阅读,更多相关《03linuxshell专题讲座-王保明(42页珍藏版)》请在金锄头文库上搜索。
1、LinuxShell 应用编程专题讲座written by 王保明第一部分 shell 编程基础1shell 简介什么是 shell存取权限和安全shell 简单脚本shell 特性1.1 什么是 shell shell 是核心程序 kernel 之外的指令解析器,是一个程序,同时是一种命令语言和程序设计语言。 shell 是命令解析器,用户输入命令,它去解析。 shell 类型 ash、bash、ksh、csh、tcsh cat /etc/shells 看系统下的 shell echo $SHELL 看当前用户运行的 shell 程序在 shell 中运行 ls 命令执行过程分析 shell
2、 中可以运行子 shell /bin/csh 退出子 shell linux 下默认的 shell 是 bash bash 特点,快速(上下键) ;tab 键盘自动补齐;自动帮助功能 help在 shell 下执行 help 命令,可以查看 shell 提供的命令testlocalhost $ help GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)These shell commands are defined internally. Type help to see this list.Type help name
3、 to find out more about the function name.Use info bash to find out more about the shell in general.Use man -k or info to find out more about commands not in this list.A star (*) next to a name means that the command is disabled.JOB_SPEC & ( expression ). filename arguments : arg. expression alias -
4、p name=value . bg job_spec . bind -lpvsPVS -m keymap -f fi break nbuiltin shell-builtin arg . caller EXPRcase WORD in PATTERN | PATTERN. cd -L|-P dircommand -pVv command arg . compgen -abcdefgjksuv -o optioncomplete -abcdefgjksuv -pr -o continue ndeclare -afFirtx -p name=val dirs -clpv +N -Ndisown -
5、h -ar jobspec . echo -neE arg .enable -pnds -a -f filename eval arg .exec -cl -a name file redirec exit nexport -nf name=value . or falsefc -e ename -nlr first last fg job_specfor NAME in WORDS . ; do COMMA for ( exp1; exp2; exp3 ); do COMfunction NAME COMMANDS ; or NA getopts optstring name arghash
6、 -lr -p pathname -dt na help -s pattern .history -c -d offset n or hi if COMMANDS; then COMMANDS; elifjobs -lnprs jobspec . or job kill -s sigspec | -n signum | -silet arg arg . local name=value .logout popd +N | -N -nprintf -v var format arguments pushd dir | +N | -N -npwd -LP read -ers -u fd -t ti
7、meout readonly -af name=value . return nselect NAME in WORDS . ; do CO set -abefhkmnptuvxBCHP -o optishift n shopt -pqsu -o long-option optsource filename arguments suspend -ftest expr time -p PIPELINEtimes trap -lp arg signal_spec .true type -afptP name name .typeset -afFirtx -p name=valu ulimit -S
8、Hacdfilmnpqstuvx limitumask -p -S mode unalias -a name name .unset -f -v name . until COMMANDS; do COMMANDS; donevariables - Some variable names an wait nwhile COMMANDS; do COMMANDS; done COMMANDS ; 1.2 存取权限与安全简介: 文件和目录的权限(-rwxr r-)setuid(suid/guid) (chmod u+s g+s file)chown 和 chgrp(chown user file/
9、chgrp group file)umask (umask nnn) (文件创建时的缺省权限位) 文件和目录的权限(-rwxr-r-) linux 下安全解决方案很多,现在讨论文件和目录的访问权限 练习 ls lh文件的权限 硬链接数 用户名用户组 文件大小、最近修改时间 文件名称drwxr-xr-x 2 test test 4096 Jun 23 08:07 cppsocket1drwxr-xr-x 8 test test 4096 Jun 23 08:08 cppsocket2drwxr-xr-x 9 test test 4096 Jun 18 12:32 gcc-rw-r-r- 1 te
10、st test 59827 Jun 23 08:11 gcc_mk_gdb.tar.gzdrwxr-xr-x 7 test test 4096 Jun 23 08:09 mkdrwxr-xr-x 4 test test 4096 Jun 23 09:47 mygccdrwxr-xr-x 5 test test 4096 Jun 23 11:13 mymk-rw-r-r- 1 root root 63 Nov 9 2013 oraInst.loc-rw-rw-r- 1 oracle oinstall 732 Nov 9 2013 oratabdrwxr-xr-x 2 root root 4096
11、 Nov 9 2013 pam.ddrwxr-xr-x 3 root root 4096 Nov 8 2013 racoonlrwxrwxrwx 1 root root 7 Nov 8 2013 rc - rc.d/rcdrwxr-xr-x 10 root root 4096 Nov 8 2013 rc.d硬链接数?d-目录 一般文件 l 快捷方式 c 字符设备 b 块设备 s-socket 设备文件 p 管道文件-rw-r-r- 1 root root 5 Jun 23 12:39 scim-bridge-0.3.0.lockfile-0localhost:0.0-rw-r-r- 1 ora
12、cle oinstall 5 Jun 18 16:13 scim-bridge-0.3.0.lockfile-501localhost:0.0srwxr-xr-x 1 root root 0 Jun 23 05:39 scim-bridge-0.3.0.socket-0localhost:0.0srwxr-xr-x 1 oracle oinstall 0 Jun 18 07:13 scim-bridge-0.3.0.socket-501localhost:0.0srw- 1 oracle oinstall 0 Jun 18 07:13 scim-helper-manager-socket-or
13、aclesrw- 1 root root 0 Jun 23 05:39 scim-helper-manager-socket-rootsrw- 1 oracle oinstall 0 Jun 18 07:13 scim-panel-socket:0-oraclesrw- 1 root root 0 Jun 23 05:39 scim-panel-socket:0-rootsrw- 1 oracle oinstall 0 Jun 18 07:13 scim-socket-frontend-oraclesrw- 1 root root 0 Jun 23 05:39 scim-socket-frontend-rootdrwx- 2 root root 4.0K Jun 23 05:39 ssh-grWlnX5288drwx- 2 oracle oinstall 4.0K Jun 18 07:13 virtual-oracle.26qtL1drwx- 2 root root 4.0K Jun 23 05:39 virtual-root.selw4Ptestlocalhost $ ls -l /tmp/.X11-unix/X0 srwxrwxrwx 1 root root 0 Jun 22 20:07 /tmp/.X11-unix/X0 这里