1 / 17

红帽企业 Linux 用户基础 RHA030

红帽企业 Linux 用户基础 RHA030. 6 单元. 使用 Bash Shell. 目标. 本单元你将学习到 : 使用命令行快捷 使用命令行扩展 使用历史和编辑技巧 使用 gnome-terminal 编写简单的 shell 脚本. 命令行快捷 - 文件通配符扩展. 通配符扩展 * – 匹配 0 或者多个字符 ? – 匹配任意单个字符 [0-9] – 匹配 0-9 范围内的数字 [abc] – 匹配该列表内的任意字符 [^abc] – 匹配除列表内字符外的所有字符 可以使用预定义的字符类. 命令行快捷 -TAB 键.

Download Presentation

红帽企业 Linux 用户基础 RHA030

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 红帽企业Linux用户基础RHA030

  2. 6单元 使用Bash Shell

  3. 目标 • 本单元你将学习到: • 使用命令行快捷 • 使用命令行扩展 • 使用历史和编辑技巧 • 使用gnome-terminal • 编写简单的shell脚本

  4. 命令行快捷-文件通配符扩展 通配符扩展 * – 匹配0或者多个字符 ? – 匹配任意单个字符 [0-9] – 匹配0-9范围内的数字 [abc] – 匹配该列表内的任意字符 [^abc] – 匹配除列表内字符外的所有字符 可以使用预定义的字符类

  5. 命令行快捷-TAB键 Tab键可用来帮助完成命令行的输入: 为命令名,它将完成命令名的输入 为参数,它将完成文件名的输入 示例 $ xte<Tab> $ xterm $ ls myf<Tab> $ ls myfile.txt

  6. 命令行快捷-历史 bash保存已经输入过的命令, 这些历史命令可以用来重复使用 使用history命令可以看到历史命令列表 $ history 14 cd /tmp 15 ls –l 16 cd 17 cp /etc/passwd 18 vi passwd ...输出截断...

  7. 其它的历史命令技巧 使用up和down键来翻阅以前的命令 按下Ctrl-r键从历史命令行中搜索命令(反向i搜索) 从先前的命令中重调上一个参数 Esc-. (Esc键后跟一点) Alt-. (当输入点的时候按住alt键) !$ (仅上一个命令才有效)

  8. 命令行扩展-波形符 波形符(~) 可指向你的主目录 $ cat ~/.bash_profile 也可指向其它用户的主目录 $ ls ~julie/public_html

  9. 命令行扩展-命令和大括号集 命令扩展:$()和`` 输出一个命令做为另外一个命令的参数 $ echo “This system’s name is $(hostname)” $ This system’s name is server1.example.com 大括号扩展 重复打印字符串 $ echo file{1,3,5} $ file1 file3 file5 $ rm –f file{1,3,5}

  10. Bash变量 变量是命名的值 用来存储数据或者命令输出 设置方式为:变量=值 引用方式为:$变量 $ HI=“Hello,and welcome to $(hostname).” $ echo $HI Hello,and welcome to stationX

  11. 命令编辑技巧 Ctrl-a:移动到行的开始位置 Ctrl-e:移动到行的最后位置 Ctrl-u:删除到行的开始位置 Ctrl-k:删除到行的最后位置 Ctrl-方向键:逐个字符移动到左边或者右边

  12. Gnome-terminal Application->Accessories->Terminal 图形终端仿真器支持多个标签式的shell Ctrl-Shift-t:创建一个新的标签 Ctrl-PgUp/PgDn:切换到下一个/前一个标签 Ctrl-Shift-c:拷贝选择的文本 Ctrl-Shift-v:粘贴文本到提示符 Shift-PgUp/PgDn:查看屏幕上下文

  13. 脚本基础 Shell脚本由许多命令或者待执行的语句组成的文本文件 Shell脚本的用途包括: 常用命令的自动化 执行系统管理和诊断工作 创建简单的应用程序 操作文本或者文件

  14. 创建Shell脚本 步骤1:创建一个包含命令的文本文件 第一行包含magic shebang序列:#! #!!/bin/bash 注释你的脚本 注释用#开始

  15. 创建Shell脚本-续 步骤2:让脚本可执行: $ chmod u+x myscript.sh 执行脚本 把脚本文件放置在一个可执行的路径的目录中或者在命令行指定这个脚本文件的绝对路径或者相对路径

  16. 简单的Shell脚本 #!/bin/bash #该脚本显示你系统环境的某些信息 echo “Greetings. The date and time are $(date)” echo “Your workding directory is:$(pwd)”

  17. 结束 问题和答案 摘要 命令扩展:$() 历史命令重调:!string,!num Shell脚本

More Related