使用 Shell(bash)

  • View
    123

  • Download
    0

Embed Size (px)

DESCRIPTION

使用 Shell(bash). 刘西洋. 大纲. 1 控制台 1.1 Linux 控制台终端 1.2 终端模拟器 2 shell 有几种 3 使用 bash 4 bash 脚本编程 参见 《Redhat Linux 指南:服务器设置与程序设计篇 》 第 11 章, bash 程序设计。. 1 控制台. Linux 控制台终端 可以使用 Alt+[F1-F6] 组合键切换和英文终端。 Linux 终端模拟器 图形界面下的终端模拟器。比如, kde 的 konsole 程序和 gnome 的 gnome-terminal. 1.1 控制台终端. - PowerPoint PPT Presentation

Text of 使用 Shell(bash)

  • 1 1.1 Linux1.2 2 shell3 bash4 bashRedhat Linux11bash

  • 1 LinuxAlt+[F1-F6]Linuxkdekonsolegnomegnome-terminal

  • 1.1 /dev/ttyn, /dev/consoleLinux LinuxttyNtty1tty1tty6tty0Alt+[F1-F6]/dev/consoleps -ax

  • 1.2 konsolegnome-terminalXterm

  • 2 Shellsh Steve BourneAT&T Unix systemcshBill Joyberkeley Unix systembash Bourne Again ShellBrian Foxtcsh cshcshash shkenneth almquistnetbsdkshDavid KornUnix system V systems shellAIXshellzshshMac OS X

  • 3 BASH3.1 Bash 3.2 Bash 3.3 Bash 3.4 Bash 3.5 Bash

    3.6 Bash 3.7 Bash 3.8 Bash 3.9 Bash

  • 3.1 bash [root@hongli ~]# ls al -rw------- 1 root root 13650 Apr 2 15:29 .bash_history -rw-r--r-- 1 root root 24 Mar 10 18:35 .bash_logout -rw-r--r-- 1 root root 191 Mar 10 18:35 .bash_profile -rw-r--r-- 1 root root 176 Mar 10 18:35 .bashrccount2+/etc/bash_profile /etc/bashrc .bash_history .bash_logout clear .bash_profile bash.bashrc bash.bash_profile.bashrc /etc/skel skel skeleton , ( useradd ),/etc/skel ,home

  • 3.2 bash shell shell shell exportexportshellshell~/.bash_profiles

  • $HOME ~ [root@hongli ~]# echo ~ [root@hongli ~]# echo $HOME/root /root$SHELL shell[root@hongli ~]# echo $SHELL/bin/bash$PS1 shell[root@hongli ~]# echo $PS1[\u@\h \W]\$$PATH [root@hongli ~]# echo $PATH/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

  • 3.3 bashcd pwd test /bin/testset unset echo exit shellhistory type fg bg [linux@localhost ~]$ help[linux@localhost ~]$ man bash [linux@localhost ~]$ info bash

  • 3.4 BashCtrl+F Character forward .Ctrl+B Character backward .Alt+F Word forward Alt+B Word backward Ctrl+A Beginning of line Ctrl+E End of line Ctrl+L Clear screen Ctrl+D Delete current Backspace Delete previous Ctrl+T Transpose character

  • Alt+T Transpose words Alt+U Uppercase word Alt+L Lowercase word Alt+C Capitalize word Ctrl+V Insert special character tabCtrl+V+Tab.Ctrl+K Cut end of line Ctrl+U Cut beginning of line.Ctrl+WCut previous word .Alt+D Cut next word ..Ctrl+YPaste recent text Alt+Y Paste earlier text Ctrl+C Delete whole line

  • 3.5 bashlinux linuxPS1 PS2 PS3PS4PS1 PS2 PS3 shellPS4 shell

  • PS1\! bash_historynumber\#\$ root# $\W \[ \] \[ \\ \d \h .\n \s shell\t \u .\w http://hi.baidu.com/%C9%ED%B4%A6%BD%AD%BA%FE/blog/item/44855139a436b3d8d462254a.html

  • 3.6 bash!n numbern!! !?string? string 10 history 11 date 12 echo $SHELL 13 echo $PS1 14 data -h[honliv@hongli root]$ !?dat?data -hbash: data: command not found

  • 3.7 bash$(command)`command`[honliv@hongli ~]$ echo "there are $(ls -l /etc | grep ^dr | wc -l) diretcories in /etc."there are 99 diretcories in /etc.[honliv@hongli ~]$ echo "there are `ls -l /etc | grep ^dr | wc -l` diretcories in /etc."there are 99 diretcories in /etc.

  • 3.8 bashstdin0stdout1stderr2< >| Unix

  • /etc1[honliv@hongli ~]$ ls -l /etc > etc.txt[honliv@hongli ~]$ cat etc.txt | moretotal 3088-rw-r--r-- 1 root root 2518 Mar 21 20:35 DIR_COLORS-rw-r--r-- 1 root root 2420 Mar 21 20:35 DIR_COLORS.xtermdrwxr-xr-x 4 root root 4096 Mar 13 11:39 NetworkManager[honliv@hongli ~]$ grep ^dr etc.txt | wc -l992 [honliv@hongli ~]$ echo /etc > 1.txt[honliv@hongli ~]$ cat 1.txt/etc[honliv@hongli ~]$ ls -l `cat 1.txt` | grep ^dr | wc -l993 [honliv@hongli ~]$ ls -l /etc | grep ^dr | wc -l99

  • 3.9 bash bashjobsfgbgvictrl+z[root@hongli ~]# jobs[1]+ Stopped vi install.log[2] Stopped vi install.log.syslog[3]- Stopped vi upgrade.log+fg+-

  • %% %string stringstring%?string string%--

    1 bgfind /usr > /tmp/allusefiles1[root@hongli ~]# jobs[2] Stopped vi install.log.syslog[3]- Stopped vi upgrade.log[4]+ Stopped find /usr > /tmp/allusefiles1[root@hongli ~]# bg %4[4]+ find /usr > /tmp/allusefiles1 &[root@hongli ~]# jobs[2]- Stopped vi install.log.syslog[3]+ Stopped vi upgrade.log[4] Done find /usr > /tmp/allusefiles1

  • 2 [root@hongli ~]# jobs[1] Stopped find /usr > /tmp/allusefiles1[2] Stopped find /usr > /tmp/allu1sefiles[3]- Stopped find /usr > /tmp/allusefiles2[4]+ Stopped find /usr > /tmp/allusefiles3[root@hongli ~]# fg %find-bash: fg: find: ambiguous job spec [root@hongli ~]# fg %?3find /usr > /tmp/allusefiles3[root@hongli ~]# jobs[1] Stopped find /usr > /tmp/allusefiles1[2]- Stopped find /usr > /tmp/allu1sefiles[2]+ Stopped find /usr > /tmp/allusefiles2[root@hongli ~]# fg %?files3-bash: fg: %?files3: no such job[root@hongli ~]# fg %?files2find /usr > /tmp/allusefiles2[root@hongli ~]# fg %?u1sefind /usr > /tmp/allu1sefiles[root@hongli ~]# fg %findfind /usr > /tmp/allusefiles1

  • *