├── .gitattributes ├── .gitignore ├── 020-file-manage.md ├── 020-file-manage.rst ├── LinuxTools.epub ├── Makefile ├── README.md ├── _build ├── doctrees │ ├── der │ │ └── README.doctree │ ├── environment.pickle │ ├── helloworld.doctree │ └── index.doctree └── html │ ├── .buildinfo │ ├── _sources │ ├── der │ │ └── README.txt │ ├── helloworld.txt │ └── index.txt │ ├── _static │ ├── ajax-loader.gif │ ├── basic.css │ ├── comment-bright.png │ ├── comment-close.png │ ├── comment.png │ ├── doctools.js │ ├── down-pressed.png │ ├── down.png │ ├── file.png │ ├── jquery.js │ ├── minus.png │ ├── plus.png │ ├── pygments.css │ ├── searchtools.js │ ├── underscore.js │ ├── up-pressed.png │ ├── up.png │ └── websupport.js │ ├── der │ └── README.html │ ├── genindex.html │ ├── helloworld.html │ ├── index.html │ ├── objects.inv │ ├── search.html │ └── searchindex.js ├── _static ├── cover_linuxtools.jpg ├── cover_linuxtools.psd ├── cover_linuxtools_s.jpg ├── crontab_format.png ├── me115_com.jpg ├── sar1.png ├── sar2.png ├── sar3.png ├── sar4.png └── sar5.png ├── advance ├── 01_program_build.rst ├── 02_program_debug.rst ├── 03_optimization.rst └── index.rst ├── base ├── 01_use_man.rst ├── 02_file_manage.rst ├── 03_text_processing.rst ├── 04_disk.rst ├── 05_process_manage.rst ├── 06_monitor.rst ├── 07_network.rst ├── 08_user_manage.rst ├── 09_system_manage.rst ├── README.rst ├── crond introduce.rst ├── index.rst └── ref.rst ├── conf.py ├── crontab.md ├── crontab.rst ├── der-master.zip ├── der ├── README.rst ├── disqus.html ├── layout.html ├── static │ ├── 42qu.png │ ├── dialog-note.png │ ├── dialog-seealso.png │ ├── dialog-topic.png │ ├── dialog-warning.png │ ├── epub.css │ ├── footerbg.png │ ├── headerbg.png │ ├── ie6.css │ ├── me115_com.jpg │ ├── middlebg.png │ ├── pyramid.css_t │ └── transparent.gif └── theme.conf ├── helloworld.rst ├── index.rst ├── make.bat ├── md2rst.py ├── sphinx_rtd_theme-master.zip ├── sphinx_rtd_theme ├── __init__.py ├── breadcrumbs.html ├── disqus.html ├── footer.html ├── layout - 副本.html ├── layout.html ├── layout_old.html ├── search.html ├── searchbox.html ├── static │ ├── css │ │ ├── badge_only.css │ │ ├── font_lato_googleapi.css │ │ ├── pyramid.css │ │ ├── theme.css │ │ └── theme.css.bak_10.1 │ ├── dialog-note.png │ ├── dialog-seealso.png │ ├── dialog-topic.png │ ├── dialog-warning.png │ ├── epub.css │ ├── fonts │ │ ├── FontAwesome.otf │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.svg │ │ ├── fontawesome-webfont.ttf │ │ └── fontawesome-webfont.woff │ ├── footerbg.png │ ├── headerbg.png │ ├── ie6.css │ ├── js │ │ ├── embed.js │ │ ├── modernizr.min.js │ │ └── theme.js │ ├── me115_com.jpg │ ├── middlebg.png │ ├── pyramid.css_t │ └── transparent.gif ├── theme.conf └── versions.html ├── tool ├── crontab.rst ├── free.rst ├── gdb.rst ├── index.rst ├── iostat.rst ├── ipcs.rst ├── ldd.rst ├── lsof.rst ├── nm.rst ├── objdump.rst ├── ps.rst ├── pstack.rst ├── readelf.rst ├── sar.rst ├── scp.rst ├── size.rst ├── strace.rst ├── top.rst ├── vmstat.rst └── wget.rst ├── top.md └── top.rst /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | _build/ 6 | 7 | *.pydevproject 8 | .project 9 | .metadata 10 | bin/ 11 | tmp/ 12 | *.tmp 13 | *.bak 14 | *.swp 15 | *~.nib 16 | local.properties 17 | .classpath 18 | .settings/ 19 | .loadpath 20 | 21 | # External tool builders 22 | .externalToolBuilders/ 23 | 24 | # Locally stored "Eclipse launch configurations" 25 | *.launch 26 | 27 | # CDT-specific 28 | .cproject 29 | 30 | # PDT-specific 31 | .buildpath 32 | 33 | 34 | ################# 35 | ## Visual Studio 36 | ################# 37 | 38 | ## Ignore Visual Studio temporary files, build results, and 39 | ## files generated by popular Visual Studio add-ons. 40 | 41 | # User-specific files 42 | *.suo 43 | *.user 44 | *.sln.docstates 45 | 46 | # Build results 47 | 48 | [Dd]ebug/ 49 | [Rr]elease/ 50 | x64/ 51 | build/ 52 | [Bb]in/ 53 | [Oo]bj/ 54 | 55 | # MSTest test Results 56 | [Tt]est[Rr]esult*/ 57 | [Bb]uild[Ll]og.* 58 | 59 | *_i.c 60 | *_p.c 61 | *.ilk 62 | *.meta 63 | *.obj 64 | *.pch 65 | *.pdb 66 | *.pgc 67 | *.pgd 68 | *.rsp 69 | *.sbr 70 | *.tlb 71 | *.tli 72 | *.tlh 73 | *.tmp 74 | *.tmp_proj 75 | *.log 76 | *.vspscc 77 | *.vssscc 78 | .builds 79 | *.pidb 80 | *.log 81 | *.scc 82 | 83 | # Visual C++ cache files 84 | ipch/ 85 | *.aps 86 | *.ncb 87 | *.opensdf 88 | *.sdf 89 | *.cachefile 90 | 91 | # Visual Studio profiler 92 | *.psess 93 | *.vsp 94 | *.vspx 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | 103 | # TeamCity is a build add-in 104 | _TeamCity* 105 | 106 | # DotCover is a Code Coverage Tool 107 | *.dotCover 108 | 109 | # NCrunch 110 | *.ncrunch* 111 | .*crunch*.local.xml 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.Publish.xml 131 | *.pubxml 132 | 133 | # NuGet Packages Directory 134 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 135 | #packages/ 136 | 137 | # Windows Azure Build Output 138 | csx 139 | *.build.csdef 140 | 141 | # Windows Store app package directory 142 | AppPackages/ 143 | 144 | # Others 145 | sql/ 146 | *.Cache 147 | ClientBin/ 148 | [Ss]tyle[Cc]op.* 149 | ~$* 150 | *~ 151 | *.dbmdl 152 | *.[Pp]ublish.xml 153 | *.pfx 154 | *.publishsettings 155 | 156 | # RIA/Silverlight projects 157 | Generated_Code/ 158 | 159 | # Backup & report files from converting an old project file to a newer 160 | # Visual Studio version. Backup files are not needed, because we have git ;-) 161 | _UpgradeReport_Files/ 162 | Backup*/ 163 | UpgradeLog*.XML 164 | UpgradeLog*.htm 165 | 166 | # SQL Server files 167 | App_Data/*.mdf 168 | App_Data/*.ldf 169 | 170 | ############# 171 | ## Windows detritus 172 | ############# 173 | 174 | # Windows image file caches 175 | Thumbs.db 176 | ehthumbs.db 177 | 178 | # Folder config file 179 | Desktop.ini 180 | 181 | # Recycle Bin used on file shares 182 | $RECYCLE.BIN/ 183 | 184 | # Mac crap 185 | .DS_Store 186 | 187 | 188 | ############# 189 | ## Python 190 | ############# 191 | 192 | *.py[co] 193 | 194 | # Packages 195 | *.egg 196 | *.egg-info 197 | dist/ 198 | build/ 199 | eggs/ 200 | parts/ 201 | var/ 202 | sdist/ 203 | develop-eggs/ 204 | .installed.cfg 205 | 206 | # Installer logs 207 | pip-log.txt 208 | 209 | # Unit test / coverage reports 210 | .coverage 211 | .tox 212 | 213 | #Translations 214 | *.mo 215 | 216 | #Mr Developer 217 | .mr.developer.cfg 218 | -------------------------------------------------------------------------------- /020-file-manage.md: -------------------------------------------------------------------------------- 1 | # 文件及目录管理 2 | 文件管理不外乎文件或目录的创建、删除、查询、移动,有mkdir/rm/mv 3 | 4 | 文件查询是重点,用find来进行查询;find的参数丰富,也非常强大; 5 | 6 | 查看文件内容是个大的话题,文本的处理有太多的工具供我们使用,在本章中只是点到即止,后面会有专门的一章来介绍文本的处理工具; 7 | 8 | 有时候,需要给文件创建一个别名,我们需要用到ln,使用这个别名和使用原文件是相同的效果; 9 | 10 | ## 创建和删除 11 | 创建:mkdir 12 | 删除:rm 删除非空目录:rm -rf file目录 13 | 删除日志 14 | $rm *log 15 | 16 | 等价: $find ./ -name "*log" -exec rm {} \; 17 | 18 | 查看当前目录下文件个数 19 | $find ./ | wc -l 20 | 移动:mv 21 | 复制:cp 复制目录:cp -r 22 | eg:$cp -r source_dir dest_dir 23 | 24 | ## 目录切换 25 | 找到文件/目录位置:cd 26 | 切换到上一个工作目录: cd - 27 | 切换到home目录: cd or cd ~ 28 | $pwd 29 | 显示当前路径 30 | $cd path 31 | 更改当前工作路径为path 32 | 33 | ## 列出目录项 34 | 显示当前目录下的文件 ls 35 | 按时间排序,以列表的方式显示目录项 ls -lrt 36 | 以上这个命令用到的频率如此之高,以至于我们需要为它建立一个快捷命令方式: 37 | 在.bashrc 中设置命令别名: 38 | alias lsl='ls -lrt' 39 | alias lm='ls -al|more' 40 | 这样,使用lsl,就可以显示目录中的文件按照修改时间排序;以列表方式显示; 41 | 注:.bashrc 在/home/你的用户名/ 文件夹下,以隐藏文件的方式存储;可使用 ls -a 查看; 42 | 43 | ## 查找目录及文件 find/locate 44 | 搜寻文件或目录: 45 | $find ./ -name "core*" | xargs file 46 | 查找目标文件夹中是否有obj文件: 47 | $find ./ -name '*.o' 48 | 递归当前目录及子目录删除所有.o文件: 49 | $find ./ -name "*.o" -exec rm {} \; 50 | 51 | find是实时查找,如果需要更快的查询,可试试locate;locate会为文件系统建立索引数据库,如果有文件更新,需要定期执行更新命令来更新索引库; 52 | $locate string 53 | 寻找包含有string的路径 54 | $updatedb 55 | 与find不同,locate并不是实时查找。你需要更新数据库,以获得最新的文件索引信息。 56 | 57 | ## 查看文件内容 58 | 查看文件:cat vi head tail more 59 | $cat -n:显示时同时显示行号 60 | $ls -al |more:一页一页显示列表内容; 61 | $head - 10 **:只看前10行 62 | $head -1 filename 显示文件第一行 63 | $tail -5 filename 显示文件倒数第五行 64 | $diff file1 file2 查看两个文件间的差别 65 | $tail -f crawler.log 动态显示文本最新信息 66 | 67 | ## 查找文件内容 68 | egrep '03.1\/CO\/AE' TSF_STAT_111130.log.012 69 | egrep 'A_LSHA777:C' TSF_STAT_111130.log.035 > co.out2 70 | co.out35: egrep 'A_LSHA777:C' TSF_STAT_111130.log.035 > co.out35 71 | 72 | ## 文件与目录权限修改 73 | chown:改变文件的拥有者 74 | chmod:改变文件读、写、执行等属性 75 | 递归子目录修改: chown -R tuxapp source/ 76 | 增加脚本可执行权限: chmod a+x myscript 77 | 78 | 79 | ## 给文件增加别名 80 | 创建符号链接/硬链接: 81 | ln cc ccAgain :硬连接;删除一个,将仍能找到; 82 | ln -s cc ccTo :符号链接(软链接);删除源,另一个无法使用;(后面一个ccTo 为新建的文件) 83 | 84 | 85 | ## 管道和重定向 86 | 批处理命令连接执行: 87 | 串联: 使用分号 ; 88 | 前面成功,则执行后面一条,否则,不执行:&& 89 | 前面失败,则后一条执行: || 90 | eg: 91 | ls /proc && echo suss! || echo failed. 92 | 能够提示命名是否执行成功or失败; 93 | 与上述相同效果的是: 94 | if ls /proc; then echo suss; else echo fail; fi 95 | 重定向: 96 | ls proc/*.c > list > &l 将结果输出到list,将错误输出到同一个文件末尾; 97 | 等价的是:ls proc/*.c &> list 98 | ls list1 list2:可同时列出多个文件; 99 | 100 | 清空文件: :> a.txt 101 | 重定向:最佳文本: echo aa >> a.txt 102 | 103 | ## 设置环境变量 104 | 启动帐号后自动执行的是 文件为 .profile,然后通过这个文件可设置自己的环境变量; 105 | 安装的软件路径一般需要加入到path中: 106 | PATH=$APPDIR:/opt/app/soft/bin:$PATH:/usr/local/bin:$TUXDIR/bin:$ORACLE_HOME/bin;export PATH 107 | 108 | ## Bash快捷输入或删除 109 | 快捷键: 110 | Ctl-U 删除光标到行首的所有字符,在某些设置下,删除全行 111 | Ctl-W 删除当前光标到前边的最近一个空格之间的字符 112 | Ctl-H backspace,删除光标前边的字符 113 | Ctl-R: 匹配最相近的一个文件,然后输出 114 | 115 | ## 综合应用 116 | cat -v record.log | grep AAA |grep -v BBB |wc -l 117 | 查找record.log中包含AAA,但不包含BBB的记录的总数 118 | 119 | ## 总结 120 | 文件管理,目录的创建、删除、查询、管理: mkdir rm mv 121 | 文件的查询和检索: find locate 122 | 查看文件内容:cat vi tail more 123 | 管道和重定向: ; | && > 124 | 125 | 126 | 127 | Posted by: 大CC | 26MAY,2014 128 | 博客:[blog.me115.com](http://blog.me115.com) 129 | 微博:[新浪微博](http://weibo.com/bigcc115) -------------------------------------------------------------------------------- /020-file-manage.rst: -------------------------------------------------------------------------------- 1 | 文件及目录管理 2 | ========================== 3 | 文件管理不外乎文件或目录的创建、删除、查询、移动,有mkdir/rm/mv 4 | 5 | 文件查询是重点,用find来进行查询;find的参数丰富,也非常强大; 6 | 7 | 查看文件内容是个大的话题,文本的处理有太多的工具供我们使用,在本章中只是点到即止,后面会有专门的一章来介绍文本的处理工具; 8 | 9 | 有时候,需要给文件创建一个别名,我们需要用到ln,使用这个别名和使用原文件是相同的效果; 10 | 11 | 创建和删除 12 | -------------------- 13 | 创建:mkdir 14 | 删除:rm 删除非空目录:rm -rf file目录 15 | 删除日志 16 | $rm *log 17 | 18 | 等价: $find ./ -name "*log" -exec rm {} \; 19 | 20 | 查看当前目录下文件个数 21 | $find ./ | wc -l 22 | 移动:mv 23 | 复制:cp 复制目录:cp -r 24 | eg:$cp -r source_dir dest_dir 25 | 26 | 目录切换 27 | ------------------- 28 | 找到文件/目录位置:cd 29 | 切换到上一个工作目录: cd - 30 | 切换到home目录: cd or cd ~ 31 | $pwd 32 | 显示当前路径 33 | $cd path 34 | 更改当前工作路径为path 35 | 36 | 列出目录项 37 | -------------------- 38 | 显示当前目录下的文件 ls 39 | 按时间排序,以列表的方式显示目录项 ls -lrt 40 | 以上这个命令用到的频率如此之高,以至于我们需要为它建立一个快捷命令方式: 41 | 在.bashrc 中设置命令别名: 42 | alias lsl='ls -lrt' 43 | alias lm='ls -al|more' 44 | 这样,使用lsl,就可以显示目录中的文件按照修改时间排序;以列表方式显示; 45 | 注:.bashrc 在/home/你的用户名/ 文件夹下,以隐藏文件的方式存储;可使用 ls -a 查看; 46 | 47 | 查找目录及文件 find/locate 48 | ---------------------------------------- 49 | 搜寻文件或目录: 50 | $find ./ -name "core*" | xargs file 51 | 查找目标文件夹中是否有obj文件: 52 | $find ./ -name '*.o' 53 | 递归当前目录及子目录删除所有.o文件: 54 | $find ./ -name "*.o" -exec rm {} \; 55 | 56 | find是实时查找,如果需要更快的查询,可试试locate;locate会为文件系统建立索引数据库,如果有文件更新,需要定期执行更新命令来更新索引库; 57 | $locate string 58 | 寻找包含有string的路径 59 | $updatedb 60 | 与find不同,locate并不是实时查找。你需要更新数据库,以获得最新的文件索引信息。 61 | 62 | 查看文件内容 63 | ----------------------- 64 | 查看文件:cat vi head tail more 65 | $cat -n:显示时同时显示行号 66 | $ls -al |more:一页一页显示列表内容; 67 | $head - 10 **:只看前10行 68 | $head -1 filename 显示文件第一行 69 | $tail -5 filename 显示文件倒数第五行 70 | $diff file1 file2 查看两个文件间的差别 71 | $tail -f crawler.log 动态显示文本最新信息 72 | 73 | 查找文件内容 74 | ----------------------- 75 | egrep '03.1\/CO\/AE' TSF_STAT_111130.log.012 76 | egrep 'A_LSHA777:C' TSF_STAT_111130.log.035 > co.out2 77 | co.out35: egrep 'A_LSHA777:C' TSF_STAT_111130.log.035 > co.out35 78 | 79 | 文件与目录权限修改 80 | -------------------------------- 81 | chown:改变文件的拥有者 82 | chmod:改变文件读、写、执行等属性 83 | 递归子目录修改: chown -R tuxapp source/ 84 | 增加脚本可执行权限: chmod a+x myscript 85 | 86 | 87 | 给文件增加别名 88 | -------------------------- 89 | 创建符号链接/硬链接: 90 | ln cc ccAgain :硬连接;删除一个,将仍能找到; 91 | ln -s cc ccTo :符号链接(软链接);删除源,另一个无法使用;(后面一个ccTo 为新建的文件) 92 | 93 | 94 | 管道和重定向 95 | ----------------------- 96 | 批处理命令连接执行: 97 | 串联: 使用分号 ; 98 | 前面成功,则执行后面一条,否则,不执行:&& 99 | 前面失败,则后一条执行: || 100 | eg: 101 | ls /proc && echo suss! || echo failed. 102 | 能够提示命名是否执行成功or失败; 103 | 与上述相同效果的是: 104 | if ls /proc; then echo suss; else echo fail; fi 105 | 重定向: 106 | ls proc/*.c > list > &l 将结果输出到list,将错误输出到同一个文件末尾; 107 | 等价的是:ls proc/*.c &> list 108 | ls list1 list2:可同时列出多个文件; 109 | 110 | 清空文件: :> a.txt 111 | 重定向:最佳文本: echo aa >> a.txt 112 | 113 | 设置环境变量 114 | ----------------------- 115 | 启动帐号后自动执行的是 文件为 .profile,然后通过这个文件可设置自己的环境变量; 116 | 安装的软件路径一般需要加入到path中: 117 | PATH=$APPDIR:/opt/app/soft/bin:$PATH:/usr/local/bin:$TUXDIR/bin:$ORACLE_HOME/bin;export PATH 118 | 119 | Bash快捷输入或删除 120 | ------------------------------ 121 | 快捷键: 122 | Ctl-U 删除光标到行首的所有字符,在某些设置下,删除全行 123 | Ctl-W 删除当前光标到前边的最近一个空格之间的字符 124 | Ctl-H backspace,删除光标前边的字符 125 | Ctl-R: 匹配最相近的一个文件,然后输出 126 | 127 | 综合应用 128 | ----------------- 129 | cat -v record.log | grep AAA | grep -v BBB | wc -l 130 | 查找record.log中包含AAA,但不包含BBB的记录的总数 131 | 132 | 总结 133 | ----------- 134 | 文件管理,目录的创建、删除、查询、管理: mkdir rm mv 135 | 文件的查询和检索: find locate 136 | 查看文件内容:cat vi tail more 137 | 管道和重定向: ; | && > 138 | 139 | 140 | 141 | Posted by: 大CC | 26MAY,2014 142 | 博客:[blog.me115.com](http://blog.me115.com) 143 | 微博:[新浪微博](http://weibo.com/bigcc115) 144 | -------------------------------------------------------------------------------- /LinuxTools.epub: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/LinuxTools.epub -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/linuxtools.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/linuxtools.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/linuxtools" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/linuxtools" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # linux_tools 2 | ============== 3 | 4 | Linux下有很多命令行工具供我们使用,每个工具总是提供了大量参数供我们选择; 实际工作中,我们用到的工具,最常用的总是那么几个参数组合; 为此,我写了这本书相对实用的书; 5 | 6 | 这本书专注于Linux工具的最常用用法,以便读者能以最快时间掌握,并在工作中应用; 7 | 8 | ## 说明 9 | 10 | 全书分为三个部分: 11 | 12 | 1. 第一部分为基础篇,介绍我们工作中常用的工具的高频用法; 13 | 2. 第二部分为进阶篇,介绍的工具更多的适合程序员使用,分为程序构建、程序调试及程序优化; 14 | 3. 第三部分是工具参考篇,主要介绍实用工具的用法和实例;相比第一二部分,这里针对每个工具的介绍更全面; 15 | 16 | 同时,这个教程也可当作Linux命令手册使用,使用左边栏的目录和搜索栏可以很方便的查阅; 17 | 18 | ## 写作方式 19 | 20 | 我将会遵循以下写作方式: 21 | 22 | 1. 首先介绍工具的使用范围; 23 | 2. 工具的快速上手教程;包含最常用的范例和最常用的选项; 24 | 3. 使用场景(例子)说明; 25 | 4. 更完整的命令参数说明; 26 | 5. 进阶 27 | 28 | ## 建议 29 | 1. 最好安装一个Linux系统(对于新手Ubuntu容易入门),将教程中的命令敲到bash中看看效果 30 | 2. 如果有兴趣,可以在了解之后立即查看相关更完备的内容 (比如查阅官方文档) 31 | 32 | ## 写作工具 33 | 本书使用的reStructuredText标记语言,相对Markdown来说,在写书方面更有优势: 34 | 35 | 1. 使用Sphinx能够自动生成目录和索引文件,方便查询和检索; 36 | 2. 有大量漂亮的HTML书籍主题模版,可为书籍轻松换肤(类似Wordpress的网站模版); 37 | 3. 对于参考手册类书籍的编写在语法上更为便利(python官方帮助文档的使用者); 38 | 39 | ## 在线阅读 40 | 在线阅读地址:[http://linuxtools-rst.readthedocs.org/zh_CN/latest/](http://linuxtools-rst.readthedocs.org/zh_CN/latest/) 41 | 42 | ## 版权声明 43 | 本书为开源图书,版权归作者所有;欢迎下载及编辑(个人用途),但未经作者同意必须保留此段声明,且不可用于商业用途,否则保留追究法律责任的权利。 44 | 45 | - 作者:大CC 46 | - 博客:http://blog.me115.com 47 | - Github地址:https://github.com/me115/linuxtools_rst 48 | 49 | -------------------------------------------------------------------------------- /_build/doctrees/der/README.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/doctrees/der/README.doctree -------------------------------------------------------------------------------- /_build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/doctrees/environment.pickle -------------------------------------------------------------------------------- /_build/doctrees/helloworld.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/doctrees/helloworld.doctree -------------------------------------------------------------------------------- /_build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/doctrees/index.doctree -------------------------------------------------------------------------------- /_build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: 2a75e1c0a5b4f6628aa6a97984f2ab67 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /_build/html/_sources/der/README.txt: -------------------------------------------------------------------------------- 1 | DER 2 | ===================== 3 | 4 | ``DER == reverse("RED")`` 5 | 6 | 本项目是 `《Redis 设计与实现》 `_ 所使用的 Sphinx 样式。 7 | 8 | 样式特点: 9 | 10 | - 单色调简单风格(默认为红色,但很容易就可以修改成其他颜色) 11 | 12 | - 醒目的 ``h1`` 标题 13 | 14 | - 清晰的、可以高效地对文本进行视线分割的 ``h2`` 标题 15 | 16 | - 固定大小、居中显示、百分比字体大小,布局健壮,适用于多种不同的屏幕环境 17 | 18 | 19 | 使用方法 20 | --------------------- 21 | 22 | 1. 克隆本项目。 23 | 24 | 2. 修改 sphinx 项目 ``conf.py`` 文件中的 ``html_theme_path`` 变量,让它指向 ``der`` 文件夹所在的位置。 25 | 26 | 3. 修改 sphinx 项目 ``conf.py`` 文件中的 ``html_theme`` 变量的值为 ``der`` 。 27 | 28 | 4. 完成! 29 | 30 | 31 | 开启 disqus 支持 32 | --------------------- 33 | 34 | 1. 编辑 ``der`` 文件夹中的 ``layout.html`` 文件,修改文件中和 disqus 有关的语句: 35 | 36 | :: 37 | 38 | {# note: remove this comment if you want to enable disqus support 39 | 40 | {% include "disqus.html" %} 41 | 42 | #} 43 | 44 | 只保留这一句: 45 | 46 | :: 47 | 48 | {% include "disqus.html" %} 49 | 50 | 2. 编辑 ``der`` 文件夹中的 ``disqus.html`` 文件,将其中的 51 | 52 | :: 53 | 54 | var disqus_shortname = 'YOUR-DISQUS-FORUM-SHORTNAME'; 55 | 56 | 中的 ``YOUR-DISQUS-FORUM-SHORTNAME`` 替换成你的 disqus 论坛的名字。 57 | 58 | 3. 完成! 59 | 60 | 61 | 使用许可 62 | --------------------- 63 | 64 | 本样式修改自 `Sphinx `_ 项目自带的 pyramid 样式, 65 | 使用与源项目同样的 BSD 协议发布。 66 | 67 | | Copyright (c) 2013, huangz 68 | | All rights reserved. 69 | 70 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 71 | 72 | - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 73 | 74 | - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 75 | 76 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 77 | -------------------------------------------------------------------------------- /_build/html/_sources/index.txt: -------------------------------------------------------------------------------- 1 | ========== 2 | Linux工具快速教程 3 | ========== 4 | 5 | .. include:: _version.inc 6 | 7 | 前言 8 | ---- 9 | 10 | Linux下有很多命令行工具供我们使用,每个工具总是提供了大量参数供我们选择; 11 | 实际工作中,我们用到的工具,最常用的总是那么几个参数组合; 12 | 为此,我写了这本书相对实用的书; 13 | 14 | 这本书专注于Linux工具的最常用用法,以便读者能以最快时间掌握,并在工作中应用; 15 | 16 | 说明 17 | ^^^^^^^^^^^^^^^^^^^^ 18 | 19 | 全书分为三个部分: 20 | 21 | - 第一部分为基础篇,介绍我们工作中常用的工具的高频用法; 22 | - 第二部分为进阶篇,介绍的工具更多的适合程序员使用,分为程序构建、程序调试及程序优化; 23 | - 第三部分是工具参考篇,主要介绍实用工具的用法和实例;相比第一二部分,这里针对每个工具的介绍更全面; 24 | 25 | 同时,这个教程也可当作Linux命令手册使用,使用左边栏的目录和搜索栏可以很方便的查阅; 26 | 27 | 28 | 建议 29 | ^^^^^^^^^^^^^^^^^^^^ 30 | 1. 最好安装一个Linux系统(对于新手Ubuntu容易入门),将教程中的命令敲到bash中看看效果 31 | 2. 如果有兴趣,可以在了解之后立即查看相关更完备的内容 (比如查阅官方文档) 32 | 33 | 写作工具 34 | ^^^^^^^^^^^^^^^^^^^^ 35 | 本书使用的reStructuredText标记语言,相对Markdown来说,在写书方面更有优势: 36 | 37 | - 使用sphnix能够自动生成目录和索引文件,方便查询和检索; 38 | - 有大量漂亮的HTML书籍主题模版,可为书籍轻松换肤(类似Wordpress的网站模版); 39 | - 对于参考手册类书籍的编写在语法上更为便利(python官方帮助文档的使用者); 40 | 41 | 42 | 43 | ^^^^^^^^^^^^^^^^^^^^ 44 | 45 | 版权声明 46 | ^^^^^^^^^^^^^^^^^^^^^ 47 | .. note:: 48 | 本书为开源图书,版权归作者所有;欢迎下载及编辑(个人用途),但未经作者同意必须保留此段声明,且不可用于商业用途,否则保留追究法律责任的权利。 49 | 50 | - 作者:大CC 51 | - 博客:http://blog.me115.com 52 | - Github地址:https://github.com/me115/linuxtools_rst 53 | 54 | 55 | 目录 56 | ---- 57 | 58 | .. toctree:: 59 | :maxdepth: 2 60 | :glob: 61 | 62 | base/index 63 | advance/index 64 | tool/index 65 | 66 | 67 | Indices and tables 68 | ================== 69 | 70 | * :ref:`genindex` 71 | * :ref:`modindex` 72 | * :ref:`search` 73 | 74 | -------------------------------------------------------------------------------- /_build/html/_static/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/html/_static/ajax-loader.gif -------------------------------------------------------------------------------- /_build/html/_static/comment-bright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/html/_static/comment-bright.png -------------------------------------------------------------------------------- /_build/html/_static/comment-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/html/_static/comment-close.png -------------------------------------------------------------------------------- /_build/html/_static/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/html/_static/comment.png -------------------------------------------------------------------------------- /_build/html/_static/down-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/html/_static/down-pressed.png -------------------------------------------------------------------------------- /_build/html/_static/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/html/_static/down.png -------------------------------------------------------------------------------- /_build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/html/_static/file.png -------------------------------------------------------------------------------- /_build/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/html/_static/minus.png -------------------------------------------------------------------------------- /_build/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/html/_static/plus.png -------------------------------------------------------------------------------- /_build/html/_static/pygments.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #eeffcc; } 3 | .highlight .c { color: #408090; font-style: italic } /* Comment */ 4 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 5 | .highlight .k { color: #007020; font-weight: bold } /* Keyword */ 6 | .highlight .o { color: #666666 } /* Operator */ 7 | .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */ 8 | .highlight .cp { color: #007020 } /* Comment.Preproc */ 9 | .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */ 10 | .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ 11 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 12 | .highlight .ge { font-style: italic } /* Generic.Emph */ 13 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 14 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 15 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 16 | .highlight .go { color: #333333 } /* Generic.Output */ 17 | .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ 18 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 19 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 20 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 21 | .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ 22 | .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ 23 | .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ 24 | .highlight .kp { color: #007020 } /* Keyword.Pseudo */ 25 | .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ 26 | .highlight .kt { color: #902000 } /* Keyword.Type */ 27 | .highlight .m { color: #208050 } /* Literal.Number */ 28 | .highlight .s { color: #4070a0 } /* Literal.String */ 29 | .highlight .na { color: #4070a0 } /* Name.Attribute */ 30 | .highlight .nb { color: #007020 } /* Name.Builtin */ 31 | .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ 32 | .highlight .no { color: #60add5 } /* Name.Constant */ 33 | .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ 34 | .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ 35 | .highlight .ne { color: #007020 } /* Name.Exception */ 36 | .highlight .nf { color: #06287e } /* Name.Function */ 37 | .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ 38 | .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ 39 | .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ 40 | .highlight .nv { color: #bb60d5 } /* Name.Variable */ 41 | .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ 42 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 43 | .highlight .mf { color: #208050 } /* Literal.Number.Float */ 44 | .highlight .mh { color: #208050 } /* Literal.Number.Hex */ 45 | .highlight .mi { color: #208050 } /* Literal.Number.Integer */ 46 | .highlight .mo { color: #208050 } /* Literal.Number.Oct */ 47 | .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ 48 | .highlight .sc { color: #4070a0 } /* Literal.String.Char */ 49 | .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ 50 | .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ 51 | .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ 52 | .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ 53 | .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ 54 | .highlight .sx { color: #c65d09 } /* Literal.String.Other */ 55 | .highlight .sr { color: #235388 } /* Literal.String.Regex */ 56 | .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ 57 | .highlight .ss { color: #517918 } /* Literal.String.Symbol */ 58 | .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ 59 | .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ 60 | .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ 61 | .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ 62 | .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /_build/html/_static/up-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/html/_static/up-pressed.png -------------------------------------------------------------------------------- /_build/html/_static/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/html/_static/up.png -------------------------------------------------------------------------------- /_build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_build/html/objects.inv -------------------------------------------------------------------------------- /_static/cover_linuxtools.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_static/cover_linuxtools.jpg -------------------------------------------------------------------------------- /_static/cover_linuxtools.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_static/cover_linuxtools.psd -------------------------------------------------------------------------------- /_static/cover_linuxtools_s.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_static/cover_linuxtools_s.jpg -------------------------------------------------------------------------------- /_static/crontab_format.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_static/crontab_format.png -------------------------------------------------------------------------------- /_static/me115_com.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_static/me115_com.jpg -------------------------------------------------------------------------------- /_static/sar1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_static/sar1.png -------------------------------------------------------------------------------- /_static/sar2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_static/sar2.png -------------------------------------------------------------------------------- /_static/sar3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_static/sar3.png -------------------------------------------------------------------------------- /_static/sar4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_static/sar4.png -------------------------------------------------------------------------------- /_static/sar5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/_static/sar5.png -------------------------------------------------------------------------------- /advance/01_program_build.rst: -------------------------------------------------------------------------------- 1 | .. _01_program_build: 2 | 3 | 程序构建 4 | =========== 5 | 6 | .. contents:: 目录 7 | 8 | 一般源代码提供的程序安装需要通过配置、编译、安装三个步骤; 9 | 10 | 1. 配置做的工作主要是检查当前环境是否满足要安装软件的依赖关系,以及设置程序安装所需要的初始化信息,比如安装路径,需要安装哪些组件;配置完成,会生成makefile文件供第二步make使用; 11 | #. 编译是对源文件进行编译链接生成可执行程序; 12 | #. 安装做的工作就简单多了,就是将生成的可执行文件拷贝到配置时设置的初始路径下; 13 | 14 | 配置 15 | -------------------- 16 | 查询可用的配置选项:: 17 | 18 | ./configure --help 19 | 20 | 配置路径:: 21 | 22 | ./configure --prefix=/usr/local/snmp 23 | --prefix是配置使用的最常用选项,设置程序安装的路径; 24 | 25 | 编译 26 | --------------------- 27 | 编译使用make编译:: 28 | 29 | make -f myMakefile 30 | 通过-f选项显示指定需要编译的makefile;如果待使用makefile文件在当前路径,且文件名为以下几个,则不用显示指定: 31 | 32 | makefile Makefile 33 | 34 | 35 | makefile编写的要点 36 | ^^^^^^^^^^^^^^^^^^^^ 37 | - 必须满足第一条规则,满足后停止 38 | - 除第一条规则,其他无顺序 39 | 40 | makefile中的全局自变量 41 | ^^^^^^^^^^^^^^^^^^^^^^ 42 | - $@目标文件名 43 | - @^所有前提名,除副本 44 | - @+所有前提名,含副本 45 | - @<一个前提名 46 | - @?所有新于目标文件的前提名 47 | - @*目标文件的基名称 48 | 49 | 50 | .. note:: 51 | 52 | 系统学习makefile的书写规则,请参考 跟我一起学makefile [#]_ 53 | 54 | 更多选择 CMake 55 | ^^^^^^^^^^^^ 56 | CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程)。他能够输出各种各样的makefile或者project文件。使用CMake,能够使程序员从复杂的编译连接过程中解脱出来。它使用一个名为 CMakeLists.txt 的文件来描述构建过程,可以生成标准的构建文件,如 Unix/Linux 的 Makefile 或Windows Visual C++ 的 projects/workspaces 。 57 | 58 | 编译依赖的库 59 | ^^^^^^^^^^^^^^^^^^^^ 60 | makefile编译过程中所依赖的非标准库和头文件路径需要显示指明:: 61 | 62 | CPPFLAGS -I标记非标准头文件存放路径 63 | LDFLAGS -L标记非标准库存放路径 64 | 65 | 如果CPPFLAGS和LDFLAGS已在用户环境变量中设置并且导出(使用export关键字),就不用再显示指定; 66 | 67 | :: 68 | 69 | make -f myMakefile LDFLAGS='-L/var/xxx/lib -L/opt/mysql/lib' 70 | CPPFLAGS='-I/usr/local/libcom/include -I/usr/local/libpng/include' 71 | 72 | .. caution:: 73 | 74 | 链接多库时,多个库之间如果有依赖,需要注意书写的顺序,右边是左边的前提; 75 | 76 | g++编译 77 | ^^^^^^^^^^^^^^^^^^^^ 78 | :: 79 | 80 | g++ -o unixApp unixApp.o a.o b.o 81 | 选项说明: 82 | 83 | - -o:指明生成的目标文件 84 | - -g:添加调试信息 85 | - -E: 查看中间文件 86 | 87 | 应用:查询宏展开的中间文件: 88 | 89 | 在g++的编译选项中,添加 -E选项,然后去掉-o选项 ,重定向到一个文件中即可:: 90 | 91 | g++ -g -E unixApp.cpp -I/opt/app/source > midfile 92 | 93 | 94 | 查询应用程序需要链接的库:: 95 | 96 | $ldd myprogrammer 97 | libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00000039a7e00000) 98 | libm.so.6 => /lib64/libm.so.6 (0x0000003996400000) 99 | libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00000039a5600000) 100 | libc.so.6 => /lib64/libc.so.6 (0x0000003995800000) 101 | /lib64/ld-linux-x86-64.so.2 (0x0000003995400000) 102 | 103 | .. note:: 104 | 105 | 关于ldd的使用细节,参见 :ref:`ldd` 106 | 107 | 安装 108 | -------------------- 109 | 安装做的工作就简单多了,就是将生成的可执行文件拷贝到配置时设置的初始路径下:: 110 | 111 | $make install 112 | 其实 **install** 就是makefile中的一个规则,打开makefile文件后可以查看程序安装的所做的工作; 113 | 114 | 总结 115 | ---------------------------------------------------- 116 | configure make install g++ 117 | 118 | 119 | .. [#] 陈皓 跟我一起写Makefile http://scc.qibebt.cas.cn/docs/linux/base/%B8%FA%CE%D2%D2%BB%C6%F0%D0%B4Makefile-%B3%C2%F0%A9.pdf 120 | -------------------------------------------------------------------------------- /advance/03_optimization.rst: -------------------------------------------------------------------------------- 1 | .. _03_optimization: 2 | 3 | 性能优化 4 | ================= 5 | 6 | .. contents:: 目录 7 | 8 | 性能优化的核心是找出系统的瓶颈点,问题找到了,优化的工作也就完成了大半; 9 | 这里介绍的性能优化主要从两个层面来介绍:系统层面和程序层面; 10 | 11 | 分析系统瓶颈 12 | -------------------- 13 | 系统响应变慢,首先得定位大致的问题出在哪里,是IO瓶颈、CPU瓶颈、内存瓶颈还是程序导致的系统问题; 14 | 15 | 使用top工具能够比较全面的查看我们关注的点:: 16 | 17 | $top 18 | top - 09:14:56 up 264 days, 20:56, 1 user, load average: 0.02, 0.04, 0.00 19 | Tasks: 87 total, 1 running, 86 sleeping, 0 stopped, 0 zombie 20 | Cpu(s): 0.0%us, 0.2%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.2%st 21 | Mem: 377672k total, 322332k used, 55340k free, 32592k buffers 22 | Swap: 397308k total, 67192k used, 330116k free, 71900k cached 23 | PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 24 | 1 root 20 0 2856 656 388 S 0.0 0.2 0:49.40 init 25 | 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 26 | 3 root 20 0 0 0 0 S 0.0 0.0 7:15.20 ksoftirqd/0 27 | 4 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/ 28 | 29 | 进入交互模式后: 30 | - 输入M,进程列表按内存使用大小降序排序,便于我们观察最大内存使用者使用有问题(检测内存泄漏问题); 31 | - 输入P,进程列表按CPU使用大小降序排序,便于我们观察最耗CPU资源的使用者是否有问题; 32 | 33 | top第三行显示当前系统的,其中有两个值很关键: 34 | - %id:空闲CPU时间百分比,如果这个值过低,表明系统CPU存在瓶颈; 35 | - %wa:等待I/O的CPU时间百分比,如果这个值过高,表明IO存在瓶颈; 36 | 37 | 分析内存瓶颈 38 | -------------------- 39 | 查看内存是否存在瓶颈,使用top指令看比较麻烦,而free命令更为直观:: 40 | 41 | [/home/weber#]free 42 | total used free shared buffers cached 43 | Mem: 501820 452028 49792 37064 5056 136732 44 | -/+ buffers/cache: 310240 191580 45 | Swap: 0 0 0 46 | [/home/weber#]top 47 | top - 17:52:17 up 42 days, 7:10, 1 user, load average: 0.02, 0.02, 0.05 48 | Tasks: 80 total, 1 running, 79 sleeping, 0 stopped, 0 zombie 49 | %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st 50 | KiB Mem: 501820 total, 452548 used, 49272 free, 5144 buffers 51 | KiB Swap: 0 total, 0 used, 0 free. 136988 cached Mem 52 | 53 | top工具显示了free工具的第一行所有信息,但真实可用的内存,还需要自己计算才知道; 54 | 系统实际可用的内存为free工具输出第二行的free+buffer+cached;也就是第三行的free值191580;关于free命令各个值的详情解读,请参考这篇文章 :ref:`free` ; 55 | 56 | 如果是因为缺少内存,系统响应变慢很明显,因为这使得系统不停的做换入换出的工作; 57 | 58 | 进一步的监视内存使用情况,可使用vmstat工具,实时动态监视操作系统的内存和虚拟内存的动态变化。 59 | 参考: :ref:`vmstat` ; 60 | 61 | 分析IO瓶颈 62 | -------------------- 63 | 如果IO存在性能瓶颈,top工具中的%wa会偏高; 64 | 65 | 进一步分析使用iostat工具:: 66 | 67 | /root$iostat -d -x -k 1 1 68 | Linux 2.6.32-279.el6.x86_64 (colin) 07/16/2014 _x86_64_ (4 CPU) 69 | 70 | Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await svctm %util 71 | sda 0.02 7.25 0.04 1.90 0.74 35.47 37.15 0.04 19.13 5.58 1.09 72 | dm-0 0.00 0.00 0.04 3.05 0.28 12.18 8.07 0.65 209.01 1.11 0.34 73 | dm-1 0.00 0.00 0.02 5.82 0.46 23.26 8.13 0.43 74.33 1.30 0.76 74 | dm-2 0.00 0.00 0.00 0.01 0.00 0.02 8.00 0.00 5.41 3.28 0.00 75 | 76 | - 如果%iowait的值过高,表示硬盘存在I/O瓶颈。 77 | - 如果 %util 接近 100%,说明产生的I/O请求太多,I/O系统已经满负荷,该磁盘可能存在瓶颈。 78 | - 如果 svctm 比较接近 await,说明 I/O 几乎没有等待时间; 79 | - 如果 await 远大于 svctm,说明I/O 队列太长,io响应太慢,则需要进行必要优化。 80 | - 如果avgqu-sz比较大,也表示有大量io在等待。 81 | 82 | 更多参数说明请参考 :ref:`iostat` ; 83 | 84 | 分析进程调用 85 | -------------------- 86 | 通过top等工具发现系统性能问题是由某个进程导致的之后,接下来我们就需要分析这个进程;继续 87 | 查询问题在哪; 88 | 89 | 这里我们有两个好用的工具: 90 | pstack和pstrace 91 | 92 | pstack用来跟踪进程栈,这个命令在排查进程问题时非常有用,比如我们发现一个服务一直处于work状态(如假死状态,好似死循环),使用这个命令就能轻松定位问题所在;可以在一段时间内,多执行几次pstack,若发现代码栈总是停在同一个位置,那个位置就需要重点关注,很可能就是出问题的地方; 93 | 94 | 示例:查看bash程序进程栈:: 95 | 96 | /opt/app/tdev1$ps -fe| grep bash 97 | tdev1 7013 7012 0 19:42 pts/1 00:00:00 -bash 98 | tdev1 11402 11401 0 20:31 pts/2 00:00:00 -bash 99 | tdev1 11474 11402 0 20:32 pts/2 00:00:00 grep bash 100 | /opt/app/tdev1$pstack 7013 101 | #0 0x00000039958c5620 in __read_nocancel () from /lib64/libc.so.6 102 | #1 0x000000000047dafe in rl_getc () 103 | #2 0x000000000047def6 in rl_read_key () 104 | #3 0x000000000046d0f5 in readline_internal_char () 105 | #4 0x000000000046d4e5 in readline () 106 | #5 0x00000000004213cf in ?? () 107 | #6 0x000000000041d685 in ?? () 108 | #7 0x000000000041e89e in ?? () 109 | #8 0x00000000004218dc in yyparse () 110 | #9 0x000000000041b507 in parse_command () 111 | #10 0x000000000041b5c6 in read_command () 112 | #11 0x000000000041b74e in reader_loop () 113 | #12 0x000000000041b2aa in main () 114 | 115 | 而strace用来跟踪进程中的系统调用;这个工具能够动态的跟踪进程执行时的系统调用和所接收的信号。是一个非常有效的检测、指导和调试工具。系统管理员可以通过该命令容易地解决程序问题。 116 | 117 | 参考: :ref:`strace` ; 118 | 119 | 120 | 优化程序代码 121 | ------------------ 122 | 优化自己开发的程序,建议采用以下准则:: 123 | 124 | 1. 二八法则:在任何一组东西中,最重要的只占其中一小部分,约20%,其余80%的尽管是多数,却是次要的;在优化实践中,我们将精力集中在优化那20%最耗时的代码上,整体性能将有显著的提升;这个很好理解。函数A虽然代码量大,但在一次正常执行流程中,只调用了一次。而另一个函数B代码量比A小很多,但被调用了1000次。显然,我们更应关注B的优化。 125 | 2. 编完代码,再优化;编码的时候总是考虑最佳性能未必总是好的;在强调最佳性能的编码方式的同时,可能就损失了代码的可读性和开发效率; 126 | 127 | gprof使用步骤 128 | ^^^^^^^^^^^^^^^^^^^^ 129 | 1. 用gcc、g++、xlC编译程序时,使用-pg参数,如:g++ -pg -o test.exe test.cpp编译器会自动在目标代码中插入用于性能测试的代码片断,这些代码在程序运行时采集并记录函数的调用关系和调用次数,并记录函数自身执行时间和被调用函数的执行时间。 130 | 2. 执行编译后的可执行程序,如:./test.exe。该步骤运行程序的时间会稍慢于正常编译的可执行程序的运行时间。程序运行结束后,会在程序所在路径下生成一个缺省文件名为gmon.out的文件,这个文件就是记录程序运行的性能、调用关系、调用次数等信息的数据文件。 131 | 3. 使用gprof命令来分析记录程序运行信息的gmon.out文件,如:gprof test.exe gmon.out则可以在显示器上看到函数调用相关的统计、分析信息。上述信息也可以采用gprof test.exe gmon.out> gprofresult.txt重定向到文本文件以便于后续分析。 132 | 133 | 关于gprof的使用案例,请参考 [f1]_ ; 134 | 135 | 其它工具 136 | -------------------- 137 | 调试内存泄漏的工具valgrind,感兴趣的朋友可以google了解; 138 | 139 | OProfile: Linux 平台上的一个功能强大的性能分析工具,使用参考 [f2]_ ; 140 | 141 | 除了上面介绍的工具,还有一些比较全面的性能分析工具,比如sar(Linux系统上默认不安装,需要手动安装下); 142 | 将sar的常驻监控工具打开后,能够收集比较全面的性能分析数据; 143 | 144 | 关于sar的使用,参考 :ref:`sar` ; 145 | 146 | .. [f1] C++的性能优化实践 http://www.cnblogs.com/me115/archive/2013/06/05/3117967.html 147 | .. [f2] 用 OProfile 彻底了解性能 http://www.ibm.com/developerworks/cn/linux/l-oprof/ 148 | .. [f3] Linux上的free命令详解 http://www.cnblogs.com/coldplayerest/archive/2010/02/20/1669949.html 149 | -------------------------------------------------------------------------------- /advance/index.rst: -------------------------------------------------------------------------------- 1 | .. _linuxadvance-overview: 2 | 3 | Linux工具进阶 4 | ============== 5 | 程序篇 6 | 7 | 8 | .. toctree:: 9 | :maxdepth: 1 10 | :numbered: 2 11 | 12 | 01_program_build 13 | 02_program_debug 14 | 03_optimization 15 | 16 | 17 | -------------------------------------------------------------------------------- /base/01_use_man.rst: -------------------------------------------------------------------------------- 1 | .. _01_use_man: 2 | 3 | 学会使用命令帮助 4 | ================ 5 | 6 | 概述 7 | -------------------- 8 | 在linux终端,面对命令不知道怎么用,或不记得命令的拼写及参数时,我们需要求助于系统的帮助文档; 9 | linux系统内置的帮助文档很详细,通常能解决我们的问题,我们需要掌握如何正确的去使用它们; 10 | 11 | - 在只记得部分命令关键字的场合,我们可通过man -k来搜索; 12 | - 需要知道某个命令的简要说明,可以使用whatis;而更详细的介绍,则可用info命令; 13 | - 查看命令在哪个位置,我们需要使用which; 14 | - 而对于命令的具体参数及使用方法,我们需要用到强大的man; 15 | 16 | 下面介绍这些命令; 17 | 18 | 19 | 命令使用 20 | -------------------- 21 | 22 | 查看命令的简要说明 23 | ^^^^^^^^^^^^^^^^^^^^ 24 | 简要说明命令的作用(显示命令所处的man分类页面):: 25 | 26 | $whatis command 27 | 28 | 正则匹配:: 29 | 30 | $whatis -w "loca*" 31 | 32 | 更加详细的说明文档:: 33 | 34 | $info command 35 | 36 | 使用man 37 | ^^^^^^^^^^^^^^^^^^^^ 38 | 39 | 查询命令command的说明文档:: 40 | 41 | $man command 42 | eg:man date 43 | 44 | 使用page up和page down来上下翻页 45 | 46 | 在man的帮助手册中,将帮助文档分为了9个类别,对于有的关键字可能存在多个类别中, 47 | 我们就需要指定特定的类别来查看;(一般我们查询bash命令,归类在1类中); 48 | 49 | man页面所属的分类标识(常用的是分类1和分类3) :: 50 | 51 | (1)、用户可以操作的命令或者是可执行文件 52 | (2)、系统核心可调用的函数与工具等 53 | (3)、一些常用的函数与数据库 54 | (4)、设备文件的说明 55 | (5)、设置文件或者某些文件的格式 56 | (6)、游戏 57 | (7)、惯例与协议等。例如Linux标准文件系统、网络协议、ASCⅡ,码等说明内容 58 | (8)、系统管理员可用的管理条令 59 | (9)、与内核有关的文件 60 | 61 | 62 | 前面说到使用whatis会显示命令所在的具体的文档类别,我们学习如何使用它 :: 63 | 64 | eg: 65 | $whatis printf 66 | printf (1) - format and print data 67 | printf (1p) - write formatted output 68 | printf (3) - formatted output conversion 69 | printf (3p) - print formatted output 70 | printf [builtins] (1) - bash built-in commands, see bash(1) 71 | 我们看到printf在分类1和分类3中都有;分类1中的页面是命令操作及可执行文件的帮助;而3是常用函数库说明;如果我们想看的是C语言中printf的用法,可以指定查看分类3的帮助: 72 | :: 73 | 74 | $man 3 printf 75 | 76 | $man -k keyword 77 | 78 | 查询关键字 79 | 根据命令中部分关键字来查询命令,适用于只记住部分命令的场合; 80 | 81 | eg:查找GNOME的config配置工具命令:: 82 | 83 | $man -k GNOME config| grep 1 84 | 85 | 对于某个单词搜索,可直接使用/word来使用: /-a; 86 | 多关注下SEE ALSO 可看到更多精彩内容 87 | 88 | 89 | 查看路径 90 | ^^^^^^^^ 91 | 查看程序的binary文件所在路径:: 92 | 93 | $which command 94 | 95 | eg:查找make程序安装路径:: 96 | 97 | $which make 98 | /opt/app/openav/soft/bin/make install 99 | 100 | 查看程序的搜索路径:: 101 | 102 | $whereis command 103 | 当系统中安装了同一软件的多个版本时,不确定使用的是哪个版本时,这个命令就能派上用场; 104 | 105 | 106 | 总结 107 | ^^^^ 108 | whatis info man which whereis 109 | 110 | -------------------------------------------------------------------------------- /base/02_file_manage.rst: -------------------------------------------------------------------------------- 1 | .. _02_file_manage: 2 | 3 | 文件及目录管理 4 | ========================== 5 | 6 | .. contents:: 目录 7 | 8 | 文件管理不外乎文件或目录的创建、删除、查询、移动,有mkdir/rm/mv 9 | 10 | 文件查询是重点,用find来进行查询;find的参数丰富,也非常强大; 11 | 12 | 查看文件内容是个大的话题,文本的处理有太多的工具供我们使用,在本章中只是点到即止,后面会有专门的一章来介绍文本的处理工具; 13 | 14 | 有时候,需要给文件创建一个别名,我们需要用到ln,使用这个别名和使用原文件是相同的效果; 15 | 16 | 创建和删除 17 | -------------------- 18 | 19 | - 创建:mkdir 20 | - 删除:rm 21 | - 删除非空目录:rm -rf file目录 22 | - 删除日志 rm \*log (等价: $find ./ -name "\*log" -exec rm {} \;) 23 | - 移动:mv 24 | - 复制:cp (复制目录:cp -r ) 25 | 26 | 查看当前目录下文件个数:: 27 | 28 | $find ./ | wc -l 29 | 30 | 复制目录:: 31 | 32 | $cp -r source_dir dest_dir 33 | 34 | 35 | 目录切换 36 | ------------------- 37 | 38 | - 找到文件/目录位置:cd 39 | - 切换到上一个工作目录: cd - 40 | - 切换到home目录: cd or cd ~ 41 | - 显示当前路径: pwd 42 | - 更改当前工作路径为path: $cd path 43 | 44 | 列出目录项 45 | -------------------- 46 | 47 | - 显示当前目录下的文件 ls 48 | - 按时间排序,以列表的方式显示目录项 ls -lrt 49 | 50 | 以上这个命令用到的频率如此之高,以至于我们需要为它建立一个快捷命令方式: 51 | 52 | 在.bashrc 中设置命令别名:: 53 | 54 | alias lsl='ls -lrt' 55 | alias lm='ls -al|more' 56 | 57 | 这样,使用lsl,就可以显示目录中的文件按照修改时间排序;以列表方式显示; 58 | 59 | - 给每项文件前面增加一个id编号(看上去更加整洁):: 60 | 61 | >ls | cat -n 62 | 1 a 63 | 2 a.out 64 | 3 app 65 | 4 b 66 | 5 bin 67 | 6 config 68 | 69 | 注:.bashrc 在/home/你的用户名/ 文件夹下,以隐藏文件的方式存储;可使用 ls -a 查看; 70 | 71 | 查找目录及文件 find/locate 72 | ---------------------------------------- 73 | 搜寻文件或目录:: 74 | 75 | $find ./ -name "core*" | xargs file 76 | 77 | 查找目标文件夹中是否有obj文件:: 78 | 79 | $find ./ -name '*.o' 80 | 81 | 递归当前目录及子目录删除所有.o文件:: 82 | 83 | $find ./ -name "*.o" -exec rm {} \; 84 | 85 | find是实时查找,如果需要更快的查询,可试试locate;locate会为文件系统建立索引数据库,如果有文件更新,需要定期执行更新命令来更新索引库:: 86 | 87 | $updatedb 88 | 89 | 寻找包含有string的路径:: 90 | 91 | $locate string 92 | 93 | 与find不同,locate并不是实时查找。你需要更新数据库,以获得最新的文件索引信息。 94 | 95 | 查看文件内容 96 | ----------------------- 97 | 查看文件:cat vi head tail more 98 | 99 | 显示时同时显示行号:: 100 | 101 | $cat -n 102 | 按页显示列表内容:: 103 | 104 | $ls -al | more 105 | 只看前10行:: 106 | 107 | $head - 10 ** 108 | 109 | 显示文件第一行:: 110 | 111 | $head -1 filename 112 | 113 | 显示文件倒数第五行:: 114 | 115 | $tail -5 filename 116 | 117 | 查看两个文件间的差别:: 118 | 119 | $diff file1 file2 120 | 121 | 动态显示文本最新信息:: 122 | 123 | $tail -f crawler.log 124 | 125 | 查找文件内容 126 | ----------------------- 127 | 使用egrep查询文件内容:: 128 | 129 | egrep '03.1\/CO\/AE' TSF_STAT_111130.log.012 130 | egrep 'A_LMCA777:C' TSF_STAT_111130.log.035 > co.out2 131 | 132 | 文件与目录权限修改 133 | -------------------------------- 134 | 135 | - 改变文件的拥有者 chown 136 | - 改变文件读、写、执行等属性 chmod 137 | - 递归子目录修改: chown -R tuxapp source/ 138 | - 增加脚本可执行权限: chmod a+x myscript 139 | 140 | 141 | 给文件增加别名 142 | -------------------------- 143 | 创建符号链接/硬链接:: 144 | 145 | ln cc ccAgain :硬连接;删除一个,将仍能找到; 146 | ln -s cc ccTo :符号链接(软链接);删除源,另一个无法使用;(后面一个ccTo 为新建的文件) 147 | 148 | 149 | 管道和重定向 150 | ----------------------- 151 | - 批处理命令连接执行,使用 | 152 | - 串联: 使用分号 ; 153 | - 前面成功,则执行后面一条,否则,不执行:&& 154 | - 前面失败,则后一条执行: || 155 | 156 | :: 157 | 158 | ls /proc && echo suss! || echo failed. 159 | 160 | 能够提示命名是否执行成功or失败; 161 | 162 | 与上述相同效果的是:: 163 | 164 | if ls /proc; then echo suss; else echo fail; fi 165 | 166 | 重定向:: 167 | 168 | ls proc/*.c > list 2> &l 将标准输出和标准错误重定向到同一文件; 169 | 170 | 等价的是:: 171 | 172 | ls proc/*.c &> list 173 | 174 | 清空文件:: 175 | 176 | :> a.txt 177 | 178 | 重定向:: 179 | 180 | echo aa >> a.txt 181 | 182 | 设置环境变量 183 | ---------------- 184 | 启动帐号后自动执行的是 文件为 .profile,然后通过这个文件可设置自己的环境变量; 185 | 186 | 安装的软件路径一般需要加入到path中:: 187 | 188 | PATH=$APPDIR:/opt/app/soft/bin:$PATH:/usr/local/bin:$TUXDIR/bin:$ORACLE_HOME/bin;export PATH 189 | 190 | Bash快捷输入或删除 191 | ------------------------------ 192 | 快捷键:: 193 | 194 | Ctl-U 删除光标到行首的所有字符,在某些设置下,删除全行 195 | Ctl-W 删除当前光标到前边的最近一个空格之间的字符 196 | Ctl-H backspace,删除光标前边的字符 197 | Ctl-R 匹配最相近的一个文件,然后输出 198 | 199 | 综合应用 200 | ----------------- 201 | 查找record.log中包含AAA,但不包含BBB的记录的总数:: 202 | 203 | cat -v record.log | grep AAA | grep -v BBB | wc -l 204 | 205 | 总结 206 | ----------- 207 | 文件管理,目录的创建、删除、查询、管理: mkdir rm mv 208 | 209 | 文件的查询和检索: find locate 210 | 211 | 查看文件内容:cat vi tail more 212 | 213 | 管道和重定向: ; | && > 214 | -------------------------------------------------------------------------------- /base/04_disk.rst: -------------------------------------------------------------------------------- 1 | .. _04_disk: 2 | 3 | 磁盘管理 4 | ======== 5 | 6 | .. contents:: 目录 7 | 8 | 9 | 日程磁盘管理中,我们最常用的有查看当前磁盘使用情况,查看当前目录所占大小,以及打包压缩与解压缩; 10 | 11 | 12 | 查看磁盘空间 13 | ----------------------- 14 | 查看磁盘空间利用大小:: 15 | 16 | df -h 17 | -h: human缩写,以易读的方式显示结果(即带单位:比如M/G,如果不加这个参数,显示的数字以B为单位) 18 | 19 | :: 20 | 21 | $df -h 22 | /opt/app/todeav/config#df -h 23 | Filesystem Size Used Avail Use% Mounted on 24 | /dev/mapper/VolGroup00-LogVol00 25 | 2.0G 711M 1.2G 38% / 26 | /dev/mapper/vg1-lv2 20G 3.8G 15G 21% /opt/applog 27 | /dev/mapper/vg1-lv1 20G 13G 5.6G 70% /opt/app 28 | 29 | 30 | 31 | 查看当前目录所占空间大小:: 32 | 33 | du -sh 34 | 35 | - -h 人性化显示 36 | - -s 递归整个目录的大小 37 | 38 | :: 39 | 40 | $du -sh 41 | 653M 42 | 43 | 44 | 查看当前目录下所有子文件夹排序后的大小:: 45 | 46 | for i in `ls`; do du -sh $i; done | sort 47 | 或者: 48 | du -sh `ls` | sort 49 | 50 | 51 | 打包/ 压缩 52 | ------------------- 53 | 在linux中打包和压缩和分两步来实现的; 54 | 55 | **打包** 56 | 57 | 打包是将多个文件归并到一个文件:: 58 | 59 | tar -cvf etc.tar /etc <==仅打包,不压缩! 60 | 61 | - -c :打包选项 62 | - -v :显示打包进度 63 | - -f :使用档案文件 64 | 注:有的系统中指定参数时不需要在前面加上-,直接使用tar xvf 65 | 66 | 示例:用tar实现文件夹同步,排除部分文件不同步:: 67 | 68 | tar --exclude '*.svn' -cvf - /path/to/source | ( cd /path/to/target; tar -xf -) 69 | 70 | **压缩** 71 | :: 72 | 73 | $gzip demo.txt 74 | 生成 demo.txt.gz 75 | 76 | 解包/解压缩 77 | --------------------- 78 | **解包** 79 | :: 80 | 81 | tar -xvf demo.tar 82 | -x 解包选项 83 | 84 | 解压后缀为 .tar.gz的文件 85 | 1. 先解压缩,生成**.tar:: 86 | 87 | $gunzip demo.tar.gz 88 | 2. 解包:: 89 | 90 | $tar -xvf demo.tar 91 | $bzip2 -d demo.tar.bz2 92 | 93 | bz2解压:: 94 | 95 | tar jxvf demo.tar.bz2 96 | 如果tar 不支持j,则同样需要分两步来解包解压缩,使用bzip2来解压,再使用tar解包:: 97 | 98 | bzip2 -d demo.tar.bz2 99 | tar -xvf demo.tar 100 | -d decompose,解压缩 101 | 102 | tar解压参数说明: 103 | 104 | - -z 解压gz文件 105 | - -j 解压bz2文件 106 | - -J 解压xz文件 107 | 108 | 总结 109 | ----------- 110 | 查看磁盘空间 df -h 111 | 112 | 查看目录大小 du -sh 113 | 114 | 打包 tar -cvf 115 | 116 | 解包 tar -xvf 117 | 118 | 压缩 gzip 119 | 120 | 解压缩 gunzip bzip 121 | -------------------------------------------------------------------------------- /base/05_process_manage.rst: -------------------------------------------------------------------------------- 1 | .. _05_process_manage: 2 | 3 | 进程管理工具 4 | ============= 5 | 6 | .. contents:: 目录 7 | 8 | 9 | 这一节我们介绍进程管理工具; 10 | 11 | 使用进程管理工具,我们可以查询程序当前的运行状态,或终止一个进程; 12 | 13 | 任何进程都与文件关联;我们会用到lsof工具(list opened files),作用是列举系统中已经被打开的文件。在linux环境中,任何事物都是文件,设备是文件,目录是文件,甚至sockets也是文件。用好lsof命令,对日常的linux管理非常有帮助。 14 | 15 | 查询进程 16 | ---------------- 17 | 18 | 查询正在运行的进程信息 19 | :: 20 | 21 | $ps -ef 22 | 23 | eg:查询归属于用户colin115的进程 24 | :: 25 | 26 | $ps -ef | grep colin115 27 | $ps -lu colin115 28 | 29 | 30 | 查询进程ID(适合只记得部分进程字段) 31 | :: 32 | 33 | $pgrep 查找进程 34 | 35 | eg:查询进程名中含有re的进程 36 | [/home/weber#]pgrep -l re 37 | 2 kthreadd 38 | 28 ecryptfs-kthrea 39 | 29515 redis-server 40 | 41 | 42 | 以完整的格式显示所有的进程 43 | :: 44 | 45 | $ps -ajx 46 | 47 | 48 | 显示进程信息,并实时更新 49 | :: 50 | 51 | $top 52 | 53 | 54 | 查看端口占用的进程状态: 55 | :: 56 | 57 | lsof -i:3306 58 | 59 | 60 | 查看用户username的进程所打开的文件 61 | :: 62 | 63 | $lsof -u username 64 | 65 | 66 | 查询init进程当前打开的文件 67 | :: 68 | 69 | $lsof -c init 70 | 71 | 72 | 查询指定的进程ID(23295)打开的文件: 73 | :: 74 | 75 | $lsof -p 23295 76 | 77 | 78 | 查询指定目录下被进程开启的文件(使用+D 递归目录): 79 | :: 80 | 81 | $lsof +d mydir1/ 82 | 83 | 84 | 终止进程 85 | ---------------- 86 | 87 | 杀死指定PID的进程 (PID为Process ID) 88 | :: 89 | 90 | $kill PID 91 | 92 | 93 | 杀死相关进程 94 | :: 95 | 96 | kill -9 3434 97 | 98 | 99 | 杀死job工作 (job为job number) 100 | :: 101 | 102 | $kill %job 103 | 104 | 105 | 进程监控 106 | ---------------- 107 | 查看系统中使用CPU、使用内存最多的进程; 108 | :: 109 | 110 | $top 111 | (->)P 112 | 113 | 输入top命令后,进入到交互界面;接着输入字符命令后显示相应的进程状态: 114 | 115 | 对于进程,平时我们最常想知道的就是哪些进程占用CPU最多,占用内存最多。以下两个命令就可以满足要求:: 116 | 117 | P:根据CPU使用百分比大小进行排序。 118 | M:根据驻留内存大小进行排序。 119 | i:使top不显示任何闲置或者僵死进程。 120 | 121 | 这里介绍最使用的几个选项,对于更详细的使用,详见 :ref:`top` ; 122 | 123 | 124 | 分析线程栈 125 | ------------------- 126 | 使用命令pmap,来输出进程内存的状况,可以用来分析线程堆栈; 127 | :: 128 | 129 | $pmap PID 130 | 131 | eg: 132 | [/home/weber#]ps -fe| grep redis 133 | weber 13508 13070 0 08:14 pts/0 00:00:00 grep --color=auto redis 134 | weber 29515 1 0 2013 ? 02:55:59 ./redis-server redis.conf 135 | [/home/weber#]pmap 29515 136 | 29515: ./redis-server redis.conf 137 | 08048000 768K r-x-- /home/weber/soft/redis-2.6.16/src/redis-server 138 | 08108000 4K r---- /home/weber/soft/redis-2.6.16/src/redis-server 139 | 08109000 12K rw--- /home/weber/soft/redis-2.6.16/src/redis-server 140 | 141 | 142 | 综合运用 143 | ---------------- 144 | 将用户colin115下的所有进程名以av_开头的进程终止:: 145 | 146 | ps -u colin115 | awk '/av_/ {print "kill -9 " $1}' | sh 147 | 148 | 将用户colin115下所有进程名中包含HOST的进程终止:: 149 | 150 | ps -fe| grep colin115|grep HOST |awk '{print $2}' | xargs kill -9; 151 | 152 | 153 | 总结 154 | ---------- 155 | ps top lsof kill pmap 156 | -------------------------------------------------------------------------------- /base/06_monitor.rst: -------------------------------------------------------------------------------- 1 | .. _06_monitor: 2 | 3 | 性能监控 4 | ========= 5 | 6 | .. contents:: 目录 7 | 8 | 9 | 在使用操作系统的过程中,我们经常需要查看当前的性能如何,需要了解CPU、内存和硬盘的使用情况; 10 | 本节介绍的这几个工具能满足日常工作要求; 11 | 12 | 监控CPU 13 | ------------- 14 | 查看CPU使用率 15 | :: 16 | 17 | $sar -u 18 | 19 | eg: 20 | $sar -u 1 2 21 | [/home/weber#]sar -u 1 2 22 | Linux 2.6.35-22-generic-pae (MyVPS) 06/28/2014 _i686_ (1 CPU) 23 | 24 | 09:03:59 AM CPU %user %nice %system %iowait %steal %idle 25 | 09:04:00 AM all 0.00 0.00 0.50 0.00 0.00 99.50 26 | 09:04:01 AM all 0.00 0.00 0.00 0.00 0.00 100.00 27 | 28 | 后面的两个参数表示监控的频率,比如例子中的1和2,表示每秒采样一次,总共采样2次; 29 | 30 | 查看CPU平均负载 31 | :: 32 | 33 | $sar -q 1 2 34 | 35 | sar指定-q后,就能查看运行队列中的进程数、系统上的进程大小、平均负载等; 36 | 37 | 38 | 查询内存 39 | ---------------- 40 | 查看内存使用状况 41 | sar指定-r之后,可查看内存使用状况; 42 | :: 43 | 44 | $sar -r 1 2 45 | 09:08:48 AM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact 46 | 09:08:49 AM 17888 359784 95.26 37796 73272 507004 65.42 137400 150764 47 | 09:08:50 AM 17888 359784 95.26 37796 73272 507004 65.42 137400 150764 48 | Average: 17888 359784 95.26 37796 73272 507004 65.42 137400 150764 49 | 50 | 51 | 查看内存使用量 52 | :: 53 | 54 | $free -m 55 | 56 | 57 | 查询页面交换 58 | ---------------------- 59 | 查看页面交换发生状况 60 | 页面发生交换时,服务器的吞吐量会大幅下降;服务器状况不良时,如果怀疑因为内存不足而导致了页面交换的发生,可以使用sar -W这个命令来确认是否发生了大量的交换; 61 | :: 62 | 63 | $sar -W 1 3 64 | 65 | 66 | 查询硬盘使用 67 | ---------------------- 68 | 查看磁盘空间利用情况 69 | :: 70 | 71 | $df -h 72 | 73 | 查询当前目录下空间使用情况 74 | :: 75 | 76 | du -sh -h是人性化显示 s是递归整个目录的大小 77 | 78 | 79 | 查看该目录下所有文件夹的排序后的大小 80 | :: 81 | 82 | for i in `ls`; do du -sh $i; done | sort 83 | 或者 84 | du -sh `ls` 85 | 86 | 87 | 88 | 综合应用 89 | ---------------- 90 | 当系统中sar不可用时,可以使用以下工具替代:linux下有 vmstat、Unix系统有prstat 91 | 92 | eg: 93 | 查看cpu、内存、使用情况: 94 | vmstat n m (n 为监控频率、m为监控次数) 95 | :: 96 | 97 | [/home/weber#]vmstat 1 3 98 | procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- 99 | r b swpd free buff cache si so bi bo in cs us sy id wa 100 | 0 0 86560 42300 9752 63556 0 1 1 1 0 0 0 0 99 0 101 | 1 0 86560 39936 9764 63544 0 0 0 52 66 95 5 0 95 0 102 | 0 0 86560 42168 9772 63556 0 0 0 20 127 231 13 2 84 0 103 | 104 | 105 | 106 | 使用watch 工具监控变化 107 | 当需要持续的监控应用的某个数据变化时,watch工具能满足要求; 108 | 执行watch命令后,会进入到一个界面,输出当前被监控的数据,一旦数据变化,便会高亮显示变化情况; 109 | 110 | 111 | eg:操作redis时,监控内存变化: 112 | :: 113 | 114 | $watch -d -n 1 './redis-cli info | grep memory' 115 | (以下为watch工具中的界面内容,一旦内存变化,即实时高亮显示变化) 116 | Every 1.0s: ./redis-cli info | grep memory Mon Apr 28 16:10:36 2014 117 | 118 | used_memory:45157376 119 | used_memory_human:43.07M 120 | used_memory_rss:47628288 121 | used_memory_peak:49686080 122 | used_memory_peak_human:47.38M 123 | 124 | 125 | 总结 126 | ---------- 127 | top / sar / free / watch 128 | 129 | 附录 130 | ---------- 131 | 关于sar的使用详解参考::ref:`sar` 132 | -------------------------------------------------------------------------------- /base/07_network.rst: -------------------------------------------------------------------------------- 1 | .. _07_network: 2 | 3 | 网络工具 4 | ==================== 5 | 6 | .. contents:: 目录 7 | 8 | 查询网络服务和端口 9 | -------------------- 10 | netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等。 11 | 12 | 13 | 列出所有端口 (包括监听和未监听的):: 14 | 15 | netstat -a 16 | 17 | 列出所有 tcp 端口:: 18 | 19 | netstat -at 20 | 21 | 列出所有有监听的服务状态:: 22 | 23 | netstat -l 24 | 25 | 使用netstat工具查询端口:: 26 | 27 | $netstat -antp | grep 6379 28 | tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 25501/redis-server 29 | 30 | $ps 25501 31 | PID TTY STAT TIME COMMAND 32 | 25501 ? Ssl 28:21 ./redis-server ./redis.conf 33 | 34 | lsof(list open files)是一个列出当前系统打开文件的工具。在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件。所以如传输控制协议 (TCP) 和用户数据报协议 (UDP) 套接字等; 35 | 在查询网络端口时,经常会用到这个工具。 36 | 37 | 查询7902端口现在运行什么程序:: 38 | 39 | #分为两步 40 | #第一步,查询使用该端口的进程的PID; 41 | $lsof -i:7902 42 | COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME 43 | WSL 30294 tuapp 4u IPv4 447684086 TCP 10.6.50.37:tnos-dp (LISTEN) 44 | 45 | #查到30294 46 | #使用ps工具查询进程详情: 47 | $ps -fe | grep 30294 48 | tdev5 30294 26160 0 Sep10 ? 01:10:50 tdesl -k 43476 49 | root 22781 22698 0 00:54 pts/20 00:00:00 grep 11554 50 | 51 | .. note:: 52 | 53 | 以上介绍lsof关于网络方面的应用,这个工具非常强大,需要好好掌握,详见 :ref:`lsof` ; 54 | 55 | 56 | 网络路由 57 | -------------------- 58 | 查看路由状态:: 59 | 60 | $route -n 61 | 62 | 发送ping包到地址IP:: 63 | 64 | $ping IP 65 | 66 | 探测前往地址IP的路由路径:: 67 | 68 | $traceroute IP 69 | 70 | DNS查询,寻找域名domain对应的IP:: 71 | 72 | $host domain 73 | 74 | 反向DNS查询:: 75 | 76 | $host IP 77 | 78 | 镜像下载 79 | -------------------- 80 | 直接下载文件或者网页:: 81 | 82 | wget url 83 | 84 | 常用选项: 85 | 86 | - --limit-rate :下载限速 87 | - -o:指定日志文件;输出都写入日志; 88 | - -c:断点续传 89 | 90 | 91 | ftp sftp lftp ssh 92 | -------------------- 93 | 94 | SSH登录:: 95 | 96 | $ssh ID@host 97 | ssh登录远程服务器host,ID为用户名。 98 | 99 | 100 | ftp/sftp文件传输:: 101 | 102 | $sftp ID@host 103 | 104 | 登录服务器host,ID为用户名。sftp登录后,可以使用下面的命令进一步操作: 105 | 106 | - get filename # 下载文件 107 | - put filename # 上传文件 108 | - ls # 列出host上当前路径的所有文件 109 | - cd # 在host上更改当前路径 110 | - lls # 列出本地主机上当前路径的所有文件 111 | - lcd # 在本地主机更改当前路径 112 | 113 | lftp同步文件夹(类似rsync工具):: 114 | 115 | lftp -u user:pass host 116 | lftp user@host:~> mirror -n 117 | 118 | 119 | 网络复制 120 | -------------------- 121 | 将本地localpath指向的文件上传到远程主机的path路径:: 122 | 123 | $scp localpath ID@host:path 124 | 125 | 以ssh协议,遍历下载path路径下的整个文件系统,到本地的localpath:: 126 | 127 | $scp -r ID@site:path localpath 128 | 129 | 总结 130 | -------------------- 131 | netstat lsof route ping host wget sftp scp 132 | -------------------------------------------------------------------------------- /base/08_user_manage.rst: -------------------------------------------------------------------------------- 1 | .. _08_user_manage: 2 | 3 | 用户管理工具 4 | ==================== 5 | 6 | .. contents:: 目录 7 | 8 | 用户 9 | --------------------- 10 | 11 | 添加用户 12 | ^^^^^^^^^^^^^^^^^^^^ 13 | 14 | :: 15 | 16 | $useradd -m username 17 | 18 | 该命令为用户创建相应的帐号和用户目录/home/username; 19 | 20 | 用户添加之后,设置密码: 21 | 22 | 密码以交互方式创建:: 23 | 24 | $passwd username 25 | 26 | 27 | 删除用户 28 | ^^^^^^^^^^^^^^^^^^^^ 29 | 30 | :: 31 | 32 | $userdel -r username 33 | 不带选项使用 userdel,只会删除用户。用户的家目录将仍会在/home目录下。要完全的删除用户信息,使用-r选项; 34 | 35 | 帐号切换 36 | 登录帐号为userA用户状态下,切换到userB用户帐号工作:: 37 | 38 | $su userB 39 | 进入交互模型,输入密码授权进入; 40 | 41 | 用户的组 42 | -------------------- 43 | 44 | 将用户加入到组 45 | ^^^^^^^^^^^^^^^^^^^^ 46 | 默认情况下,添加用户操作也会相应的增加一个同名的组,用户属于同名组; 47 | 查看当前用户所属的组:: 48 | 49 | $groups 50 | 51 | 一个用户可以属于多个组,将用户加入到组:: 52 | 53 | $usermod -G groupNmame username 54 | 55 | 变更用户所属的根组(将用加入到新的组,并从原有的组中除去):: 56 | 57 | $usermod -g groupName username 58 | 59 | 查看系统所有组 60 | ^^^^^^^^^^^^^^^^^^^^ 61 | 系统的所有用户及所有组信息分别记录在两个文件中:/etc/passwd , /etc/group 62 | 默认情况下这两个文件对所有用户可读: 63 | 64 | 查看所有用户及权限:: 65 | 66 | $more /etc/passwd 67 | 68 | 查看所有的用户组及权限:: 69 | 70 | $more /etc/group 71 | 72 | 用户权限 73 | ----------------- 74 | 使用ls -l可查看文件的属性字段,文件属性字段总共有10个字母组成,第一个字母表示文件类型,如果这个字母是一个减号"-",则说明该文件是一个普通文件。字母"d"表示该文件是一个目录,字母"d",是dirtectory(目录)的缩写。 75 | 后面的9个字母为该文件的权限标识,3个为一组,分别表示文件所属用户、用户所在组、其它用户的读写和执行权限; 76 | 例如: 77 | :: 78 | 79 | [/home/weber#]ls -l /etc/group 80 | -rwxrw-r-- colin king 725 2013-11-12 15:37 /home/colin/a 81 | 82 | 表示这个文件对文件拥有者colin这个用户可读写、可执行;对colin所在的组(king)可读可写;对其它用户只可读; 83 | 84 | 更改读写权限 85 | ^^^^^^^^^^^^^^^^^^^^ 86 | 使用chmod命令更改文件的读写权限,更改读写权限有两种方法,一种是字母方式,一种是数字方式 87 | 88 | 字母方式:: 89 | 90 | $chmod userMark(+|-)PermissionsMark 91 | userMark取值: 92 | 93 | - u:用户 94 | - g:组 95 | - o:其它用户 96 | - a:所有用户 97 | PermissionsMark取值: 98 | 99 | - r:读 100 | - w:写 101 | - x:执行 102 | 103 | 例如:: 104 | 105 | $chmod a+x main 对所有用户给文件main增加可执行权限 106 | $chmod g+w blogs 对组用户给文件blogs增加可写权限 107 | 108 | 数字方式: 109 | 110 | 数字方式直接设置所有权限,相比字母方式,更加简洁方便; 111 | 112 | 使用三位八进制数字的形式来表示权限,第一位指定属主的权限,第二位指定组权限,第三位指定其他用户的权限,每位通过4(读)、2(写)、1(执行)三种数值的和来确定权限。如6(4+2)代表有读写权,7(4+2+1)有读、写和执行的权限。 113 | 114 | 例如:: 115 | 116 | $chmod 740 main 将main的用户权限设置为rwxr----- 117 | 118 | 119 | 更改文件或目录的拥有者 120 | ^^^^^^^^^^^^^^^^^^^^^^ 121 | :: 122 | 123 | $chown username dirOrFile 124 | 使用-R选项递归更改该目下所有文件的拥有者:: 125 | 126 | $chown -R weber server/ 127 | 128 | 129 | 环境变量 130 | -------------------- 131 | bashrc与profile都用于保存用户的环境信息,bashrc用于交互式non-loginshell,而profile用于交互式login shell。 132 | 133 | | /etc/profile,/etc/bashrc 是系统全局环境变量设定 134 | | ~/.profile,~/.bashrc用户目录下的私有环境变量设定 135 | | 136 | 137 | 当登入系统获得一个shell进程时,其读取环境设置脚本分为三步: 138 | 139 | 1. 首先读入的是全局环境变量设置文件/etc/profile,然后根据其内容读取额外的文档,如/etc/profile.d和/etc/inputrc 140 | #. 读取当前登录用户Home目录下的文件~/.bash_profile,其次读取~/.bash_login,最后读取~/.profile,这三个文档设定基本上是一样的,读取有优先关系 141 | #. 读取~/.bashrc 142 | 143 | ~/.profile与~/.bashrc的区别: 144 | 145 | - 这两者都具有个性化定制功能 146 | - ~/.profile可以设定本用户专有的路径,环境变量,等,它只能登入的时候执行一次 147 | - ~/.bashrc也是某用户专有设定文档,可以设定路径,命令别名,每次shell script的执行都会使用它一次 148 | 149 | 例如,我们可以在这些环境变量中设置自己经常进入的文件路径,以及命令的快捷方式: 150 | :: 151 | 152 | .bashrc 153 | alias m='more' 154 | alias cp='cp -i' 155 | alias mv='mv -i' 156 | alias ll='ls -l' 157 | alias lsl='ls -lrt' 158 | alias lm='ls -al|more' 159 | 160 | log=/opt/applog/common_dir 161 | unit=/opt/app/unittest/common 162 | 163 | .bash_profile 164 | . /opt/app/tuxapp/openav/config/setenv.prod.sh.linux 165 | export PS1='$PWD#' 166 | 167 | 执行 source ~/.bashrc 使.bashrc中的修改生效 168 | 通过上述设置,我们进入log目录就只需要输入cd $log即可; 169 | 170 | 总结 171 | -------------------- 172 | useradd passwd userdel usermod chmod chown .bashrc .bash_profile 173 | -------------------------------------------------------------------------------- /base/09_system_manage.rst: -------------------------------------------------------------------------------- 1 | .. _09_system_manage: 2 | 3 | 系统管理及IPC资源管理 4 | ================================= 5 | 6 | .. contents:: 目录 7 | 8 | 系统管理 9 | -------------------- 10 | 查询系统版本 11 | ^^^^^^^^^^^^^^^^^^^^ 12 | 查看Linux系统版本:: 13 | 14 | $uname -a 15 | $lsb_release -a 16 | 17 | 查看Unix系统版本:操作系统版本:: 18 | 19 | $more /etc/release 20 | 21 | 22 | 查询硬件信息 23 | ^^^^^^^^^^^^^^^^^^^^ 24 | 查看CPU使用情况:: 25 | 26 | $sar -u 5 10 27 | 28 | 查询CPU信息:: 29 | 30 | $cat /proc/cpuinfo 31 | 32 | 查看CPU的核的个数:: 33 | 34 | $cat /proc/cpuinfo | grep processor | wc -l 35 | 36 | 查看内存信息:: 37 | 38 | $cat /proc/meminfo 39 | 40 | 显示内存page大小(以KByte为单位):: 41 | 42 | $pagesize 43 | 44 | 显示架构:: 45 | 46 | $arch 47 | 48 | 设置系统时间 49 | ^^^^^^^^^^^^^^^^^^^^ 50 | 显示当前系统时间:: 51 | 52 | $date 53 | 54 | 设置系统日期和时间(格式为2014-09-15 17:05:00):: 55 | 56 | $date -s 2014-09-15 17:05:00 57 | $date -s 2014-09-15 58 | $date -s 17:05:00 59 | 60 | 设置时区:: 61 | 62 | 选择时区信息。命令为:tzselect 63 | 根据系统提示,选择相应的时区信息。 64 | 65 | 强制把系统时间写入CMOS(这样,重启后时间也正确了):: 66 | 67 | $clock -w 68 | 69 | .. Caution:: 70 | 71 | 设置系统时间需要root用户权限. 72 | 73 | 格式化输出当前日期时间:: 74 | 75 | $date +%Y%m%d.%H%M%S 76 | >20150512.173821 77 | 78 | IPC资源管理 79 | -------------------- 80 | IPC资源查询 81 | ^^^^^^^^^^^^^^^^^^^^ 82 | 查看系统使用的IPC资源:: 83 | 84 | $ipcs 85 | 86 | ------ Shared Memory Segments -------- 87 | key shmid owner perms bytes nattch status 88 | 89 | ------ Semaphore Arrays -------- 90 | key semid owner perms nsems 91 | 0x00000000 229376 weber 600 1 92 | 93 | ------ Message Queues -------- 94 | key msqid owner perms used-bytes messages 95 | 96 | 查看系统使用的IPC共享内存资源:: 97 | 98 | $ipcs -m 99 | 100 | 查看系统使用的IPC队列资源:: 101 | 102 | $ipcs -q 103 | 104 | 查看系统使用的IPC信号量资源:: 105 | 106 | $ipcs -s 107 | 108 | 应用示例:查看IPC资源被谁占用 109 | 110 | 有个IPCKEY:51036 ,需要查询其是否被占用; 111 | 112 | 1. 首先通过计算器将其转为十六进制: 113 | 51036 -> c75c 114 | 2. 如果知道是被共享内存占用:: 115 | 116 | $ipcs -m | grep c75c 117 | 0x0000c75c 40403197 tdea3 666 536870912 2 118 | 119 | 3. 如果不确定,则直接查找:: 120 | 121 | $ipcs | grep c75c 122 | 0x0000c75c 40403197 tdea3 666 536870912 2 123 | 0x0000c75c 5079070 tdea3 666 4 124 | 125 | 检测和设置系统资源限制 126 | ^^^^^^^^^^^^^^^^^^^^^^^^ 127 | 显示当前所有的系统资源limit 信息:: 128 | 129 | ulimit – a 130 | 131 | 对生成的 core 文件的大小不进行限制:: 132 | 133 | ulimit – c unlimited 134 | 135 | 总结 136 | -------------------- 137 | uname sar arch date ipcs ulimit 138 | -------------------------------------------------------------------------------- /base/README.rst: -------------------------------------------------------------------------------- 1 | linux_tools 2 | =============== 3 | =========== 4 | 5 | linux tools desc 6 | 这里介绍Linux下非常优秀的工具; 7 | 8 | 说明 9 | ----------- 10 | 11 | 1. 教程将工具分为初级和高级两种;初级都是简单常用的工具,而高级篇更多的适合程序调试或优化; 12 | 2. 我将专注于Linux工具的最常用用法,以便读者能以最快时间掌握,并在工作中应用。 13 | 3. 我将此教程写成手册的形式,在工作中应用时能够方便快速查阅; 14 | 4. Linux命令行将以 $ 开始,比如 $ls 15 | 16 | 写作方式 17 | ----------------- 18 | 19 | 我将会遵循以下写作方式: 20 | 21 | 1. 首先介绍工具的使用范围; 22 | 2. 工具的快速上手教程;包含最常用的范例和最常用的选项; 23 | 3. 使用场景(例子)说明; 24 | 4. 更完整的命令参数说明; 25 | 5. 进阶 26 | 27 | 建议 28 | ----------- 29 | 1. 你应该安装有Linux系统,将教程中的命令敲到bash中看看效果 30 | 2. 如果有兴趣,可以在了解之后立即查看相关更完备的内容 (比如查阅官方文档) 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /base/crond introduce.rst: -------------------------------------------------------------------------------- 1 | crontab命令 2 | 3 | crond简介 4 | ---------------- 5 | crond是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动crond进程,crond进程每分钟会定期检查是否有要执行的任务,如果有要执行的任务,则自动执行该任务。 6 | Linux下的任务调度分为两类,系统任务调度和用户任务调度。 7 | 系统任务调度:系统周期性所要执行的工作,比如写缓存数据到硬盘、日志清理等。在/etc目录下有一个crontab文件,这个就是系统任务调度的配置文件。 8 | /etc/crontab文件包括下面几行: 9 | :: 10 | 11 | [root@localhost ~]# cat /etc/crontab 12 | SHELL=/bin/bash 13 | PATH=/sbin:/bin:/usr/sbin:/usr/bin 14 | MAILTO=""HOME=/ 15 | # run-parts 16 | 51 * * * * root run-parts /etc/cron.hourly 17 | 24 7 * * * root run-parts /etc/cron.daily 18 | 22 4 * * 0 root run-parts /etc/cron.weekly 19 | 42 4 1 * * root run-parts /etc/cron.monthly 20 | 21 | 前四行是用来配置crond任务运行的环境变量,第一行SHELL变量指定了系统要使用哪个shell,这里是bash,第二行PATH变量指定了系统执行命令的路径,第三行MAILTO变量指定了crond的任务执行信息将通过电子邮件发送给root用户,如果MAILTO变量的值为空,则表示不发送任务执行信息给用户,第四行的HOME变量指定了在执行命令或者脚本时使用的主目录。第六至九行表示的含义将在下个小节详细讲述。这里不在多说。 22 | 用户任务调度:用户定期要执行的工作,比如用户数据备份、定时邮件提醒等。用户可以使用 crontab 工具来定制自己的计划任务。所有用户定义的crontab 文件都被保存在 /var/spool/cron目录中。其文件名与用户名一致。 23 | 24 | 使用者权限文件 25 | -------------------------- 26 | 文件: 27 | /etc/cron.deny 28 | 说明: 29 | 该文件中所列用户不允许使用crontab命令 30 | 文件: 31 | /etc/cron.allow 32 | 说明: 33 | 该文件中所列用户允许使用crontab命令 34 | 文件: 35 | /var/spool/cron/ 36 | 说明: 37 | 所有用户crontab文件存放的目录,以用户名命名 38 | 39 | crontab文件的含义 40 | --------------------------- 41 | 用户所建立的crontab文件中,每一行都代表一项任务,每行的每个字段代表一项设置,它的格式共分为六个字段,前五段是时间设定段,第六段是要执行的命令段,格式如下: 42 | minute hour day month week command 43 | 其中: 44 | minute: 表示分钟,可以是从0到59之间的任何整数。 45 | hour:表示小时,可以是从0到23之间的任何整数。 46 | day:表示日期,可以是从1到31之间的任何整数。 47 | month:表示月份,可以是从1到12之间的任何整数。 48 | week:表示星期几,可以是从0到7之间的任何整数,这里的0或7代表星期日。 49 | command:要执行的命令,可以是系统命令,也可以是自己编写的脚本文件。 50 | 51 | 在以上各个字段中,还可以使用以下特殊字符: 52 | 星号(*):代表所有可能的值,例如month字段如果是星号,则表示在满足其它字段的制约条件后每月都执行该命令操作。 53 | 逗号(,):可以用逗号隔开的值指定一个列表范围,例如,“1,2,5,7,8,9” 54 | 中杠(-):可以用整数之间的中杠表示一个整数范围,例如“2-6”表示“2,3,4,5,6” 55 | 正斜线(/):可以用正斜线指定时间的间隔频率,例如“0-23/2”表示每两小时执行一次。同时正斜线可以和星号一起使用,例如*/10,如果用在minute字段,表示每十分钟执行一次。 56 | 57 | crond服务 58 | ---------------- 59 | 安装crontab: 60 | yum install crontabs 61 | 服务操作说明: 62 | /sbin/service crond start //启动服务 63 | /sbin/service crond stop //关闭服务 64 | /sbin/service crond restart //重启服务 65 | /sbin/service crond reload //重新载入配置 66 | 查看crontab服务状态: 67 | service crond status 68 | 手动启动crontab服务: 69 | service crond start 70 | 查看crontab服务是否已设置为开机启动,执行命令: 71 | ntsysv 72 | 加入开机自动启动: 73 | chkconfig –level 35 crond on 74 | 75 | 76 | -------------------------------------------------------------------------------- /base/index.rst: -------------------------------------------------------------------------------- 1 | .. _linuxbase-overview: 2 | 3 | Linux基础 4 | ========== 5 | 这一部分主要介绍Linux常用命令工具,比如文件管理、文本处理;\ 6 | 为了让读者用最少的时间掌握到常用的知识,对于每个工具的举例,尽量做到小而精; 7 | 8 | .. note:: 9 | 10 | 本书并非一本讲解Linux各种命令的完整用法的书,并且假设读者已经熟悉Linux命令行下的基本操作。如果读者对\ 11 | Linux操作系统尚不了解,可以参考 《鸟哥的私房菜 基础学习篇》\ [#]_\ 一书。 12 | 13 | 14 | .. toctree:: 15 | :maxdepth: 2 16 | :numbered: 2 17 | 18 | 01_use_man 19 | 02_file_manage 20 | 03_text_processing 21 | 04_disk 22 | 05_process_manage 23 | 06_monitor 24 | 07_network 25 | 08_user_manage 26 | 09_system_manage 27 | 28 | 29 | 30 | ---- 31 | 32 | .. [#] 鸟哥的Linux私房菜 基础学习篇(第二版) http://book.douban.com/subject/2208530/ 33 | -------------------------------------------------------------------------------- /base/ref.rst: -------------------------------------------------------------------------------- 1 | 参考: 2 | 3 | Shell脚本编程30分钟入门 4 | https://github.com/qinjx/30min_guides/blob/master/shell.md 5 | -------------------------------------------------------------------------------- /crontab.md: -------------------------------------------------------------------------------- 1 | ## 命令格式 2 | crontab [-u user] file 3 | crontab [-u user] [ -e | -l | -r ] 4 | 5 | ## 命令功能 6 | 通过crontab 命令,我们可以在固定的间隔时间执行指定的系统指令或 shell script脚本。时间间隔的单位可以是分钟、小时、日、月、周及以上的任意组合。这个命令非常设合周期性的日志分析或数据备份等工作。 7 | 8 | ## 命令参数 9 | -u user:用来设定某个用户的crontab服务,例如,“-u ixdba”表示设定ixdba用户的crontab服务,此参数一般有root用户来运行。 10 | file:file是命令文件的名字,表示将file做为crontab的任务列表文件并载入crontab。如果在命令行中没有指定这个文件,crontab命令将接受标准输入(键盘)上键入的命令,并将它们载入crontab。 11 | -e:编辑某个用户的crontab文件内容。如果不指定用户,则表示编辑当前用户的crontab文件。 12 | -l:显示某个用户的crontab文件内容,如果不指定用户,则表示显示当前用户的crontab文件内容。 13 | -r:从/var/spool/cron目录中删除某个用户的crontab文件,如果不指定用户,则默认删除当前用户的crontab文件。 14 | -i:在删除用户的crontab文件时给确认提示。 15 | 16 | ## 文件格式 17 | 下面是crontab的格式: 18 | 分 时 日 月 星期 要运行的命令 19 | 20 | 第1列分钟1~59 21 | 第2列小时1~23(0表示子夜) 22 | 第3列日1~31 23 | 第4列月1~12 24 | 第5列星期0~6(0表示星期天) 25 | 第6列要运行的命令 26 | 27 | 28 | ## 常用方法 29 | ### 创建一个新的crontab文件 30 | 在考虑向cron进程提交一个crontab文件之前,首先要做的一件事情就是设置环境变量EDITOR。cron进程根据它来确定使用哪个编辑器编辑crontab文件。9 9 %的UNIX和LINUX用户都使用vi,如果你也是这样,那么你就编辑$ HOME目录下的. profile文件,在其中加入这样一行: 31 | EDITOR=vi; export EDITOR 32 | 然后保存并退出。不妨创建一个名为 cron的文件,其中是用户名,例如, davecron。在该文件中加入如下的内容。 33 | ``` 34 | # (put your own initials here)echo the date to the console every 35 | # 15minutes between 6pm and 6am 36 | 0,15,30,45 18-06 * * * /bin/echo 'date' > /dev/console 37 | ``` 38 | 保存并退出。确信前面5个域用空格分隔。 39 | 在上面的例子中,系统将每隔1 5分钟向控制台输出一次当前时间。如果系统崩溃或挂起,从最后所显示的时间就可以一眼看出系统是什么时间停止工作的。在有些系统中,用tty1来表示控制台,可以根据实际情况对上面的例子进行相应的修改。为了提交你刚刚创建的crontab文件,可以把这个新创建的文件作为cron命令的参数: 40 | $ crontab davecron 41 | 现在该文件已经提交给cron进程,它将每隔1 5分钟运行一次。 42 | 同时,新创建文件的一个副本已经被放在/var/spool/cron目录中,文件名就是用户名(即dave)。 43 | 44 | ### 列出crontab文件 45 | 为了列出crontab文件,可以用: 46 | $ crontab -l 47 | 0,15,30,45,18-06 * * * /bin/echo `date` > dev/tty1 48 | 你将会看到和上面类似的内容。可以使用这种方法在$ H O M E目录中对crontab文件做一备份: 49 | $ crontab -l > $HOME/mycron 50 | 这样,一旦不小心误删了crontab文件,可以用上一节所讲述的方法迅速恢复。 51 | 52 | ### 编辑crontab文件 53 | 如果希望添加、删除或编辑crontab文件中的条目,而E D I TO R环境变量又设置为v i,那么就可以用v i来编辑crontab文件,相应的命令为: 54 | $ crontab -e 55 | 可以像使用v i编辑其他任何文件那样修改crontab文件并退出。如果修改了某些条目或添加了新的条目,那么在保存该文件时, c r o n会对其进行必要的完整性检查。如果其中的某个域出现了超出允许范围的值,它会提示你。 56 | 我们在编辑crontab文件时,没准会加入新的条目。例如,加入下面的一条: 57 | ``` 58 | # DT:delete core files,at 3.30am on 1,7,14,21,26,26 days of each month 59 | 30 3 1,7,14,21,26 * * /bin/find -name 'core' -exec rm {} \; 60 | ``` 61 | 62 | 现在保存并退出。最好在crontab文件的每一个条目之上加入一条注释,这样就可以知道它的功能、运行时间,更为重要的是,知道这是哪位用户的作业。 63 | 现在让我们使用前面讲过的crontab -l命令列出它的全部信息: 64 | ``` 65 | $ crontab -l 66 | # (crondave installed on Tue May 4 13:07:43 1999) 67 | # DT:ech the date to the console every 30 minites 68 | 0,15,30,45 18-06 * * * /bin/echo `date` > /dev/tty1 69 | # DT:delete core files,at 3.30am on 1,7,14,21,26,26 days of each month 70 | 30 3 1,7,14,21,26 * * /bin/find -name 'core' -exec rm {} \; 71 | ``` 72 | 73 | ### 删除crontab文件 74 | 要删除crontab文件,可以用: 75 | $ crontab -r 76 | 77 | ### 恢复丢失的crontab文件 78 | 如果不小心误删了crontab文件,假设你在自己的$HOME目录下还有一个备份,那么可以将其拷贝到/var/spool/cron/,其中是用户名。如果由于权限问题无法完成拷贝,可以用: 79 | $ crontab 80 | 其中,是你在$HOME目录中副本的文件名。 81 | 我建议你在自己的$HOME目录中保存一个该文件的副本。我就有过类似的经历,有数次误删了crontab文件(因为r键紧挨在e键的右边)。这就是为什么有些系统文档建议不要直接编辑crontab文件,而是编辑该文件的一个副本,然后重新提交新的文件。 82 | 有些crontab的变体有些怪异,所以在使用crontab命令时要格外小心。如果遗漏了任何选项,crontab可能会打开一个空文件,或者看起来像是个空文件。这时敲delete键退出,不要按,否则你将丢失crontab文件。 83 | 84 | ## 使用实例 85 | ### 实例1:每1分钟执行一次command 86 | 命令: 87 | * * * * * command 88 | 89 | ### 实例2:每小时的第3和第15分钟执行 90 | 命令: 91 | 3,15 * * * * command 92 | 93 | ### 实例3:在上午8点到11点的第3和第15分钟执行 94 | 命令: 95 | 3,15 8-11 * * * command 96 | 97 | ### 实例4:每隔两天的上午8点到11点的第3和第15分钟执行 98 | 命令: 99 | 3,15 8-11 */2 * * command 100 | 101 | ### 实例5:每个星期一的上午8点到11点的第3和第15分钟执行 102 | 命令: 103 | 3,15 8-11 * * 1 command 104 | 105 | ### 实例6:每晚的21:30重启smb 106 | 命令: 107 | 30 21 * * * /etc/init.d/smb restart 108 | 109 | ### 实例7:每月1、10、22日的4 : 45重启smb 110 | 命令: 111 | 45 4 1,10,22 * * /etc/init.d/smb restart 112 | 113 | ### 实例8:每周六、周日的1 : 10重启smb 114 | 命令: 115 | 10 1 * * 6,0 /etc/init.d/smb restart 116 | 117 | ### 实例9:每天18 : 00至23 : 00之间每隔30分钟重启smb 118 | 命令: 119 | 0,30 18-23 * * * /etc/init.d/smb restart 120 | 121 | ### 实例10:每星期六的晚上11 : 00 pm重启smb 122 | 命令: 123 | 0 23 * * 6 /etc/init.d/smb restart 124 | 125 | ### 实例11:每一小时重启smb 126 | 命令: 127 | * */1 * * * /etc/init.d/smb restart 128 | 129 | ### 实例12:晚上11点到早上7点之间,每隔一小时重启smb 130 | 命令: 131 | 0 23-7 * * * /etc/init.d/smb restart 132 | 133 | ### 实例13:每月的4号与每周一到周三的11点重启smb 134 | 命令: 135 | 0 11 4 * mon-wed /etc/init.d/smb restart 136 | 137 | ### 实例14:一月一号的4点重启smb 138 | 命令: 139 | 0 4 1 jan * /etc/init.d/smb restart 140 | 141 | ### 实例15:每小时执行/etc/cron.hourly目录内的脚本 142 | 命令: 143 | 01 * * * * root run-parts /etc/cron.hourly 144 | 说明: 145 | run-parts这个参数了,如果去掉这个参数的话,后面就可以写要运行的某个脚本名,而不是目录名了 146 | 147 | ## 使用注意事项 148 | ### 注意环境变量问题 149 | 有时我们创建了一个crontab,但是这个任务却无法自动执行,而手动执行这个任务却没有问题,这种情况一般是由于在crontab文件中没有配置环境变量引起的。 150 | 在crontab文件中定义多个调度任务时,需要特别注意的一个问题就是环境变量的设置,因为我们手动执行某个任务时,是在当前shell环境下进行的,程序当然能找到环境变量,而系统自动执行任务调度时,是不会加载任何环境变量的,因此,就需要在crontab文件中指定任务运行所需的所有环境变量,这样,系统执行任务调度时就没有问题了。 151 | 不要假定cron知道所需要的特殊环境,它其实并不知道。所以你要保证在shelll脚本中提供所有必要的路径和环境变量,除了一些自动设置的全局变量。所以注意如下3点: 152 | 1)脚本中涉及文件路径时写全局路径; 153 | 2)脚本执行要用到java或其他环境变量时,通过source命令引入环境变量,如: 154 | cat start_cbp.sh 155 | #!/bin/sh 156 | source /etc/profile 157 | export RUN_CONF=/home/d139/conf/platform/cbp/cbp_jboss.conf 158 | /usr/local/jboss-4.0.5/bin/run.sh -c mev & 159 | 3)当手动执行脚本OK,但是crontab死活不执行时。这时必须大胆怀疑是环境变量惹的祸,并可以尝试在crontab中直接引入环境变量解决问题。如: 160 | 0 * * * * . /etc/profile;/bin/sh /var/www/java/audit_no_count/bin/restart_audit.sh 161 | 162 | ### 注意清理系统用户的邮件日志 163 | 每条任务调度执行完毕,系统都会将任务输出信息通过电子邮件的形式发送给当前系统用户,这样日积月累,日志信息会非常大,可能会影响系统的正常运行,因此,将每条任务进行重定向处理非常重要。 164 | 例如,可以在crontab文件中设置如下形式,忽略日志输出: 165 | 0 */3 * * * /usr/local/apache2/apachectl restart >/dev/null 2>&1 166 | “/dev/null 2>&1”表示先将标准输出重定向到/dev/null,然后将标准错误重定向到标准输出,由于标准输出已经重定向到了/dev/null,因此标准错误也会重定向到/dev/null,这样日志输出问题就解决了。 167 | 168 | ### 系统级任务调度与用户级任务调度 169 | 系统级任务调度主要完成系统的一些维护操作,用户级任务调度主要完成用户自定义的一些任务,可以将用户级任务调度放到系统级任务调度来完成(不建议这么做),但是反过来却不行,root用户的任务调度操作可以通过“crontab –uroot –e”来设置,也可以将调度任务直接写入/etc/crontab文件,需要注意的是,如果要定义一个定时重启系统的任务,就必须将任务放到/etc/crontab文件,即使在root用户下创建一个定时重启系统的任务也是无效的。 170 | 171 | ### 其他注意事项 172 | 新创建的cron job,不会马上执行,至少要过2分钟才执行。如果重启cron则马上执行。 173 | 当crontab突然失效时,可以尝试/etc/init.d/crond restart解决问题。或者查看日志看某个job有没有执行/报错tail -f /var/log/cron。 174 | 千万别乱运行crontab -r。它从Crontab目录(/var/spool/cron)中删除用户的Crontab文件。删除了该用户的所有crontab都没了。 175 | 在crontab中%是有特殊含义的,表示换行的意思。如果要用的话必须进行转义\%,如经常用的date ‘+%Y%m%d’在crontab里是不会执行的,应该换成date ‘+\%Y\%m\%d’。 176 | -------------------------------------------------------------------------------- /der-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/der-master.zip -------------------------------------------------------------------------------- /der/README.rst: -------------------------------------------------------------------------------- 1 | DER 2 | ===================== 3 | 4 | ``DER == reverse("RED")`` 5 | 6 | 本项目是 `《Redis 设计与实现》 `_ 所使用的 Sphinx 样式。 7 | 8 | 样式特点: 9 | 10 | - 单色调简单风格(默认为红色,但很容易就可以修改成其他颜色) 11 | 12 | - 醒目的 ``h1`` 标题 13 | 14 | - 清晰的、可以高效地对文本进行视线分割的 ``h2`` 标题 15 | 16 | - 固定大小、居中显示、百分比字体大小,布局健壮,适用于多种不同的屏幕环境 17 | 18 | 19 | 使用方法 20 | --------------------- 21 | 22 | 1. 克隆本项目。 23 | 24 | 2. 修改 sphinx 项目 ``conf.py`` 文件中的 ``html_theme_path`` 变量,让它指向 ``der`` 文件夹所在的位置。 25 | 26 | 3. 修改 sphinx 项目 ``conf.py`` 文件中的 ``html_theme`` 变量的值为 ``der`` 。 27 | 28 | 4. 完成! 29 | 30 | 31 | 开启 disqus 支持 32 | --------------------- 33 | 34 | 1. 编辑 ``der`` 文件夹中的 ``layout.html`` 文件,修改文件中和 disqus 有关的语句: 35 | 36 | :: 37 | 38 | {# note: remove this comment if you want to enable disqus support 39 | 40 | {% include "disqus.html" %} 41 | 42 | #} 43 | 44 | 只保留这一句: 45 | 46 | :: 47 | 48 | {% include "disqus.html" %} 49 | 50 | 2. 编辑 ``der`` 文件夹中的 ``disqus.html`` 文件,将其中的 51 | 52 | :: 53 | 54 | var disqus_shortname = 'YOUR-DISQUS-FORUM-SHORTNAME'; 55 | 56 | 中的 ``YOUR-DISQUS-FORUM-SHORTNAME`` 替换成你的 disqus 论坛的名字。 57 | 58 | 3. 完成! 59 | 60 | 61 | 使用许可 62 | --------------------- 63 | 64 | 本样式修改自 `Sphinx `_ 项目自带的 pyramid 样式, 65 | 使用与源项目同样的 BSD 协议发布。 66 | 67 | | Copyright (c) 2013, huangz 68 | | All rights reserved. 69 | 70 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 71 | 72 | - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 73 | 74 | - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 75 | 76 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 77 | -------------------------------------------------------------------------------- /der/disqus.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

4 | 讨论 5 | 6 |

7 | 8 |
9 | 20 | 21 | comments powered by Disqus 22 |
23 | 24 | 35 | -------------------------------------------------------------------------------- /der/layout.html: -------------------------------------------------------------------------------- 1 | {# 2 | basic/layout.html 3 | ~~~~~~~~~~~~~~~~~ 4 | 5 | Master layout template for Sphinx themes. 6 | 7 | :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 | {%- block doctype -%} 11 | 13 | {%- endblock %} 14 | {%- set reldelim1 = reldelim1 is not defined and ' »' or reldelim1 %} 15 | {%- set reldelim2 = reldelim2 is not defined and ' |' or reldelim2 %} 16 | {%- set render_sidebar = (not embedded) and (not theme_nosidebar|tobool) and 17 | (sidebars != []) %} 18 | {%- set url_root = pathto('', 1) %} 19 | {# XXX necessary? #} 20 | {%- if url_root == '#' %}{% set url_root = '' %}{% endif %} 21 | {%- if not embedded and docstitle %} 22 | {%- set titlesuffix = " — "|safe + docstitle|e %} 23 | {%- else %} 24 | {%- set titlesuffix = "" %} 25 | {%- endif %} 26 | 27 | {%- macro relbar() %} 28 | 46 | {%- endmacro %} 47 | 48 | {%- macro sidebar() %}{%- endmacro %} 49 | 50 | {%- macro script() %} 51 | 60 | {%- for scriptfile in script_files %} 61 | 62 | {%- endfor %} 63 | {%- endmacro %} 64 | 65 | {%- macro css() %} 66 | 67 | 68 | {%- for cssfile in css_files %} 69 | 70 | {%- endfor %} 71 | {%- endmacro %} 72 | 73 | 74 | 75 | 76 | {{ metatags }} 77 | {%- block htmltitle %} 78 | {{ title|striptags|e }}{{ titlesuffix }} 79 | {%- endblock %} 80 | {{ css() }} 81 | {%- if not embedded %} 82 | {{ script() }} 83 | {%- if use_opensearch %} 84 | 87 | {%- endif %} 88 | {%- if favicon %} 89 | 90 | {%- endif %} 91 | {%- endif %} 92 | {%- block linktags %} 93 | {%- if hasdoc('about') %} 94 | 95 | {%- endif %} 96 | {%- if hasdoc('genindex') %} 97 | 98 | {%- endif %} 99 | {%- if hasdoc('search') %} 100 | 101 | {%- endif %} 102 | {%- if hasdoc('copyright') %} 103 | 104 | {%- endif %} 105 | 106 | {%- if parents %} 107 | 108 | {%- endif %} 109 | {%- if next %} 110 | 111 | {%- endif %} 112 | {%- if prev %} 113 | 114 | {%- endif %} 115 | {%- endblock %} 116 | {%- block extrahead %} 117 | 118 | 121 | 122 | {% endblock %} 123 | 124 | 125 | {%- block header %} 126 | {%- if logo %} 127 |
128 | 133 |
134 | {%- endif %} 135 | 136 | {% endblock %} 137 | 138 | {%- block relbar1 %}{{ relbar() }}{% endblock %} 139 | 140 | {%- block content %} 141 | {%- block sidebar1 %} {# possible location for sidebar #} {% endblock %} 142 | 143 |
144 | {%- block document %} 145 |
146 | {%- if render_sidebar %} 147 |
148 | {%- endif %} 149 |
150 | {% block body %} {% endblock %} 151 | 152 | {% include "disqus.html" %} 153 | 154 |
155 | {%- if render_sidebar %} 156 |
157 | {%- endif %} 158 |
159 | {%- endblock %} 160 | 161 | {%- block sidebar2 %}{{ sidebar() }}{% endblock %} 162 |
163 |
164 | {%- endblock %} 165 | 166 | {%- block relbar2 %}{{ relbar() }}{% endblock %} 167 | 168 | {%- block footer %} 169 | 184 | {%- endblock %} 185 | 186 | 187 | -------------------------------------------------------------------------------- /der/static/42qu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/der/static/42qu.png -------------------------------------------------------------------------------- /der/static/dialog-note.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/der/static/dialog-note.png -------------------------------------------------------------------------------- /der/static/dialog-seealso.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/der/static/dialog-seealso.png -------------------------------------------------------------------------------- /der/static/dialog-topic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/der/static/dialog-topic.png -------------------------------------------------------------------------------- /der/static/dialog-warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/der/static/dialog-warning.png -------------------------------------------------------------------------------- /der/static/epub.css: -------------------------------------------------------------------------------- 1 | /* 2 | * default.css_t 3 | * ~~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- default theme. 6 | * 7 | * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | @import url("basic.css"); 13 | 14 | /* -- page layout ----------------------------------------------------------- */ 15 | 16 | body { 17 | font-family: {{ theme_bodyfont }}; 18 | font-size: 100%; 19 | background-color: {{ theme_footerbgcolor }}; 20 | color: #000; 21 | margin: 0; 22 | padding: 0; 23 | } 24 | 25 | div.document { 26 | background-color: {{ theme_sidebarbgcolor }}; 27 | } 28 | 29 | div.documentwrapper { 30 | float: left; 31 | width: 100%; 32 | } 33 | 34 | div.bodywrapper { 35 | margin: 0 0 0 230px; 36 | } 37 | 38 | div.body { 39 | background-color: {{ theme_bgcolor }}; 40 | color: {{ theme_textcolor }}; 41 | padding: 0 20px 30px 20px; 42 | } 43 | 44 | {%- if theme_rightsidebar|tobool %} 45 | div.bodywrapper { 46 | margin: 0 230px 0 0; 47 | } 48 | {%- endif %} 49 | 50 | div.footer { 51 | color: {{ theme_footertextcolor }}; 52 | width: 100%; 53 | padding: 9px 0 9px 0; 54 | text-align: center; 55 | font-size: 75%; 56 | } 57 | 58 | div.footer a { 59 | color: {{ theme_footertextcolor }}; 60 | text-decoration: underline; 61 | } 62 | 63 | div.related { 64 | background-color: {{ theme_relbarbgcolor }}; 65 | line-height: 30px; 66 | color: {{ theme_relbartextcolor }}; 67 | } 68 | 69 | div.related a { 70 | color: {{ theme_relbarlinkcolor }}; 71 | } 72 | 73 | div.sphinxsidebar { 74 | {%- if theme_stickysidebar|tobool %} 75 | top: 30px; 76 | bottom: 0; 77 | margin: 0; 78 | position: fixed; 79 | overflow: auto; 80 | height: auto; 81 | {%- endif %} 82 | {%- if theme_rightsidebar|tobool %} 83 | float: right; 84 | {%- if theme_stickysidebar|tobool %} 85 | right: 0; 86 | {%- endif %} 87 | {%- endif %} 88 | } 89 | 90 | {%- if theme_stickysidebar|tobool %} 91 | /* this is nice, but it it leads to hidden headings when jumping 92 | to an anchor */ 93 | /* 94 | div.related { 95 | position: fixed; 96 | } 97 | 98 | div.documentwrapper { 99 | margin-top: 30px; 100 | } 101 | */ 102 | {%- endif %} 103 | 104 | div.sphinxsidebar h3 { 105 | font-family: {{ theme_headfont }}; 106 | color: {{ theme_sidebartextcolor }}; 107 | font-size: 1.4em; 108 | font-weight: normal; 109 | margin: 0; 110 | padding: 0; 111 | } 112 | 113 | div.sphinxsidebar h3 a { 114 | color: {{ theme_sidebartextcolor }}; 115 | } 116 | 117 | div.sphinxsidebar h4 { 118 | font-family: {{ theme_headfont }}; 119 | color: {{ theme_sidebartextcolor }}; 120 | font-size: 1.3em; 121 | font-weight: normal; 122 | margin: 5px 0 0 0; 123 | padding: 0; 124 | } 125 | 126 | div.sphinxsidebar p { 127 | color: {{ theme_sidebartextcolor }}; 128 | } 129 | 130 | div.sphinxsidebar p.topless { 131 | margin: 5px 10px 10px 10px; 132 | } 133 | 134 | div.sphinxsidebar ul { 135 | margin: 10px; 136 | padding: 0; 137 | color: {{ theme_sidebartextcolor }}; 138 | } 139 | 140 | div.sphinxsidebar a { 141 | color: {{ theme_sidebarlinkcolor }}; 142 | } 143 | 144 | div.sphinxsidebar input { 145 | border: 1px solid {{ theme_sidebarlinkcolor }}; 146 | font-family: sans-serif; 147 | font-size: 1em; 148 | } 149 | 150 | {% if theme_collapsiblesidebar|tobool %} 151 | /* for collapsible sidebar */ 152 | div#sidebarbutton { 153 | background-color: {{ theme_sidebarbtncolor }}; 154 | } 155 | {% endif %} 156 | 157 | /* -- hyperlink styles ------------------------------------------------------ */ 158 | 159 | a { 160 | color: {{ theme_linkcolor }}; 161 | text-decoration: none; 162 | } 163 | 164 | a:visited { 165 | color: {{ theme_visitedlinkcolor }}; 166 | text-decoration: none; 167 | } 168 | 169 | a:hover { 170 | text-decoration: underline; 171 | } 172 | 173 | {% if theme_externalrefs|tobool %} 174 | a.external { 175 | text-decoration: none; 176 | border-bottom: 1px dashed {{ theme_linkcolor }}; 177 | } 178 | 179 | a.external:hover { 180 | text-decoration: none; 181 | border-bottom: none; 182 | } 183 | 184 | a.external:visited { 185 | text-decoration: none; 186 | border-bottom: 1px dashed {{ theme_visitedlinkcolor }}; 187 | } 188 | {% endif %} 189 | 190 | /* -- body styles ----------------------------------------------------------- */ 191 | 192 | div.body h1, 193 | div.body h2, 194 | div.body h3, 195 | div.body h4, 196 | div.body h5, 197 | div.body h6 { 198 | font-family: {{ theme_headfont }}; 199 | background-color: {{ theme_headbgcolor }}; 200 | font-weight: normal; 201 | color: {{ theme_headtextcolor }}; 202 | border-bottom: 1px solid #ccc; 203 | margin: 20px -20px 10px -20px; 204 | padding: 3px 0 3px 10px; 205 | } 206 | 207 | div.body h1 { margin-top: 0; font-size: 200%; } 208 | div.body h2 { font-size: 160%; } 209 | div.body h3 { font-size: 140%; } 210 | div.body h4 { font-size: 120%; } 211 | div.body h5 { font-size: 110%; } 212 | div.body h6 { font-size: 100%; } 213 | 214 | a.headerlink { 215 | color: {{ theme_headlinkcolor }}; 216 | font-size: 0.8em; 217 | padding: 0 4px 0 4px; 218 | text-decoration: none; 219 | } 220 | 221 | a.headerlink:hover { 222 | background-color: {{ theme_headlinkcolor }}; 223 | color: white; 224 | } 225 | 226 | div.body p, div.body dd, div.body li { 227 | text-align: justify; 228 | line-height: 130%; 229 | } 230 | 231 | div.admonition p.admonition-title + p { 232 | display: inline; 233 | } 234 | 235 | div.admonition p { 236 | margin-bottom: 5px; 237 | } 238 | 239 | div.admonition pre { 240 | margin-bottom: 5px; 241 | } 242 | 243 | div.admonition ul, div.admonition ol { 244 | margin-bottom: 5px; 245 | } 246 | 247 | div.note { 248 | background-color: #eee; 249 | border: 1px solid #ccc; 250 | } 251 | 252 | div.seealso { 253 | background-color: #ffc; 254 | border: 1px solid #ff6; 255 | } 256 | 257 | div.topic { 258 | background-color: #eee; 259 | } 260 | 261 | div.warning { 262 | background-color: #ffe4e4; 263 | border: 1px solid #f66; 264 | } 265 | 266 | p.admonition-title { 267 | display: inline; 268 | } 269 | 270 | p.admonition-title:after { 271 | content: ":"; 272 | } 273 | 274 | pre { 275 | padding: 5px; 276 | background-color: {{ theme_codebgcolor }}; 277 | color: {{ theme_codetextcolor }}; 278 | line-height: 120%; 279 | border: 1px solid #ac9; 280 | border-left: none; 281 | border-right: none; 282 | } 283 | 284 | tt { 285 | background-color: #ecf0f3; 286 | padding: 0 1px 0 1px; 287 | font-size: 0.95em; 288 | } 289 | 290 | th { 291 | background-color: #ede; 292 | } 293 | 294 | .warning tt { 295 | background: #efc2c2; 296 | } 297 | 298 | .note tt { 299 | background: #d6d6d6; 300 | } 301 | 302 | .viewcode-back { 303 | font-family: {{ theme_bodyfont }}; 304 | } 305 | 306 | div.viewcode-block:target { 307 | background-color: #f4debf; 308 | border-top: 1px solid #ac9; 309 | border-bottom: 1px solid #ac9; 310 | } 311 | -------------------------------------------------------------------------------- /der/static/footerbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/der/static/footerbg.png -------------------------------------------------------------------------------- /der/static/headerbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/der/static/headerbg.png -------------------------------------------------------------------------------- /der/static/ie6.css: -------------------------------------------------------------------------------- 1 | * html img, 2 | * html .png{position:relative;behavior:expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none", 3 | this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "',sizingMethod='image')", 4 | this.src = "_static/transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''), 5 | this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "',sizingMethod='crop')", 6 | this.runtimeStyle.backgroundImage = "none")),this.pngSet=true) 7 | );} 8 | -------------------------------------------------------------------------------- /der/static/me115_com.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/der/static/me115_com.jpg -------------------------------------------------------------------------------- /der/static/middlebg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/der/static/middlebg.png -------------------------------------------------------------------------------- /der/static/transparent.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/der/static/transparent.gif -------------------------------------------------------------------------------- /der/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = pyramid.css 4 | pygments_style = sphinx.pygments_styles.PyramidStyle 5 | 6 | [options] 7 | color = #6f9f3f 8 | # color = #C52F24 9 | -------------------------------------------------------------------------------- /index.rst: -------------------------------------------------------------------------------- 1 | ========== 2 | Linux工具快速教程 3 | ========== 4 | 5 | .. include:: _version.inc 6 | 7 | 前言 8 | ---- 9 | 10 | Linux下有很多命令行工具供我们使用,每个工具总是提供了大量参数供我们选择; 11 | 实际工作中,我们用到的工具,最常用的总是那么几个参数组合; 12 | 为此,我写了这本书相对实用的书; 13 | 14 | 这本书专注于Linux工具的最常用用法,以便读者能以最快时间掌握,并在工作中应用; 15 | 16 | 说明 17 | ^^^^^^^^^^^^^^^^^^^^ 18 | 19 | 全书分为三个部分: 20 | 21 | - 第一部分为基础篇,介绍我们工作中常用的工具的高频用法; 22 | - 第二部分为进阶篇,介绍的工具更多的适合程序员使用,分为程序构建、程序调试及程序优化; 23 | - 第三部分是工具参考篇,主要介绍实用工具的用法和实例;相比第一二部分,这里针对每个工具的介绍更全面; 24 | 25 | 同时,这个教程也可当作Linux命令手册使用,使用左边栏的目录和搜索栏可以很方便的查阅; 26 | 27 | 28 | 建议 29 | ^^^^^^^^^^^^^^^^^^^^ 30 | 1. 最好安装一个Linux系统(对于新手Ubuntu容易入门),将教程中的命令敲到bash中看看效果 31 | 2. 如果有兴趣,可以在了解之后立即查看相关更完备的内容 (比如查阅官方文档) 32 | 33 | 写作工具 34 | ^^^^^^^^^^^^^^^^^^^^ 35 | 本书使用的reStructuredText标记语言,相对Markdown来说,在写书方面更有优势: 36 | 37 | - 使用sphnix能够自动生成目录和索引文件,方便查询和检索; 38 | - 有大量漂亮的HTML书籍主题模版,可为书籍轻松换肤(类似Wordpress的网站模版); 39 | - 对于参考手册类书籍的编写在语法上更为便利(python官方帮助文档的使用者); 40 | 41 | 42 | 43 | ^^^^^^^^^^^^^^^^^^^^ 44 | 45 | 版权声明 46 | ^^^^^^^^^^^^^^^^^^^^^ 47 | .. note:: 48 | 本书为开源图书,版权归作者所有;欢迎下载及编辑(个人用途),但未经作者同意必须保留此段声明,且不可用于商业用途,否则保留追究法律责任的权利。 49 | 50 | - 作者:大CC 51 | - 博客:http://blog.me115.com 52 | - Github地址:https://github.com/me115/linuxtools_rst 53 | 54 | 55 | 目录 56 | ---- 57 | 58 | .. toctree:: 59 | :maxdepth: 2 60 | :glob: 61 | 62 | base/index 63 | advance/index 64 | tool/index 65 | 66 | 67 | Indices and tables 68 | ================== 69 | 70 | * :ref:`genindex` 71 | * :ref:`modindex` 72 | * :ref:`search` 73 | 74 | -------------------------------------------------------------------------------- /make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\linuxtools.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\linuxtools.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end 243 | -------------------------------------------------------------------------------- /md2rst.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | #coding=utf-8 3 | # markdown文件转换为rst文件 4 | #author: colin 8/14/2014 5 | import os,sys,re,traceback 6 | 7 | 8 | class Md2rstConvertor: 9 | 10 | #change 11 | def convert(self,filename): 12 | lines = [] 13 | isCodeLine = False 14 | datafile = open(filename,"r") 15 | for line in datafile: 16 | # 识别代码段 17 | m = re.match(r'`{3}[ ]*',line) 18 | if m is not None: 19 | if isCodeLine == False: 20 | lines.append('::\n\n') 21 | isCodeLine = True 22 | else: 23 | isCodeLine = False # code块结束 24 | lines.append('\n') 25 | continue 26 | 27 | if isCodeLine == True: 28 | lines.append('\t' + line.strip() + '\n') 29 | continue 30 | else: 31 | # 识别一级标题 32 | m = re.match(r'[ ]*#{1}[^#]+',line) 33 | if m is not None: 34 | lines.append(line.strip('# \r\n') + '\n') 35 | lines.append('=' * len(line) + '\n') 36 | continue 37 | 38 | # 识别二级标题 39 | m = re.match(r'[ ]*#{2}[^#]+',line) 40 | if m is not None: 41 | lines.append(line.strip('# \r\n') + '\n') 42 | lines.append('-' * len(line) + '\n') 43 | continue 44 | 45 | # 识别三级标题 46 | m = re.match(r'[ ]*#{3}[^#]+',line) 47 | if m is not None: 48 | lines.append(line.strip('# \r\n') + '\n') 49 | lines.append('~' * len(line) + '\n') 50 | continue 51 | 52 | lines.append(line.strip() + '\n') 53 | 54 | 55 | 56 | rstFile = '%s.rst' % filename.split('.')[0] 57 | fw = open(rstFile,'w') 58 | for str in lines: 59 | fw.writelines(str ) 60 | fw.close() 61 | 62 | 63 | 64 | if __name__ == '__main__': 65 | 66 | convertor = Md2rstConvertor() 67 | try: 68 | if len(sys.argv) <= 1: 69 | print "please input file name to convert :('all' for all file in cur dir)" 70 | exit() 71 | 72 | arg = sys.argv[1] 73 | if arg == 'all': 74 | # 转换当前文件夹下所有md文件 75 | for filename in os.listdir('./'): 76 | if os.path.isfile(filename): # 过滤文件夹 77 | fix = filename.split('.')[-1] 78 | if fix.upper() == "MD" : 79 | convertor.convert(filename) 80 | else: 81 | convertor.convert(arg) 82 | 83 | except Exception, ex: 84 | 85 | exc = traceback.format_exc() 86 | sys.stderr.write("trace =%s \n" % exc) 87 | sys.stderr.write("ex=%s \n" % str(ex)) 88 | -------------------------------------------------------------------------------- /sphinx_rtd_theme-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme-master.zip -------------------------------------------------------------------------------- /sphinx_rtd_theme/__init__.py: -------------------------------------------------------------------------------- 1 | """Sphinx ReadTheDocs theme. 2 | 3 | From https://github.com/ryan-roemer/sphinx-bootstrap-theme. 4 | 5 | """ 6 | import os 7 | 8 | VERSION = (0, 1, 5) 9 | 10 | __version__ = ".".join(str(v) for v in VERSION) 11 | __version_full__ = __version__ 12 | 13 | 14 | def get_html_theme_path(): 15 | """Return list of HTML theme paths.""" 16 | cur_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) 17 | return cur_dir 18 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/breadcrumbs.html: -------------------------------------------------------------------------------- 1 |
2 | 18 |
19 |
20 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/disqus.html: -------------------------------------------------------------------------------- 1 | 24 |
25 |
26 | 27 |

28 | 讨论 29 | 30 |

31 | 32 |
33 | 44 | 45 | comments powered by Disqus 46 |
47 | 48 | 55 |
56 |
57 | 58 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/footer.html: -------------------------------------------------------------------------------- 1 |
2 | {% if next or prev %} 3 | 11 | {% endif %} 12 | 13 | 14 |
15 | {% include "disqus.html" %} 16 |
17 | 18 |
19 |

20 | {%- if show_copyright %} 21 | {%- if hasdoc('copyright') %} 22 | {% trans path=pathto('copyright'), copyright=copyright|e %}© Copyright {{ copyright }}.{% endtrans %} 23 | {%- else %} 24 | {% trans copyright=copyright|e %}© Copyright {{ copyright }}.{% endtrans %} 25 | {%- endif %} 26 | {%- endif %} 27 | 28 | {%- if last_updated %} 29 | {% trans last_updated=last_updated|e %}Last updated on {{ last_updated }}.{% endtrans %} 30 | {%- endif %} 31 |

32 |
33 | 34 | {% trans %}Sphinx theme provided by Read the Docs{% endtrans %} 35 |
36 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/layout - 副本.html: -------------------------------------------------------------------------------- 1 | {# TEMPLATE VAR SETTINGS #} 2 | {%- set url_root = pathto('', 1) %} 3 | {%- if url_root == '#' %}{% set url_root = '' %}{% endif %} 4 | {%- if not embedded and docstitle %} 5 | {%- set titlesuffix = " — "|safe + docstitle|e %} 6 | {%- else %} 7 | {%- set titlesuffix = "" %} 8 | {%- endif %} 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | {% block htmltitle %} 17 | {{ title|striptags|e }}{{ titlesuffix }} 18 | {% endblock %} 19 | 20 | {# FAVICON #} 21 | {% if favicon %} 22 | 23 | {% endif %} 24 | 25 | {# CSS #} 26 | 27 | {# OPENSEARCH #} 28 | {% if not embedded %} 29 | {% if use_opensearch %} 30 | 31 | {% endif %} 32 | 33 | {% endif %} 34 | 35 | {# RTD hosts this file, so just load on non RTD builds #} 36 | {% if not READTHEDOCS %} 37 | 38 | {% endif %} 39 | 40 | {% for cssfile in css_files %} 41 | 42 | {% endfor %} 43 | 44 | {%- block linktags %} 45 | {%- if hasdoc('about') %} 46 | 48 | {%- endif %} 49 | {%- if hasdoc('genindex') %} 50 | 52 | {%- endif %} 53 | {%- if hasdoc('search') %} 54 | 55 | {%- endif %} 56 | {%- if hasdoc('copyright') %} 57 | 58 | {%- endif %} 59 | 60 | {%- if parents %} 61 | 62 | {%- endif %} 63 | {%- if next %} 64 | 65 | {%- endif %} 66 | {%- if prev %} 67 | 68 | {%- endif %} 69 | {%- endblock %} 70 | {%- block extrahead %} {% endblock %} 71 | 72 | {# Keep modernizr in head - http://modernizr.com/docs/#installing #} 73 | 74 | 75 | 76 | 77 | 78 | 79 |
80 | 81 | {# SIDE NAV, TOGGLES ON MOBILE #} 82 | 101 | 102 |
103 | 104 | {# MOBILE NAV, TRIGGLES SIDE NAV ON TOGGLE #} 105 | 109 | 110 | 111 | {# PAGE CONTENT #} 112 | 113 |
114 |
115 | {% include "breadcrumbs.html" %} 116 |
117 | {% block body %}{% endblock %} 118 |
119 | 120 | {% include "footer.html" %} 121 |
122 |
123 | 124 |
125 | 126 |
127 | 128 | {% include "versions.html" %} 129 | 130 | {% if not embedded %} 131 | 132 | 141 | {%- for scriptfile in script_files %} 142 | 143 | {%- endfor %} 144 | 145 | {% endif %} 146 | 147 | {# RTD hosts this file, so just load on non RTD builds #} 148 | {% if not READTHEDOCS %} 149 | 150 | {% endif %} 151 | 152 | {# STICKY NAVIGATION #} 153 | {% if theme_sticky_navigation %} 154 | 159 | {% endif %} 160 | 161 | {%- block footer %} {% endblock %} 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/layout.html: -------------------------------------------------------------------------------- 1 | {# TEMPLATE VAR SETTINGS #} 2 | {%- set url_root = pathto('', 1) %} 3 | {%- if url_root == '#' %}{% set url_root = '' %}{% endif %} 4 | {%- if not embedded and docstitle %} 5 | {%- set titlesuffix = " — "|safe + docstitle|e %} 6 | {%- else %} 7 | {%- set titlesuffix = "" %} 8 | {%- endif %} 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | {% block htmltitle %} 17 | {{ title|striptags|e }}{{ titlesuffix }} 18 | {% endblock %} 19 | 20 | {# FAVICON #} 21 | {% if favicon %} 22 | 23 | {% endif %} 24 | 25 | {# CSS #} 26 | 27 | {# OPENSEARCH #} 28 | {% if not embedded %} 29 | {% if use_opensearch %} 30 | 31 | {% endif %} 32 | 33 | {% endif %} 34 | 35 | {# RTD hosts this file, so just load on non RTD builds #} 36 | {% if not READTHEDOCS %} 37 | 38 | {% endif %} 39 | 40 | {% for cssfile in css_files %} 41 | 42 | {% endfor %} 43 | 44 | {%- block linktags %} 45 | {%- if hasdoc('about') %} 46 | 48 | {%- endif %} 49 | {%- if hasdoc('genindex') %} 50 | 52 | {%- endif %} 53 | {%- if hasdoc('search') %} 54 | 55 | {%- endif %} 56 | {%- if hasdoc('copyright') %} 57 | 58 | {%- endif %} 59 | 60 | {%- if parents %} 61 | 62 | {%- endif %} 63 | {%- if next %} 64 | 65 | {%- endif %} 66 | {%- if prev %} 67 | 68 | {%- endif %} 69 | {%- endblock %} 70 | {%- block extrahead %} {% endblock %} 71 | 72 | {# Keep modernizr in head - http://modernizr.com/docs/#installing #} 73 | 74 | 75 | 76 | 77 | 78 | 79 |
80 | 81 | {# SIDE NAV, TOGGLES ON MOBILE #} 82 | 101 | 102 |
103 | 104 | {# MOBILE NAV, TRIGGLES SIDE NAV ON TOGGLE #} 105 | 109 | 110 | 111 | {# PAGE CONTENT #} 112 | 113 |
114 |
115 | {% include "breadcrumbs.html" %} 116 |
117 | {% block body %}{% endblock %} 118 |
119 | 120 | {% include "footer.html" %} 121 |
122 |
123 | 124 |
125 | 126 |
127 | 128 | {% include "versions.html" %} 129 | 130 | {% if not embedded %} 131 | 132 | 141 | {%- for scriptfile in script_files %} 142 | 143 | {%- endfor %} 144 | 145 | {% endif %} 146 | 147 | {# RTD hosts this file, so just load on non RTD builds #} 148 | {% if not READTHEDOCS %} 149 | 150 | {% endif %} 151 | 152 | {# STICKY NAVIGATION #} 153 | {% if theme_sticky_navigation %} 154 | 159 | {% endif %} 160 | 161 | {%- block footer %} {% endblock %} 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/search.html: -------------------------------------------------------------------------------- 1 | {# 2 | basic/search.html 3 | ~~~~~~~~~~~~~~~~~ 4 | 5 | Template for the search page. 6 | 7 | :copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 | {%- extends "layout.html" %} 11 | {% set title = _('Search') %} 12 | {% set script_files = script_files + ['_static/searchtools.js'] %} 13 | {% block footer %} 14 | 17 | {# this is used when loading the search index using $.ajax fails, 18 | such as on Chrome for documents on localhost #} 19 | 20 | {{ super() }} 21 | {% endblock %} 22 | {% block body %} 23 | 31 | 32 | {% if search_performed %} 33 |

{{ _('Search Results') }}

34 | {% if not search_results %} 35 |

{{ _('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.') }}

36 | {% endif %} 37 | {% endif %} 38 |
39 | {% if search_results %} 40 |
    41 | {% for href, caption, context in search_results %} 42 |
  • 43 | {{ caption }} 44 |

    {{ context|e }}

    45 |
  • 46 | {% endfor %} 47 |
48 | {% endif %} 49 |
50 | {% endblock %} 51 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/searchbox.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 5 | 6 |
7 |
8 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .fa:before{-webkit-font-smoothing:antialiased}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-weight:normal;font-style:normal;src:url("../font/fontawesome_webfont.eot");src:url("../font/fontawesome_webfont.eot?#iefix") format("embedded-opentype"),url("../font/fontawesome_webfont.woff") format("woff"),url("../font/fontawesome_webfont.ttf") format("truetype"),url("../font/fontawesome_webfont.svg#FontAwesome") format("svg")}.fa:before{display:inline-block;font-family:FontAwesome;font-style:normal;font-weight:normal;line-height:1;text-decoration:inherit}a .fa{display:inline-block;text-decoration:inherit}li .fa{display:inline-block}li .fa-large:before,li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-0.8em}ul.fas li .fa{width:0.8em}ul.fas li .fa-large:before,ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before{content:""}.icon-book:before{content:""}.fa-caret-down:before{content:""}.icon-caret-down:before{content:""}.fa-caret-up:before{content:""}.icon-caret-up:before{content:""}.fa-caret-left:before{content:""}.icon-caret-left:before{content:""}.fa-caret-right:before{content:""}.icon-caret-right:before{content:""}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;border-top:solid 10px #343131;font-family:"Lato","proxima-nova","Helvetica Neue",Arial,sans-serif;z-index:400}.rst-versions a{color:#2980B9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27AE60;*zoom:1}.rst-versions .rst-current-version:before,.rst-versions .rst-current-version:after{display:table;content:""}.rst-versions .rst-current-version:after{clear:both}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book{float:left}.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#E74C3C;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#F1C40F;color:#000}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:gray;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:solid 1px #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px}.rst-versions.rst-badge .icon-book{float:none}.rst-versions.rst-badge .fa-book{float:none}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book{float:left}.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge .rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width: 768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}img{width:100%;height:auto}} 2 | /*# sourceMappingURL=badge_only.css.map */ 3 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/css/font_lato_googleapi.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Inconsolata'; 3 | font-style: normal; 4 | font-weight: 400; 5 | src: local('Inconsolata'), url(https://fonts.gstatic.com/s/inconsolata/v9/BjAYBlHtW3CJxDcjzrnZCIbN6UDyHWBl620a-IRfuBk.woff) format('woff'); 6 | } 7 | @font-face { 8 | font-family: 'Inconsolata'; 9 | font-style: normal; 10 | font-weight: 700; 11 | src: local('Inconsolata Bold'), local('Inconsolata-Bold'), url(https://fonts.gstatic.com/s/inconsolata/v9/AIed271kqQlcIRSOnQH0yTqR_3kx9_hJXbbyU8S6IN0.woff) format('woff'); 12 | } 13 | @font-face { 14 | font-family: 'Lato'; 15 | font-style: normal; 16 | font-weight: 400; 17 | src: local('Lato Regular'), local('Lato-Regular'), url(https://fonts.gstatic.com/s/lato/v10/9k-RPmcnxYEPm8CNFsH2gg.woff) format('woff'); 18 | } 19 | @font-face { 20 | font-family: 'Lato'; 21 | font-style: normal; 22 | font-weight: 700; 23 | src: local('Lato Bold'), local('Lato-Bold'), url(https://fonts.gstatic.com/s/lato/v10/wkfQbvfT_02e2IWO3yYueQ.woff) format('woff'); 24 | } 25 | @font-face { 26 | font-family: 'Lato'; 27 | font-style: italic; 28 | font-weight: 400; 29 | src: local('Lato Italic'), local('Lato-Italic'), url(https://fonts.gstatic.com/s/lato/v10/oUan5VrEkpzIazlUe5ieaA.woff) format('woff'); 30 | } 31 | @font-face { 32 | font-family: 'Lato'; 33 | font-style: italic; 34 | font-weight: 700; 35 | src: local('Lato Bold Italic'), local('Lato-BoldItalic'), url(https://fonts.gstatic.com/s/lato/v10/HkF_qI1x_noxlxhrhMQYED8E0i7KZn-EPnyo3HZu7kw.woff) format('woff'); 36 | } 37 | @font-face { 38 | font-family: 'Roboto Slab'; 39 | font-style: normal; 40 | font-weight: 400; 41 | src: local('Roboto Slab Regular'), local('RobotoSlab-Regular'), url(https://fonts.gstatic.com/s/robotoslab/v6/y7lebkjgREBJK96VQi37ZobN6UDyHWBl620a-IRfuBk.woff) format('woff'); 42 | } 43 | @font-face { 44 | font-family: 'Roboto Slab'; 45 | font-style: normal; 46 | font-weight: 700; 47 | src: local('Roboto Slab Bold'), local('RobotoSlab-Bold'), url(https://fonts.gstatic.com/s/robotoslab/v6/dazS1PrQQuCxC3iOAJFEJTqR_3kx9_hJXbbyU8S6IN0.woff) format('woff'); 48 | } 49 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/css/pyramid.css: -------------------------------------------------------------------------------- 1 | /* 2 | * pylons.css_t 3 | * ~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- pylons theme. 6 | * 7 | * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | body a:hover, body a:hover .pre, a .pre:hover{ 10 | color:white; 11 | background-color: {{ theme_color }}; 12 | } 13 | * 14 | */ 15 | #ad { 16 | float: right; 17 | width: 39%; 18 | } 19 | 20 | #discuss { 21 | float: left; 22 | width: 60%; 23 | } 24 | 25 | em { 26 | font-style: normal; 27 | } 28 | 29 | a, a .pre { 30 | color: {{ theme_color }}; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/dialog-note.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme/static/dialog-note.png -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/dialog-seealso.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme/static/dialog-seealso.png -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/dialog-topic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme/static/dialog-topic.png -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/dialog-warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme/static/dialog-warning.png -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/epub.css: -------------------------------------------------------------------------------- 1 | /* 2 | * default.css_t 3 | * ~~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- default theme. 6 | * 7 | * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | @import url("basic.css"); 13 | 14 | /* -- page layout ----------------------------------------------------------- */ 15 | 16 | body { 17 | font-family: {{ theme_bodyfont }}; 18 | font-size: 100%; 19 | background-color: {{ theme_footerbgcolor }}; 20 | color: #000; 21 | margin: 0; 22 | padding: 0; 23 | } 24 | 25 | div.document { 26 | background-color: {{ theme_sidebarbgcolor }}; 27 | } 28 | 29 | div.documentwrapper { 30 | float: left; 31 | width: 100%; 32 | } 33 | 34 | div.bodywrapper { 35 | margin: 0 0 0 230px; 36 | } 37 | 38 | div.body { 39 | background-color: {{ theme_bgcolor }}; 40 | color: {{ theme_textcolor }}; 41 | padding: 0 20px 30px 20px; 42 | } 43 | 44 | {%- if theme_rightsidebar|tobool %} 45 | div.bodywrapper { 46 | margin: 0 230px 0 0; 47 | } 48 | {%- endif %} 49 | 50 | div.footer { 51 | color: {{ theme_footertextcolor }}; 52 | width: 100%; 53 | padding: 9px 0 9px 0; 54 | text-align: center; 55 | font-size: 75%; 56 | } 57 | 58 | div.footer a { 59 | color: {{ theme_footertextcolor }}; 60 | text-decoration: underline; 61 | } 62 | 63 | div.related { 64 | background-color: {{ theme_relbarbgcolor }}; 65 | line-height: 30px; 66 | color: {{ theme_relbartextcolor }}; 67 | } 68 | 69 | div.related a { 70 | color: {{ theme_relbarlinkcolor }}; 71 | } 72 | 73 | div.sphinxsidebar { 74 | {%- if theme_stickysidebar|tobool %} 75 | top: 30px; 76 | bottom: 0; 77 | margin: 0; 78 | position: fixed; 79 | overflow: auto; 80 | height: auto; 81 | {%- endif %} 82 | {%- if theme_rightsidebar|tobool %} 83 | float: right; 84 | {%- if theme_stickysidebar|tobool %} 85 | right: 0; 86 | {%- endif %} 87 | {%- endif %} 88 | } 89 | 90 | {%- if theme_stickysidebar|tobool %} 91 | /* this is nice, but it it leads to hidden headings when jumping 92 | to an anchor */ 93 | /* 94 | div.related { 95 | position: fixed; 96 | } 97 | 98 | div.documentwrapper { 99 | margin-top: 30px; 100 | } 101 | */ 102 | {%- endif %} 103 | 104 | div.sphinxsidebar h3 { 105 | font-family: {{ theme_headfont }}; 106 | color: {{ theme_sidebartextcolor }}; 107 | font-size: 1.4em; 108 | font-weight: normal; 109 | margin: 0; 110 | padding: 0; 111 | } 112 | 113 | div.sphinxsidebar h3 a { 114 | color: {{ theme_sidebartextcolor }}; 115 | } 116 | 117 | div.sphinxsidebar h4 { 118 | font-family: {{ theme_headfont }}; 119 | color: {{ theme_sidebartextcolor }}; 120 | font-size: 1.3em; 121 | font-weight: normal; 122 | margin: 5px 0 0 0; 123 | padding: 0; 124 | } 125 | 126 | div.sphinxsidebar p { 127 | color: {{ theme_sidebartextcolor }}; 128 | } 129 | 130 | div.sphinxsidebar p.topless { 131 | margin: 5px 10px 10px 10px; 132 | } 133 | 134 | div.sphinxsidebar ul { 135 | margin: 10px; 136 | padding: 0; 137 | color: {{ theme_sidebartextcolor }}; 138 | } 139 | 140 | div.sphinxsidebar a { 141 | color: {{ theme_sidebarlinkcolor }}; 142 | } 143 | 144 | div.sphinxsidebar input { 145 | border: 1px solid {{ theme_sidebarlinkcolor }}; 146 | font-family: sans-serif; 147 | font-size: 1em; 148 | } 149 | 150 | {% if theme_collapsiblesidebar|tobool %} 151 | /* for collapsible sidebar */ 152 | div#sidebarbutton { 153 | background-color: {{ theme_sidebarbtncolor }}; 154 | } 155 | {% endif %} 156 | 157 | /* -- hyperlink styles ------------------------------------------------------ */ 158 | 159 | a { 160 | color: {{ theme_linkcolor }}; 161 | text-decoration: none; 162 | } 163 | 164 | a:visited { 165 | color: {{ theme_visitedlinkcolor }}; 166 | text-decoration: none; 167 | } 168 | 169 | a:hover { 170 | text-decoration: underline; 171 | } 172 | 173 | {% if theme_externalrefs|tobool %} 174 | a.external { 175 | text-decoration: none; 176 | border-bottom: 1px dashed {{ theme_linkcolor }}; 177 | } 178 | 179 | a.external:hover { 180 | text-decoration: none; 181 | border-bottom: none; 182 | } 183 | 184 | a.external:visited { 185 | text-decoration: none; 186 | border-bottom: 1px dashed {{ theme_visitedlinkcolor }}; 187 | } 188 | {% endif %} 189 | 190 | /* -- body styles ----------------------------------------------------------- */ 191 | 192 | div.body h1, 193 | div.body h2, 194 | div.body h3, 195 | div.body h4, 196 | div.body h5, 197 | div.body h6 { 198 | font-family: {{ theme_headfont }}; 199 | background-color: {{ theme_headbgcolor }}; 200 | font-weight: normal; 201 | color: {{ theme_headtextcolor }}; 202 | border-bottom: 1px solid #ccc; 203 | margin: 20px -20px 10px -20px; 204 | padding: 3px 0 3px 10px; 205 | } 206 | 207 | div.body h1 { margin-top: 0; font-size: 200%; } 208 | div.body h2 { font-size: 160%; } 209 | div.body h3 { font-size: 140%; } 210 | div.body h4 { font-size: 120%; } 211 | div.body h5 { font-size: 110%; } 212 | div.body h6 { font-size: 100%; } 213 | 214 | a.headerlink { 215 | color: {{ theme_headlinkcolor }}; 216 | font-size: 0.8em; 217 | padding: 0 4px 0 4px; 218 | text-decoration: none; 219 | } 220 | 221 | a.headerlink:hover { 222 | background-color: {{ theme_headlinkcolor }}; 223 | color: white; 224 | } 225 | 226 | div.body p, div.body dd, div.body li { 227 | text-align: justify; 228 | line-height: 130%; 229 | } 230 | 231 | div.admonition p.admonition-title + p { 232 | display: inline; 233 | } 234 | 235 | div.admonition p { 236 | margin-bottom: 5px; 237 | } 238 | 239 | div.admonition pre { 240 | margin-bottom: 5px; 241 | } 242 | 243 | div.admonition ul, div.admonition ol { 244 | margin-bottom: 5px; 245 | } 246 | 247 | div.note { 248 | background-color: #eee; 249 | border: 1px solid #ccc; 250 | } 251 | 252 | div.seealso { 253 | background-color: #ffc; 254 | border: 1px solid #ff6; 255 | } 256 | 257 | div.topic { 258 | background-color: #eee; 259 | } 260 | 261 | div.warning { 262 | background-color: #ffe4e4; 263 | border: 1px solid #f66; 264 | } 265 | 266 | p.admonition-title { 267 | display: inline; 268 | } 269 | 270 | p.admonition-title:after { 271 | content: ":"; 272 | } 273 | 274 | pre { 275 | padding: 5px; 276 | background-color: {{ theme_codebgcolor }}; 277 | color: {{ theme_codetextcolor }}; 278 | line-height: 120%; 279 | border: 1px solid #ac9; 280 | border-left: none; 281 | border-right: none; 282 | } 283 | 284 | tt { 285 | background-color: #ecf0f3; 286 | padding: 0 1px 0 1px; 287 | font-size: 0.95em; 288 | } 289 | 290 | th { 291 | background-color: #ede; 292 | } 293 | 294 | .warning tt { 295 | background: #efc2c2; 296 | } 297 | 298 | .note tt { 299 | background: #d6d6d6; 300 | } 301 | 302 | .viewcode-back { 303 | font-family: {{ theme_bodyfont }}; 304 | } 305 | 306 | div.viewcode-block:target { 307 | background-color: #f4debf; 308 | border-top: 1px solid #ac9; 309 | border-bottom: 1px solid #ac9; 310 | } 311 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme/static/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme/static/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme/static/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme/static/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/footerbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme/static/footerbg.png -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/headerbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme/static/headerbg.png -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/ie6.css: -------------------------------------------------------------------------------- 1 | * html img, 2 | * html .png{position:relative;behavior:expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none", 3 | this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "',sizingMethod='image')", 4 | this.src = "_static/transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''), 5 | this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "',sizingMethod='crop')", 6 | this.runtimeStyle.backgroundImage = "none")),this.pngSet=true) 7 | );} 8 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/js/theme.js: -------------------------------------------------------------------------------- 1 | $( document ).ready(function() { 2 | // Shift nav in mobile when clicking the menu. 3 | $(document).on('click', "[data-toggle='wy-nav-top']", function() { 4 | $("[data-toggle='wy-nav-shift']").toggleClass("shift"); 5 | $("[data-toggle='rst-versions']").toggleClass("shift"); 6 | }); 7 | // Close menu when you click a link. 8 | $(document).on('click', ".wy-menu-vertical .current ul li a", function() { 9 | $("[data-toggle='wy-nav-shift']").removeClass("shift"); 10 | $("[data-toggle='rst-versions']").toggleClass("shift"); 11 | }); 12 | $(document).on('click', "[data-toggle='rst-current-version']", function() { 13 | $("[data-toggle='rst-versions']").toggleClass("shift-up"); 14 | }); 15 | // Make tables responsive 16 | $("table.docutils:not(.field-list)").wrap("
"); 17 | }); 18 | 19 | window.SphinxRtdTheme = (function (jquery) { 20 | var stickyNav = (function () { 21 | var navBar, 22 | win, 23 | stickyNavCssClass = 'stickynav', 24 | applyStickNav = function () { 25 | if (navBar.height() <= win.height()) { 26 | navBar.addClass(stickyNavCssClass); 27 | } else { 28 | navBar.removeClass(stickyNavCssClass); 29 | } 30 | }, 31 | enable = function () { 32 | applyStickNav(); 33 | win.on('resize', applyStickNav); 34 | }, 35 | init = function () { 36 | navBar = jquery('nav.wy-nav-side:first'); 37 | win = jquery(window); 38 | }; 39 | jquery(init); 40 | return { 41 | enable : enable 42 | }; 43 | }()); 44 | return { 45 | StickyNav : stickyNav 46 | }; 47 | }($)); 48 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/me115_com.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme/static/me115_com.jpg -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/middlebg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme/static/middlebg.png -------------------------------------------------------------------------------- /sphinx_rtd_theme/static/transparent.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/me115/linuxtools_rst/7e40155c7d3610e785b014b885ef3028f0c5ceaa/sphinx_rtd_theme/static/transparent.gif -------------------------------------------------------------------------------- /sphinx_rtd_theme/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = css/theme.css 4 | 5 | [options] 6 | typekit_id = hiw1hhg 7 | analytics_id = 8 | sticky_navigation = False 9 | -------------------------------------------------------------------------------- /sphinx_rtd_theme/versions.html: -------------------------------------------------------------------------------- 1 | {% if READTHEDOCS %} 2 | {# Add rst-badge after rst-versions for small badge style. #} 3 |
4 | 5 | Read the Docs 6 | v: {{ current_version }} 7 | 8 | 9 |
10 |
11 |
Versions
12 | {% for slug, url in versions %} 13 |
{{ slug }}
14 | {% endfor %} 15 |
16 |
17 |
Downloads
18 | {% for type, url in downloads %} 19 |
{{ type }}
20 | {% endfor %} 21 |
22 |
23 |
On Read the Docs
24 |
25 | Project Home 26 |
27 |
28 | Builds 29 |
30 |
31 |
32 | Free document hosting provided by Read the Docs. 33 | 34 |
35 |
36 | {% endif %} 37 | 38 | -------------------------------------------------------------------------------- /tool/crontab.rst: -------------------------------------------------------------------------------- 1 | .. _crontab: 2 | 3 | crontab 定时任务 4 | ================== 5 | 通过crontab 命令,我们可以在固定的间隔时间执行指定的系统指令或 shell script脚本。时间间隔的单位可以是分钟、小时、日、月、周及以上的任意组合。这个命令非常适合周期性的日志分析或数据备份等工作。 6 | 7 | 8 | 命令格式 9 | -------------- 10 | crontab [-u user] file 11 | 12 | crontab [-u user] { -e | -l | -r } 13 | 14 | 命令参数 15 | ----------- 16 | - -u user:用来设定某个用户的crontab服务; 17 | - file:file是命令文件的名字,表示将file做为crontab的任务列表文件并载入crontab。如果在命令行中没有指定这个文件,crontab命令将接受标准输入(键盘)上键入的命令,并将它们载入crontab。 18 | - -e:编辑某个用户的crontab文件内容。如果不指定用户,则表示编辑当前用户的crontab文件。 19 | - -l:显示某个用户的crontab文件内容,如果不指定用户,则表示显示当前用户的crontab文件内容。 20 | - -r:从/var/spool/cron目录中删除某个用户的crontab文件,如果不指定用户,则默认删除当前用户的crontab文件。 21 | - -i:在删除用户的crontab文件时给确认提示。 22 | 23 | crontab 的文件格式 24 | ------------------- 25 | 分 时 日 月 星期 要运行的命令 26 | 27 | - 第1列分钟0~59 28 | - 第2列小时0~23(0表示子夜) 29 | - 第3列日1~31 30 | - 第4列月1~12 31 | - 第5列星期0~7(0和7表示星期天) 32 | - 第6列要运行的命令 33 | 34 | 为了便于大家记忆,可以看下面这张图: 35 | 36 | .. image:: ../_static/crontab_format.png 37 | :alt: crontab 文件格式 38 | 39 | 常用方法 40 | ----------------- 41 | 创建一个新的 crontab 文件 42 | ~~~~~~~~~~~~~~~~~~~~~~~~~ 43 | 向cron进程提交一个crontab文件之前,首先要设置环境变量EDITOR。cron进程根据它来确定使用哪个编辑器编辑crontab文件。9 9 %的UNIX和LINUX用户都使用vi,如果你也是这样,那么你就编辑$HOME目录下的. profile文件,在其中加入这样一行:: 44 | 45 | EDITOR=vi; export EDITOR 46 | 47 | 然后保存并退出。不妨创建一个名为 cron的文件,其中是用户名,例如, davecron。在该文件中加入如下的内容。 48 | :: 49 | 50 | # (put your own initials here)echo the date to the console every 51 | # 15minutes between 6pm and 6am 52 | 0,15,30,45 18-06 * * * /bin/echo 'date' > /dev/console 53 | 54 | 保存并退出。注意前面5个域用空格分隔。 55 | 56 | 在上面的例子中,系统将每隔1 5分钟向控制台输出一次当前时间。如果系统崩溃或挂起,从最后所显示的时间就可以一眼看出系统是什么时间停止工作的。在有些系统中,用tty1来表示控制台,可以根据实际情况对上面的例子进行相应的修改。为了提交你刚刚创建的crontab文件,可以把这个新创建的文件作为cron命令的参数:: 57 | 58 | $ crontab davecron 59 | 60 | 现在该文件已经提交给cron进程,它将每隔1 5分钟运行一次。同时,新创建文件的一个副本已经被放在/var/spool/cron目录中,文件名就是用户名(即dave)。 61 | 62 | 列出crontab文件 63 | ~~~~~~~~~~~~~~~~~ 64 | 使用-l参数列出crontab文件:: 65 | 66 | $ crontab -l 67 | 0,15,30,45 18-06 * * * /bin/echo `date` > dev/tty1 68 | 69 | 可以使用这种方法在$HOME目录中对crontab文件做一备份:: 70 | 71 | $ crontab -l > $HOME/mycron 72 | 这样,一旦不小心误删了crontab文件,可以用上一节所讲述的方法迅速恢复。 73 | 74 | 编辑crontab文件 75 | ~~~~~~~~~~~~~~~~~~~ 76 | 如果希望添加、删除或编辑crontab文件中的条目,而EDITOR环境变量又设置为vi,那么就可以用vi来编辑crontab文件:: 77 | 78 | $ crontab -e 79 | 可以像使用vi编辑其他任何文件那样修改crontab文件并退出。如果修改了某些条目或添加了新的条目,那么在保存该文件时, cron会对其进行必要的完整性检查。如果其中的某个域出现了超出允许范围的值,它会提示你。 80 | 我们在编辑crontab文件时,没准会加入新的条目。例如,加入下面的一条: 81 | :: 82 | 83 | # DT:delete core files,at 3.30am on 1,7,14,21,26,26 days of each month 84 | 30 3 1,7,14,21,26 * * /bin/find -name 'core' -exec rm {} \; 85 | 86 | 保存并退出。 87 | 88 | .. note:: 89 | 90 | 最好在crontab文件的每一个条目之上加入一条注释,这样就可以知道它的功能、运行时间,更为重要的是,知道这是哪位用户的定时作业。 91 | 92 | 删除crontab文件 93 | ~~~~~~~~~~~~~~~~~ 94 | :: 95 | 96 | $crontab -r 97 | 98 | 使用实例 99 | ---------- 100 | 实例1:每1分钟执行一次myCommand 101 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 102 | :: 103 | 104 | * * * * * myCommand 105 | 106 | 实例2:每小时的第3和第15分钟执行 107 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 108 | :: 109 | 110 | 3,15 * * * * myCommand 111 | 112 | 实例3:在上午8点到11点的第3和第15分钟执行 113 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 114 | :: 115 | 116 | 3,15 8-11 * * * myCommand 117 | 118 | 实例4:每隔两天的上午8点到11点的第3和第15分钟执行 119 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 120 | :: 121 | 122 | 3,15 8-11 */2 * * myCommand 123 | 124 | 实例5:每周一上午8点到11点的第3和第15分钟执行 125 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 126 | :: 127 | 128 | 3,15 8-11 * * 1 myCommand 129 | 130 | 实例6:每晚的21:30重启smb 131 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 132 | :: 133 | 134 | 30 21 * * * /etc/init.d/smb restart 135 | 136 | 实例7:每月1、10、22日的4 : 45重启smb 137 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 138 | :: 139 | 140 | 45 4 1,10,22 * * /etc/init.d/smb restart 141 | 142 | 实例8:每周六、周日的1 : 10重启smb 143 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 144 | :: 145 | 146 | 10 1 * * 6,0 /etc/init.d/smb restart 147 | 148 | 实例9:每天18 : 00至23 : 00之间每隔30分钟重启smb 149 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 150 | :: 151 | 152 | 0,30 18-23 * * * /etc/init.d/smb restart 153 | 154 | 实例10:每星期六的晚上11 : 00 pm重启smb 155 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 156 | :: 157 | 158 | 0 23 * * 6 /etc/init.d/smb restart 159 | 160 | 实例11:每一小时重启smb 161 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 162 | :: 163 | 164 | 0 */1 * * * /etc/init.d/smb restart 165 | 166 | 实例12:晚上11点到早上7点之间,每隔一小时重启smb 167 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 168 | :: 169 | 170 | 0 23-7 * * * /etc/init.d/smb restart 171 | 172 | 使用注意事项 173 | ----------------------- 174 | 注意环境变量问题 175 | ~~~~~~~~~~~~~~~~~~ 176 | 有时我们创建了一个crontab,但是这个任务却无法自动执行,而手动执行这个任务却没有问题,这种情况一般是由于在crontab文件中没有配置环境变量引起的。 177 | 178 | 在crontab文件中定义多个调度任务时,需要特别注环境变量的设置,因为我们手动执行某个任务时,是在当前shell环境下进行的,程序当然能找到环境变量,而系统自动执行任务调度时,是不会加载任何环境变量的,因此,就需要在crontab文件中指定任务运行所需的所有环境变量,这样,系统执行任务调度时就没有问题了。 179 | 180 | 不要假定cron知道所需要的特殊环境,它其实并不知道。所以你要保证在shelll脚本中提供所有必要的路径和环境变量,除了一些自动设置的全局变量。所以注意如下3点: 181 | 182 | 1. 脚本中涉及文件路径时写全局路径; 183 | 2. 脚本执行要用到java或其他环境变量时,通过source命令引入环境变量,如:: 184 | 185 | cat start_cbp.sh 186 | !/bin/sh 187 | source /etc/profile 188 | export RUN_CONF=/home/d139/conf/platform/cbp/cbp_jboss.conf 189 | /usr/local/jboss-4.0.5/bin/run.sh -c mev & 190 | 3. 当手动执行脚本OK,但是crontab死活不执行时,很可能是环境变量惹的祸,可尝试在crontab中直接引入环境变量解决问题。如:: 191 | 192 | 0 * * * * . /etc/profile;/bin/sh /var/www/java/audit_no_count/bin/restart_audit.sh 193 | 194 | 注意清理系统用户的邮件日志 195 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 196 | 每条任务调度执行完毕,系统都会将任务输出信息通过电子邮件的形式发送给当前系统用户,这样日积月累,日志信息会非常大,可能会影响系统的正常运行,因此,将每条任务进行重定向处理非常重要。 197 | 例如,可以在crontab文件中设置如下形式,忽略日志输出:: 198 | 199 | 0 */3 * * * /usr/local/apache2/apachectl restart >/dev/null 2>&1 200 | "/dev/null 2>&1"表示先将标准输出重定向到/dev/null,然后将标准错误重定向到标准输出,由于标准输出已经重定向到了/dev/null,因此标准错误也会重定向到/dev/null,这样日志输出问题就解决了。 201 | 202 | 系统级任务调度与用户级任务调度 203 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 204 | 系统级任务调度主要完成系统的一些维护操作,用户级任务调度主要完成用户自定义的一些任务,可以将用户级任务调度放到系统级任务调度来完成(不建议这么做),但是反过来却不行,root用户的任务调度操作可以通过"crontab –uroot –e"来设置,也可以将调度任务直接写入/etc/crontab文件,需要注意的是,如果要定义一个定时重启系统的任务,就必须将任务放到/etc/crontab文件,即使在root用户下创建一个定时重启系统的任务也是无效的。 205 | 206 | 其他注意事项 207 | ~~~~~~~~~~~~~~~~~ 208 | 新创建的cron job,不会马上执行,至少要过2分钟才执行。如果重启cron则马上执行。 209 | 210 | 当crontab失效时,可以尝试/etc/init.d/crond restart解决问题。或者查看日志看某个job有没有执行/报错tail -f /var/log/cron。 211 | 212 | 千万别乱运行crontab -r。它从Crontab目录(/var/spool/cron)中删除用户的Crontab文件。删除了该用户的所有crontab都没了。 213 | 214 | 在crontab中%是有特殊含义的,表示换行的意思。如果要用的话必须进行转义\%,如经常用的date ‘+%Y%m%d’在crontab里是不会执行的,应该换成date ‘+\%Y\%m\%d’。 215 | 216 | 更新系统时间时区后需要重启cron,在ubuntu中服务名为cron:: 217 | 218 | $service cron restart 219 | 220 | ubuntu下启动、停止与重启cron:: 221 | 222 | $sudo /etc/init.d/cron start 223 | $sudo /etc/init.d/cron stop 224 | $sudo /etc/init.d/cron restart 225 | 226 | -------------------------------------------------------------------------------- /tool/free.rst: -------------------------------------------------------------------------------- 1 | .. _free: 2 | 3 | free 查询可用内存 4 | ------------------- 5 | free工具用来查看系统可用内存:: 6 | 7 | /opt/app/tdev1$free 8 | total used free shared buffers cached 9 | Mem: 8175320 6159248 2016072 0 310208 5243680 10 | -/+ buffers/cache: 605360 7569960 11 | Swap: 6881272 16196 6865076 12 | 13 | 解释一下Linux上free命令的输出。 14 | 15 | 下面是free的运行结果,一共有4行。为了方便说明,我加上了列号。这样可以把free的输出看成一个二维数组FO(Free Output)。例如:: 16 | 17 | FO[2][1] = 24677460 18 | FO[3][2] = 10321516 19 | 20 | 1 2 3 4 5 6 21 | 1 total used free shared buffers cached 22 | 2 Mem: 24677460 23276064 1401396 0 870540 12084008 23 | 3 -/+ buffers/cache: 10321516 14355944 24 | 4 Swap: 25151484 224188 24927296 25 | free的输出一共有四行,第四行为交换区的信息,分别是交换的总量(total),使用量(used)和有多少空闲的交换区(free),这个比较清楚,不说太多。 26 | 27 | free输出地第二行和第三行是比较让人迷惑的。这两行都是说明内存使用情况的。第一列是总量(total),第二列是使用量(used),第三列是可用量(free)。 28 | 29 |   第一行的输出时从操作系统(OS)来看的。也就是说,从OS的角度来看,计算机上一共有: 30 | 31 | 24677460KB(缺省时free的单位为KB)物理内存,即FO[2][1]; 32 | 在这些物理内存中有23276064KB(即FO[2][2])被使用了; 33 | 还用1401396KB(即FO[2][3])是可用的; 34 | 35 | 这里得到第一个等式: 36 | 37 | FO[2][1] = FO[2][2] + FO[2][3] 38 | 39 | FO[2][4]表示被几个进程共享的内存的,现在已经deprecated,其值总是0(当然在一些系统上也可能不是0,主要取决于free命令是怎么实现的)。 40 | 41 | FO[2][5]表示被OS buffer住的内存。FO[2][6]表示被OS cache的内存。在有些时候buffer和cache这两个词经常混用。不过在一些比较低层的软件里是要区分这两个词的,看老外的洋文:: 42 | 43 | A buffer is something that has yet to be "written" to disk. 44 | A cache is something that has been "read" from the disk and stored for later use. 45 | 也就是说buffer是用于存放要输出到disk(块设备)的数据的,而cache是存放从disk上读出的数据。这二者是为了提高IO性能的,并由OS管理。 46 | 47 | Linux和其他成熟的操作系统(例如windows),为了提高IO read的性能,总是要多cache一些数据,这也就是为什么FO[2][6](cached memory)比较大,而FO[2][3]比较小的原因。我们可以做一个简单的测试: 48 | 49 | 释放掉被系统cache占用的数据:: 50 | 51 | echo 3>/proc/sys/vm/drop_caches 52 | 53 | 54 | 1. 读一个大文件,并记录时间; 55 | 2. 关闭该文件; 56 | 3. 重读这个大文件,并记录时间; 57 | 58 | 第二次读应该比第一次快很多。原来我做过一个BerkeleyDB的读操作,大概要读5G的文件,几千万条记录。在我的环境上,第二次读比第一次大概可以快9倍左右。 59 | 60 | free输出的第二行是从一个应用程序的角度看系统内存的使用情况。 61 | 62 | - 对于FO[3][2],即-buffers/cache,表示一个应用程序认为系统被用掉多少内存; 63 | - 对于FO[3][3],即+buffers/cache,表示一个应用程序认为系统还有多少内存; 64 | 65 | 因为被系统cache和buffer占用的内存可以被快速回收,所以通常FO[3][3]比FO[2][3]会大很多。 66 | 67 | 这里还用两个等式:: 68 | 69 | FO[3][2] = FO[2][2] - FO[2][5] - FO[2][6] 70 | FO[3][3] = FO[2][3] + FO[2][5] + FO[2][6] 71 | 这二者都不难理解。 72 | 73 | free命令由procps.*.rpm提供(在Redhat系列的OS上)。free命令的所有输出值都是从/proc/meminfo中读出的。 74 | 75 | 在系统上可能有meminfo(2)这个函数,它就是为了解析/proc/meminfo的。procps这个包自己实现了meminfo()这个函数。可以下载一个procps的tar包看看具体实现,现在最新版式3.2.8。 76 | 77 | 78 | 文章出处: 79 | 80 | http://www.cnblogs.com/coldplayerest/archive/2010/02/20/1669949.html 81 | -------------------------------------------------------------------------------- /tool/gdb.rst: -------------------------------------------------------------------------------- 1 | .. _gdb: 2 | 3 | gdb 调试利器 4 | ============== 5 | 6 | GDB是一个由GNU开源组织发布的、UNIX/LINUX操作系统下的、基于命令行的、功能强大的程序调试工具。 7 | 对于一名Linux下工作的c++程序员,gdb是必不可少的工具; 8 | 9 | 启动gdb 10 | -------------- 11 | 对C/C++程序的调试,需要在编译前就加上-g选项:: 12 | 13 | $g++ -g hello.cpp -o hello 14 | 15 | 调试可执行文件:: 16 | 17 | $gdb 18 | program也就是你的执行文件,一般在当前目录下。 19 | 20 | 调试core文件(core是程序非法执行后core dump后产生的文件):: 21 | 22 | $gdb 23 | $gdb program core.11127 24 | 25 | 调试服务程序:: 26 | 27 | $gdb 28 | $gdb hello 11127 29 | 如果你的程序是一个服务程序,那么你可以指定这个服务程序运行时的进程ID。gdb会自动attach上去,并调试他。program应该在PATH环境变量中搜索得到。 30 | 31 | gdb交互命令 32 | -------------------- 33 | 启动gdb后,进入到交互模式,通过以下命令完成对程序的调试;注意高频使用的命令一般都会有缩写,熟练使用这些缩写命令能提高调试的效率; 34 | 35 | 运行 36 | ^^^^^^^^^^^^^^^^^^^^ 37 | 38 | - run:简记为 r ,其作用是运行程序,当遇到断点后,程序会在断点处停止运行,等待用户输入下一步的命令。 39 | - continue (简写c ):继续执行,到下一个断点处(或运行结束) 40 | - next:(简写 n),单步跟踪程序,当遇到函数调用时,也不进入此函数体;此命令同 step 的主要区别是,step 遇到用户自定义的函数,将步进到函数中去运行,而 next 则直接调用函数,不会进入到函数体内。 41 | - step (简写s):单步调试如果有函数调用,则进入函数;与命令n不同,n是不进入调用的函数的 42 | - until:当你厌倦了在一个循环体内单步跟踪时,这个命令可以运行程序直到退出循环体。 43 | - until+行号: 运行至某行,不仅仅用来跳出循环 44 | - finish: 运行程序,直到当前函数完成返回,并打印函数返回时的堆栈地址和返回值及参数值等信息。 45 | - call 函数(参数):调用程序中可见的函数,并传递“参数”,如:call gdb_test(55) 46 | - quit:简记为 q ,退出gdb 47 | 48 | 设置断点 49 | ^^^^^^^^^^^^^^^^^^^^ 50 | - break n (简写b n):在第n行处设置断点 51 | (可以带上代码路径和代码名称: b OAGUPDATE.cpp:578) 52 | - b fn1 if a>b:条件断点设置 53 | - break func(break缩写为b):在函数func()的入口处设置断点,如:break cb_button 54 | - delete 断点号n:删除第n个断点 55 | - disable 断点号n:暂停第n个断点 56 | - enable 断点号n:开启第n个断点 57 | - clear 行号n:清除第n行的断点 58 | - info b (info breakpoints) :显示当前程序的断点设置情况 59 | - delete breakpoints:清除所有断点: 60 | 61 | 62 | 查看源代码 63 | ^^^^^^^^^^^^^^^^^^^^ 64 | - list :简记为 l ,其作用就是列出程序的源代码,默认每次显示10行。 65 | - list 行号:将显示当前文件以“行号”为中心的前后10行代码,如:list 12 66 | - list 函数名:将显示“函数名”所在函数的源代码,如:list main 67 | - list :不带参数,将接着上一次 list 命令的,输出下边的内容。 68 | 69 | 打印表达式 70 | ^^^^^^^^^^^^^^^^^^^^ 71 | - print 表达式:简记为 p ,其中“表达式”可以是任何当前正在被测试程序的有效表达式,比如当前正在调试C语言的程序,那么“表达式”可以是任何C语言的有效表达式,包括数字,变量甚至是函数调用。 72 | - print a:将显示整数 a 的值 73 | - print ++a:将把 a 中的值加1,并显示出来 74 | - print name:将显示字符串 name 的值 75 | - print gdb_test(22):将以整数22作为参数调用 gdb_test() 函数 76 | - print gdb_test(a):将以变量 a 作为参数调用 gdb_test() 函数 77 | - display 表达式:在单步运行时将非常有用,使用display命令设置一个表达式后,它将在每次单步进行指令后,紧接着输出被设置的表达式及值。如: display a 78 | - watch 表达式:设置一个监视点,一旦被监视的“表达式”的值改变,gdb将强行终止正在被调试的程序。如: watch a 79 | - whatis :查询变量或函数 80 | - info function: 查询函数 81 | - 扩展info locals: 显示当前堆栈页的所有变量 82 | 83 | 84 | 查询运行信息 85 | ^^^^^^^^^^^^^^^^^^^^ 86 | - where/bt :当前运行的堆栈列表; 87 | - bt backtrace 显示当前调用堆栈 88 | - up/down 改变堆栈显示的深度 89 | - set args 参数:指定运行时的参数 90 | - show args:查看设置好的参数 91 | - info program: 来查看程序的是否在运行,进程号,被暂停的原因。 92 | 93 | 分割窗口 94 | ^^^^^^^^^^^^^^^^^^^^ 95 | - layout:用于分割窗口,可以一边查看代码,一边测试: 96 | - layout src:显示源代码窗口 97 | - layout asm:显示反汇编窗口 98 | - layout regs:显示源代码/反汇编和CPU寄存器窗口 99 | - layout split:显示源代码和反汇编窗口 100 | - Ctrl + L:刷新窗口 101 | 102 | .. note:: 103 | 104 | 交互模式下直接回车的作用是重复上一指令,对于单步调试非常方便; 105 | 106 | 更强大的工具 107 | --------------------- 108 | cgdb 109 | ^^^^^^^^^^^^^^^^^^^^ 110 | cgdb可以看作gdb的界面增强版,用来替代gdb的 gdb -tui。cgdb主要功能是在调试时进行代码的同步显示,这无疑增加了调试的方便性,提高了调试效率。界面类似vi,符合unix/linux下开发人员习惯;如果熟悉gdb和vi,几乎可以立即使用cgdb。 111 | -------------------------------------------------------------------------------- /tool/index.rst: -------------------------------------------------------------------------------- 1 | .. _toolref: 2 | 3 | 工具参考篇 4 | ==================== 5 | 6 | .. toctree:: 7 | :maxdepth: 1 8 | :numbered: 2 9 | 10 | gdb 11 | ldd 12 | lsof 13 | ps 14 | pstack 15 | strace 16 | ipcs 17 | top 18 | free 19 | vmstat 20 | iostat 21 | sar 22 | readelf 23 | objdump 24 | nm 25 | size 26 | wget 27 | scp 28 | crontab 29 | 30 | -------------------------------------------------------------------------------- /tool/ipcs.rst: -------------------------------------------------------------------------------- 1 | .. _ipcs: 2 | 3 | ipcs 查询进程间通信状态 4 | ========================== 5 | 6 | ipcs是Linux下显示进程间通信设施状态的工具。可以显示消息队列、共享内存和信号量的信息。对于程序员非常有用,普通的系统管理员一般用不到此指令。 7 | 8 | 9 | IPC资源查询 10 | -------------------- 11 | 查看系统使用的IPC资源 12 | ^^^^^^^^^^^^^^^^^^^^^^ 13 | :: 14 | 15 | $ipcs 16 | 17 | ------ Shared Memory Segments -------- 18 | key shmid owner perms bytes nattch status 19 | 20 | ------ Semaphore Arrays -------- 21 | key semid owner perms nsems 22 | 0x00000000 229376 weber 600 1 23 | 24 | ------ Message Queues -------- 25 | key msqid owner perms used-bytes messages 26 | 27 | 分别查询IPC资源:: 28 | 29 | $ipcs -m 查看系统使用的IPC共享内存资源 30 | $ipcs -q 查看系统使用的IPC队列资源 31 | $ipcs -s 查看系统使用的IPC信号量资源 32 | 33 | 查看IPC资源被谁占用 34 | ^^^^^^^^^^^^^^^^^^^^ 35 | 示例:有个IPCKEY(51036),需要查询其是否被占用; 36 | 37 | 1. 首先通过计算器将其转为十六进制:: 38 | 39 | 51036 -> c75c 40 | 2. 如果知道是被共享内存占用:: 41 | 42 | $ipcs -m | grep c75c 43 | 0x0000c75c 40403197 tdea3 666 536870912 2 44 | 45 | 3. 如果不确定,则直接查找:: 46 | 47 | $ipcs | grep c75c 48 | 0x0000c75c 40403197 tdea3 666 536870912 2 49 | 0x0000c75c 5079070 tdea3 666 4 50 | 51 | 系统IPC参数查询 52 | -------------------- 53 | :: 54 | 55 | ipcs -l 56 | 57 | ------ Shared Memory Limits -------- 58 | max number of segments = 4096 59 | max seg size (kbytes) = 4194303 60 | max total shared memory (kbytes) = 1073741824 61 | min seg size (bytes) = 1 62 | 63 | ------ Semaphore Limits -------- 64 | max number of arrays = 128 65 | max semaphores per array = 250 66 | max semaphores system wide = 32000 67 | max ops per semop call = 32 68 | semaphore max value = 32767 69 | 70 | ------ Messages: Limits -------- 71 | max queues system wide = 2048 72 | max size of message (bytes) = 524288 73 | default max size of queue (bytes) = 5242880 74 | 75 | 以上输出显示,目前这个系统的允许的最大内存为1073741824kb;最大可使用128个信号量,每个消息的最大长度为524288bytes; 76 | 77 | 修改IPC系统参数 78 | -------------------- 79 | 以linux系统为例,在root用户下修改/etc/sysctl.conf 文件,保存后使用sysctl -p生效:: 80 | 81 | $cat /etc/sysctl.conf 82 | # 一个消息的最大长度 83 | kernel.msgmax = 524288 84 | 85 | # 一个消息队列上的最大字节数 86 | # 524288*10 87 | kernel.msgmnb = 5242880 88 | 89 | #最大消息队列的个数 90 | kernel.msgmni=2048 91 | 92 | #一个共享内存区的最大字节数 93 | kernel.shmmax = 17179869184 94 | 95 | #系统范围内最大共享内存标识数 96 | kernel.shmmni=4096 97 | 98 | #每个信号灯集的最大信号灯数 系统范围内最大信号灯数 每个信号灯支持的最大操作数 系统范围内最大信号灯集数 99 | #此参数为系统默认,可以不用修改 100 | #kernel.sem = * 101 | kernel.sem = 250 32000 32 128 102 | 103 | 104 | 显示输入不带标志的 ipcs:的输出:: 105 | 106 | $ipcs 107 | IPC status from /dev/mem as of Mon Aug 14 15:03:46 1989 108 | T ID KEY MODE OWNER GROUP 109 | Message Queues: 110 | q 0 0x00010381 -Rrw-rw-rw- root system 111 | q 65537 0x00010307 -Rrw-rw-rw- root system 112 | q 65538 0x00010311 -Rrw-rw-rw- root system 113 | q 65539 0x0001032f -Rrw-rw-rw- root system 114 | q 65540 0x0001031b -Rrw-rw-rw- root system 115 | q 65541 0x00010339--rw-rw-rw- root system 116 | q 6 0x0002fe03 -Rrw-rw-rw- root system 117 | Shared Memory: 118 | m 65537 0x00000000 DCrw------- root system 119 | m 720898 0x00010300 -Crw-rw-rw- root system 120 | m 65539 0x00000000 DCrw------- root system 121 | Semaphores: 122 | s 131072 0x4d02086a --ra-ra---- root system 123 | s 65537 0x00000000 --ra------- root system 124 | s 1310722 0x000133d0 --ra------- 7003 30720 125 | 126 | 127 | 清除IPC资源 128 | -------------------- 129 | 使用ipcrm 命令来清除IPC资源:这个命令同时会将与ipc对象相关联的数据也一起移除。当然,只有root用户,或者ipc对象的创建者才有这项权利; 130 | 131 | ipcrm用法:: 132 | 133 | ipcrm -M shmkey 移除用shmkey创建的共享内存段 134 | ipcrm -m shmid 移除用shmid标识的共享内存段 135 | ipcrm -Q msgkey 移除用msqkey创建的消息队列 136 | ipcrm -q msqid 移除用msqid标识的消息队列 137 | ipcrm -S semkey 移除用semkey创建的信号 138 | ipcrm -s semid 移除用semid标识的信号 139 | 140 | 清除当前用户创建的所有的IPC资源:: 141 | 142 | ipcs -q | awk '{ print "ipcrm -q "$2}' | sh > /dev/null 2>&1; 143 | ipcs -m | awk '{ print "ipcrm -m "$2}' | sh > /dev/null 2>&1; 144 | ipcs -s | awk '{ print "ipcrm -s "$2}' | sh > /dev/null 2>&1; 145 | 146 | 综合应用 147 | -------------------- 148 | 查询user1用户环境上是否存在积Queue现象 149 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 150 | 1. 查询队列Queue:: 151 | 152 | $ipcs -q 153 | 154 | ------ Message Queues -------- 155 | key msqid owner perms used-bytes messages 156 | 0x49060005 58261504 user1 660 0 0 157 | 0x4f060005 58294273 user1 660 0 0 158 | ... 159 | 160 | 2. 找出第6列大于0的服务:: 161 | 162 | $ ipcs -q |grep user1 |awk '{if($5>0) print $0}' 163 | 0x00000000 1071579324 user1 644 1954530 4826 164 | 0x00000000 1071644862 user1 644 1961820 4844 165 | 0x00000000 1071677631 user1 644 1944810 4802 166 | 0x00000000 1071710400 user1 644 1961820 4844 167 | 168 | -------------------------------------------------------------------------------- /tool/ldd.rst: -------------------------------------------------------------------------------- 1 | .. _ldd: 2 | 3 | ldd 查看程序依赖库 4 | ============================ 5 | 6 | ldd 7 | 作用:用来查看程式运行所需的共享库,常用来解决程式因缺少某个库文件而不能运行的一些问题。 8 | 9 | 示例:查看test程序运行所依赖的库:: 10 | 11 | /opt/app/todeav1/test$ldd test 12 | libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00000039a7e00000) 13 | libm.so.6 => /lib64/libm.so.6 (0x0000003996400000) 14 | libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00000039a5600000) 15 | libc.so.6 => /lib64/libc.so.6 (0x0000003995800000) 16 | /lib64/ld-linux-x86-64.so.2 (0x0000003995400000) 17 | 18 | 19 | - 第一列:程序需要依赖什么库 20 | - 第二列: 系统提供的与程序需要的库所对应的库 21 | - 第三列:库加载的开始地址 22 | 23 | 通过上面的信息,我们可以得到以下几个信息: 24 | 25 | 1. 通过对比第一列和第二列,我们可以分析程序需要依赖的库和系统实际提供的,是否相匹配 26 | 2. 通过观察第三列,我们可以知道在当前的库中的符号在对应的进程的地址空间中的开始位置 27 | 28 | 29 | 如果依赖的某个库找不到,通过这个命令可以迅速定位问题所在; 30 | 31 | .. note:: 32 | 33 | 原理: 34 | ldd不是个可执行程式,而只是个shell脚本; 35 | ldd显示可执行模块的dependency的工作原理,其实质是通过ld-linux.so(elf动态库的装载器)来实现的。ld-linux.so模块会先于executable模块程式工作,并获得控制权,因此当上述的那些环境变量被设置时,ld-linux.so选择了显示可执行模块的dependency。 36 | 37 | -------------------------------------------------------------------------------- /tool/lsof.rst: -------------------------------------------------------------------------------- 1 | .. _lsof: 2 | 3 | lsof 一切皆文件 4 | ================ 5 | 6 | lsof(list open files)是一个查看当前系统文件的工具。在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件。如传输控制协议 (TCP) 和用户数据报协议 (UDP) 套接字等,系统在后台都为该应用程序分配了一个文件描述符,该文件描述符提供了大量关于这个应用程序本身的信息。 7 | 8 | lsof打开的文件可以是: 9 | 10 | 1. 普通文件 11 | 2. 目录 12 | 3. 网络文件系统的文件 13 | 4. 字符或设备文件 14 | 5. (函数)共享库 15 | 6. 管道,命名管道 16 | 7. 符号链接 17 | 8. 网络文件(例如:NFS file、网络socket,unix域名socket) 18 | 9. 还有其它类型的文件,等等 19 | 20 | 命令参数 21 | ----------------- 22 | - -a 列出打开文件存在的进程 23 | - -c<进程名> 列出指定进程所打开的文件 24 | - -g 列出GID号进程详情 25 | - -d<文件号> 列出占用该文件号的进程 26 | - +d<目录> 列出目录下被打开的文件 27 | - +D<目录> 递归列出目录下被打开的文件 28 | - -n<目录> 列出使用NFS的文件 29 | - -i<条件> 列出符合条件的进程。(4、6、协议、:端口、 @ip ) 30 | - -p<进程号> 列出指定进程号所打开的文件 31 | - -u 列出UID号进程详情 32 | - -h 显示帮助信息 33 | - -v 显示版本信息 34 | 35 | 使用实例 36 | ------------------- 37 | 38 | 实例1:无任何参数 39 | ^^^^^^^^^^^^^^^^^^^^^ 40 | :: 41 | 42 | $lsof| more 43 | COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME 44 | init 1 root cwd DIR 253,0 4096 2 / 45 | init 1 root rtd DIR 253,0 4096 2 / 46 | init 1 root txt REG 253,0 150352 1310795 /sbin/init 47 | init 1 root mem REG 253,0 65928 5505054 /lib64/libnss_files-2.12.so 48 | init 1 root mem REG 253,0 1918016 5521405 /lib64/libc-2.12.so 49 | init 1 root mem REG 253,0 93224 5521440 /lib64/libgcc_s-4.4.6-20120305.so.1 50 | init 1 root mem REG 253,0 47064 5521407 /lib64/librt-2.12.so 51 | init 1 root mem REG 253,0 145720 5521406 /lib64/libpthread-2.12.so 52 | ... 53 | 54 | 说明: 55 | 56 | lsof输出各列信息的意义如下: 57 | 58 | - COMMAND:进程的名称 59 | - PID:进程标识符 60 | - PPID:父进程标识符(需要指定-R参数) 61 | - USER:进程所有者 62 | - PGID:进程所属组 63 | - FD:文件描述符,应用程序通过文件描述符识别该文件。如cwd、txt等:: 64 | 65 | (1)cwd:表示current work dirctory,即:应用程序的当前工作目录,这是该应用程序启动的目录,除非它本身对这个目录进行更改 66 | (2)txt :该类型的文件是程序代码,如应用程序二进制文件本身或共享库,如上列表中显示的 /sbin/init 程序 67 | (3)lnn:library references (AIX); 68 | (4)er:FD information error (see NAME column); 69 | (5)jld:jail directory (FreeBSD); 70 | (6)ltx:shared library text (code and data); 71 | (7)mxx :hex memory-mapped type number xx. 72 | (8)m86:DOS Merge mapped file; 73 | (9)mem:memory-mapped file; 74 | (10)mmap:memory-mapped device; 75 | (11)pd:parent directory; 76 | (12)rtd:root directory; 77 | (13)tr:kernel trace file (OpenBSD); 78 | (14)v86 VP/ix mapped file; 79 | (15)0:表示标准输入 80 | (16)1:表示标准输出 81 | (17)2:表示标准错误 82 | 一般在标准输出、标准错误、标准输入后还跟着文件状态模式:r、w、u等 83 | (1)u:表示该文件被打开并处于读取/写入模式 84 | (2)r:表示该文件被打开并处于只读模式 85 | (3)w:表示该文件被打开并处于 86 | (4)空格:表示该文件的状态模式为unknow,且没有锁定 87 | (5)-:表示该文件的状态模式为unknow,且被锁定 88 | 同时在文件状态模式后面,还跟着相关的锁 89 | (1)N:for a Solaris NFS lock of unknown type; 90 | (2)r:for read lock on part of the file; 91 | (3)R:for a read lock on the entire file; 92 | (4)w:for a write lock on part of the file;(文件的部分写锁) 93 | (5)W:for a write lock on the entire file;(整个文件的写锁) 94 | (6)u:for a read and write lock of any length; 95 | (7)U:for a lock of unknown type; 96 | (8)x:for an SCO OpenServer Xenix lock on part of the file; 97 | (9)X:for an SCO OpenServer Xenix lock on the entire file; 98 | (10)space:if there is no lock. 99 | 100 | - TYPE:文件类型,如DIR、REG等,常见的文件类型:: 101 | 102 | (1)DIR:表示目录 103 | (2)CHR:表示字符类型 104 | (3)BLK:块设备类型 105 | (4)UNIX: UNIX 域套接字 106 | (5)FIFO:先进先出 (FIFO) 队列 107 | (6)IPv4:网际协议 (IP) 套接字 108 | - DEVICE:指定磁盘的名称 109 | - SIZE:文件的大小 110 | - NODE:索引节点(文件在磁盘上的标识) 111 | - NAME:打开文件的确切名称 112 | 113 | 实例2:查找某个文件相关的进程 114 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 115 | :: 116 | 117 | $lsof /bin/bash 118 | COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME 119 | mysqld_sa 2169 root txt REG 253,0 938736 4587562 /bin/bash 120 | ksmtuned 2334 root txt REG 253,0 938736 4587562 /bin/bash 121 | bash 20121 root txt REG 253,0 938736 4587562 /bin/bash 122 | 123 | 124 | 实例3:列出某个用户打开的文件信息 125 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 126 | :: 127 | 128 | $lsof -u username 129 | 130 | -u 选项,u是user的缩写 131 | 132 | 实例4:列出某个程序进程所打开的文件信息 133 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 134 | :: 135 | 136 | $lsof -c mysql 137 | 138 | -c 选项将会列出所有以mysql这个进程开头的程序的文件,其实你也可以写成 lsof | grep mysql, 但是第一种方法明显比第二种方法要少打几个字符; 139 | 140 | 实例5:列出某个用户以及某个进程所打开的文件信息 141 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 142 | :: 143 | 144 | $lsof -u test -c mysql 145 | 146 | 实例6:通过某个进程号显示该进程打开的文件 147 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 148 | :: 149 | 150 | $lsof -p 11968 151 | 152 | 实例7:列出所有的网络连接 153 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 154 | :: 155 | 156 | $lsof -i 157 | 158 | 实例8:列出所有tcp 网络连接信息 159 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 160 | :: 161 | 162 | $lsof -i tcp 163 | 164 | $lsof -n -i tcp 165 | COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME 166 | svnserve 11552 weber 3u IPv4 3799399 0t0 TCP *:svn (LISTEN) 167 | redis-ser 25501 weber 4u IPv4 113150 0t0 TCP 127.0.0.1:6379 (LISTEN) 168 | 169 | 实例9:列出谁在使用某个端口 170 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 171 | :: 172 | 173 | $lsof -i :3306 174 | 175 | 实例10:列出某个用户的所有活跃的网络端口 176 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 177 | :: 178 | 179 | $lsof -a -u test -i 180 | 181 | 实例11:根据文件描述列出对应的文件信息 182 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 183 | :: 184 | 185 | $lsof -d description(like 2) 186 | 187 | 示例:: 188 | 189 | $lsof -d 3 | grep PARSER1 190 | tail 6499 tde 3r REG 253,3 4514722 417798 /opt/applog/open/log/HOSTPARSER1_ERROR_141217.log.001 191 | 192 | 193 | 说明: 194 | 0表示标准输入,1表示标准输出,2表示标准错误,从而可知:所以大多数应用程序所打开的文件的 FD 都是从 3 开始 195 | 196 | 197 | 实例12:列出被进程号为1234的进程所打开的所有IPV4 network files 198 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 199 | :: 200 | 201 | $lsof -i 4 -a -p 1234 202 | 203 | 实例13:列出目前连接主机nf5260i5-td上端口为:20,21,80相关的所有文件信息,且每隔3秒重复执行 204 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 205 | :: 206 | 207 | lsof -i @nf5260i5-td:20,21,80 -r 3 208 | -------------------------------------------------------------------------------- /tool/nm.rst: -------------------------------------------------------------------------------- 1 | .. _nm: 2 | 3 | nm 目标文件格式分析 4 | ======================= 5 | 6 | nm 命令显示关于指定 File 中符号的信息,文件可以是对象文件、可执行文件或对象文件库。如果文件没有包含符号信息,nm 命令报告该情况,但不把它解释为出错条件。 nm 命令缺省情况下报告十进制符号表示法下的数字值。 7 | 8 | :: 9 | 10 | $nm myProgrammer 11 | 08049f28 d _DYNAMIC 12 | 08049ff4 d _GLOBAL_OFFSET_TABLE_ 13 | 080484dc R _IO_stdin_used 14 | w _Jv_RegisterClasses 15 | 08049f18 d __CTOR_END__ 16 | 08049f14 d __CTOR_LIST__ 17 | 08049f20 D __DTOR_END__ 18 | 08049f1c d __DTOR_LIST__ 19 | 080485e0 r __FRAME_END__ 20 | 08049f24 d __JCR_END__ 21 | 08049f24 d __JCR_LIST__ 22 | 0804a014 A __bss_start 23 | 0804a00c D __data_start 24 | 08048490 t __do_global_ctors_aux 25 | 08048360 t __do_global_dtors_aux 26 | 0804a010 D __dso_handle 27 | w __gmon_start__ 28 | 08048482 T __i686.get_pc_thunk.bx 29 | 08049f14 d __init_array_end 30 | 08049f14 d __init_array_start 31 | 08048480 T __libc_csu_fini 32 | 08048410 T __libc_csu_init 33 | U __libc_start_main@@GLIBC_2.0 34 | 0804a014 A _edata 35 | 0804a01c A _end 36 | 080484bc T _fini 37 | 080484d8 R _fp_hw 38 | 080482b4 T _init 39 | 08048330 T _start 40 | 0804a014 b completed.6086 41 | 0804a00c W data_start 42 | 0804a018 b dtor_idx.6088 43 | 080483c0 t frame_dummy 44 | 080483e4 T main 45 | U printf@@GLIBC_2.0 46 | 47 | 这些包含可执行代码的段称为正文段。同样地,数据段包含了不可执行的信息或数据。另一种类型的段,称为 BSS 段,它包含以符号数据开头的块。对于 nm 命令列出的每个符号,它们的值使用十六进制来表示(缺省行为),并且在该符号前面加上了一个表示符号类型的编码字符。 48 | 49 | 可以将目标文件中所包含的不同的部分划分为段。段可以包含可执行代码、符号名称、初始数据值和许多其他类型的数据。有关这些类型的数据的详细信息,可以阅读 UNIX 中 nm 的 man 页面,其中按照该命令输出中的字符编码分别对每种类型进行了描述。 50 | 51 | 选项说明 52 | -------------------- 53 | - -a或--debug-syms:显示所有的符号,包括debugger-only symbols。 54 | - -B:等同于--format=bsd,用来兼容MIPS的nm。 55 | - -C或--demangle:将低级符号名解析(demangle)成用户级名字。这样可以使得C++函数名具有可读性。 56 | - --no-demangle:默认的选项,不需要将低级符号名解析成用户级名。 57 | - -D或--dynamic:显示动态符号。该任选项仅对于动态目标(例如特定类型的共享库)有意义。 58 | - -f format:使用format格式输出。format可以选取bsd、sysv或posix,该选项在GNU的nm中有用。默认为bsd。 59 | - -g或--extern-only:仅显示外部符号。 60 | - -n、-v或--numeric-sort:按符号对应地址的顺序排序,而非按符号名的字符顺序。 61 | - -p或--no-sort:按目标文件中遇到的符号顺序显示,不排序。 62 | - -P或--portability:使用POSIX.2标准输出格式代替默认的输出格式。等同于使用任选项-f posix。 63 | - -s或--print-armap:当列出库中成员的符号时,包含索引。索引的内容包含:哪些模块包含哪些名字的映射。 64 | - -r或--reverse-sort:反转排序的顺序(例如,升序变为降序)。 65 | - --size-sort:按大小排列符号顺序。该大小是按照一个符号的值与它下一个符号的值进行计算的。 66 | - --target=bfdname:指定一个目标代码的格式,而非使用系统的默认格式。 67 | - -u或--undefined-only:仅显示没有定义的符号(那些外部符号)。 68 | - --defined-only:仅显示定义的符号。 69 | - -l或--line-numbers:对每个符号,使用调试信息来试图找到文件名和行号。 70 | - -V或--version:显示nm的版本号。 71 | - --help:显示nm的选项。 72 | 73 | 符号说明 74 | -------------------- 75 | 对于每一个符号来说,其类型如果是小写的,则表明该符号是local的;大写则表明该符号是global(external)的。 76 | 77 | - A 该符号的值是绝对的,在以后的链接过程中,不允许进行改变。这样的符号值,常常出现在中断向量表中,例如用符号来表示各个中断向量函数在中断向量表中的位置。 78 | - B 该符号的值出现在非初始化数据段(bss)中。例如,在一个文件中定义全局static int test。则该符号test的类型为b,位于bss section中。其值表示该符号在bss段中的偏移。一般而言,bss段分配于RAM中。 79 | - C 该符号为common。common symbol是未初始话数据段。该符号没有包含于一个普通section中。只有在链接过程中才进行分配。符号的值表示该符号需要的字节数。例如在一个c文件中,定义int test,并且该符号在别的地方会被引用,则该符号类型即为C。否则其类型为B。 80 | - D 该符号位于初始化数据段中。一般来说,分配到data section中。 81 | 例如:定义全局int baud_table[5] = {9600, 19200, 38400, 57600, 115200},会分配到初始化数据段中。 82 | 83 | - G 该符号也位于初始化数据段中。主要用于small object提高访问small data object的一种方式。 84 | - I 该符号是对另一个符号的间接引用。 85 | - N 该符号是一个debugging符号。 86 | - R 该符号位于只读数据区。 87 | * 例如定义全局const int test[] = {123, 123};则test就是一个只读数据区的符号。 88 | * 值得注意的是,如果在一个函数中定义const char *test = "abc", const char test_int = 3。使用nm都不会得到符号信息,但是字符串"abc"分配于只读存储器中,test在rodata section中,大小为4。 89 | - S 符号位于非初始化数据区,用于small object。 90 | - T 该符号位于代码区text section。 91 | - U 该符号在当前文件中是未定义的,即该符号的定义在别的文件中。 92 | 例如,当前文件调用另一个文件中定义的函数,在这个被调用的函数在当前就是未定义的;但是在定义它的文件中类型是T。但是对于全局变量来说,在定义它的文件中,其符号类型为C,在使用它的文件中,其类型为U。 93 | - V 该符号是一个weak object。 94 | - W The symbol is a weak symbol that has not been specifically tagged as a weak object symbol. 95 | - ? 该符号类型没有定义 96 | 97 | *库或对象名* 98 | 如果您指定了 -A 选项,则 nm 命令只报告与该文件有关的或者库或者对象名。 99 | 100 | 101 | 示例 102 | -------------------- 103 | 1. 寻找特殊标识 104 | 105 | 有时会碰到一个编译了但没有链接的代码,那是因为它缺失了标识符;这种情况,可以用nm和objdump、readelf命令来查看程序的符号表;所有这些命令做的工作基本一样; 106 | 107 | 比如连接器报错有未定义的标识符;大多数情况下,会发生在库的缺失或企图链接一个错误版本的库的时候;浏览目标代码来寻找一个特殊标识符的引用:: 108 | 109 | nm -uCA *.o | grep foo 110 | 111 | -u选项限制了每个目标文件中未定义标识符的输出。-A选项用于显示每个标识符的文件名信息;对于C++代码,常用的还有-C选项,它也为解码这些标识符; 112 | 113 | .. note:: 114 | 115 | objdump、readld命令可以完成同样的任务。等效命令为: 116 | $objdump -t 117 | $readelf -s 118 | 119 | 2. 列出 a.out 对象文件的静态和外部符:: 120 | 121 | $nm -e a.out 122 | 123 | 3. 以十六进制显示符号大小和值并且按值排序符号:: 124 | 125 | $nm -xv a.out 126 | 127 | 4. 显示 libc.a 中所有 64 位对象符号,忽略所有 32 位对象:: 128 | 129 | $nm -X64 /usr/lib/libc.a 130 | -------------------------------------------------------------------------------- /tool/objdump.rst: -------------------------------------------------------------------------------- 1 | .. _objdump: 2 | 3 | objdump 二进制文件分析 4 | ========================= 5 | 6 | objdump工具用来显示二进制文件的信息,就是以一种可阅读的格式让你更多地了解二进制文件可能带有的附加信息。 7 | 8 | 9 | 常用参数说明 10 | ------------------- 11 | - -f 显示文件头信息 12 | - -D 反汇编所有section (-d反汇编特定section) 13 | - -h 显示目标文件各个section的头部摘要信息 14 | - -x 显示所有可用的头信息,包括符号表、重定位入口。-x 等价于 -a -f -h -r -t 同时指定。 15 | - -i 显示对于 -b 或者 -m 选项可用的架构和目标格式列表。 16 | - -r 显示文件的重定位入口。如果和-d或者-D一起使用,重定位部分以反汇编后的格式显示出来。 17 | - -R 显示文件的动态重定位入口,仅仅对于动态目标文件有意义,比如某些共享库。 18 | - -S 尽可能反汇编出源代码,尤其当编译的时候指定了-g这种调试参数时,效果比较明显。隐含了-d参数。 19 | - -t 显示文件的符号表入口。类似于nm -s提供的信息 20 | 21 | 示例 22 | -------------------- 23 | 24 | 查看本机目标结构(使用大端还是小端存储):: 25 | 26 | $objdump -i 27 | 28 | 29 | 反汇编程序:: 30 | 31 | $objdump -d main.o 32 | 33 | 显示符号表入口:: 34 | 35 | $objdump -t main.o 36 | 37 | 希望显示可用的简洁帮助信息,直接输入objdump即可;(objdump -H) 38 | -------------------------------------------------------------------------------- /tool/ps.rst: -------------------------------------------------------------------------------- 1 | .. _ps: 2 | 3 | ps 进程查看器 4 | ============== 5 | Linux中的ps命令是Process Status的缩写。ps命令用来列出系统中当前运行的那些进程。ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程,如果想要动态的显示进程信息,就可以使用top命令。 6 | 7 | 要对进程进行监测和控制,首先必须要了解当前进程的情况,也就是需要查看当前进程,而 ps 命令就是最基本同时也是非常强大的进程查看命令。使用该命令可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵死、哪些进程占用了过多的资源等等。总之大部分信息都是可以通过执行该命令得到的。 8 | 9 | ps 为我们提供了进程的一次性的查看,它所提供的查看结果并不动态连续的;如果想对进程时间监控,应该用 :ref:`top` 工具。 10 | 11 | 注:kill 命令用于杀死进程。 12 | 13 | linux上进程有5种状态: 14 | 15 | 1. 运行(正在运行或在运行队列中等待) 16 | 2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号) 17 | 3. 不可中断(收到信号不唤醒和不可运行, 进程必须等待直到有中断发生) 18 | 4. 僵死(进程已终止, 但进程描述符存在, 直到父进程调用wait4()系统调用后释放) 19 | 5. 停止(进程收到SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU信号后停止运行运行) 20 | 21 | ps工具标识进程的5种状态码: 22 | 23 | - D 不可中断 uninterruptible sleep (usually IO) 24 | - R 运行 runnable (on run queue) 25 | - S 中断 sleeping 26 | - T 停止 traced or stopped 27 | - Z 僵死 a defunct (”zombie”) process 28 | 29 | 命令参数 30 | -------------------- 31 | - a 显示所有进程 32 | - -a 显示同一终端下的所有程序 33 | - -A 显示所有进程 34 | - c 显示进程的真实名称 35 | - -N 反向选择 36 | - -e 等于“-A” 37 | - e 显示环境变量 38 | - f 显示程序间的关系 39 | - -H 显示树状结构 40 | - r 显示当前终端的进程 41 | - T 显示当前终端的所有程序 42 | - u 指定用户的所有进程 43 | - -au 显示较详细的资讯 44 | - -aux 显示所有包含其他使用者的行程 45 | - -C<命令> 列出指定命令的状况 46 | - --lines<行数> 每页显示的行数 47 | - --width<字符数> 每页显示的字符数 48 | - --help 显示帮助信息 49 | - --version 显示版本显示 50 | 51 | 输出列的含义 52 | -------------------- 53 | - F 代表这个程序的旗标 (flag), 4 代表使用者为 super user 54 | - S 代表这个程序的状态 (STAT),关于各 STAT 的意义将在内文介绍 55 | - UID 程序被该 UID 所拥有 56 | - PID 进程的ID 57 | - PPID 则是其上级父程序的ID 58 | - C CPU 使用的资源百分比 59 | - PRI 这个是 Priority (优先执行序) 的缩写,详细后面介绍 60 | - NI 这个是 Nice 值,在下一小节我们会持续介绍 61 | - ADDR 这个是 kernel function,指出该程序在内存的那个部分。如果是个 running的程序,一般就是 "-" 62 | - SZ 使用掉的内存大小 63 | - WCHAN 目前这个程序是否正在运作当中,若为 - 表示正在运作 64 | - TTY 登入者的终端机位置 65 | - TIME 使用掉的 CPU 时间。 66 | - CMD 所下达的指令为何 67 | 68 | 69 | 使用实例 70 | -------------------- 71 | 实例1:显示所有进程信息 72 | ~~~~~~~~~~~~~~~~~~~~~~~~~ 73 | :: 74 | 75 | [root@localhost test6]# ps -A 76 | PID TTY TIME CMD 77 | 1 ? 00:00:00 init 78 | 2 ? 00:00:01 migration/0 79 | 3 ? 00:00:00 ksoftirqd/0 80 | 4 ? 00:00:01 migration/1 81 | 5 ? 00:00:00 ksoftirqd/1 82 | 6 ? 00:29:57 events/0 83 | 7 ? 00:00:00 events/1 84 | 8 ? 00:00:00 khelper 85 | 49 ? 00:00:00 kthread 86 | 54 ? 00:00:00 kblockd/0 87 | 55 ? 00:00:00 kblockd/1 88 | 56 ? 00:00:00 kacpid 89 | 217 ? 00:00:00 cqueue/0 90 | ……省略部分结果 91 | 92 | 93 | 实例2:显示指定用户信息 94 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 95 | :: 96 | 97 | [root@localhost test6]# ps -u root 98 | PID TTY TIME CMD 99 | 1 ? 00:00:00 init 100 | 2 ? 00:00:01 migration/0 101 | 3 ? 00:00:00 ksoftirqd/0 102 | 4 ? 00:00:01 migration/1 103 | 5 ? 00:00:00 ksoftirqd/1 104 | 6 ? 00:29:57 events/0 105 | 7 ? 00:00:00 events/1 106 | 8 ? 00:00:00 khelper 107 | 49 ? 00:00:00 kthread 108 | 54 ? 00:00:00 kblockd/0 109 | 55 ? 00:00:00 kblockd/1 110 | 56 ? 00:00:00 kacpid 111 | ……省略部分结果 112 | 113 | 114 | 实例3:显示所有进程信息,连同命令行 115 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 116 | :: 117 | 118 | [root@localhost test6]# ps -ef 119 | UID PID PPID C STIME TTY TIME CMD 120 | root 1 0 0 Nov02 ? 00:00:00 init [3] 121 | root 2 1 0 Nov02 ? 00:00:01 [migration/0] 122 | root 3 1 0 Nov02 ? 00:00:00 [ksoftirqd/0] 123 | root 4 1 0 Nov02 ? 00:00:01 [migration/1] 124 | root 5 1 0 Nov02 ? 00:00:00 [ksoftirqd/1] 125 | root 6 1 0 Nov02 ? 00:29:57 [events/0] 126 | root 7 1 0 Nov02 ? 00:00:00 [events/1] 127 | root 8 1 0 Nov02 ? 00:00:00 [khelper] 128 | root 49 1 0 Nov02 ? 00:00:00 [kthread] 129 | root 54 49 0 Nov02 ? 00:00:00 [kblockd/0] 130 | root 55 49 0 Nov02 ? 00:00:00 [kblockd/1] 131 | root 56 49 0 Nov02 ? 00:00:00 [kacpid] 132 | 133 | 134 | 实例4: ps 与grep 组合使用,查找特定进程 135 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 136 | :: 137 | 138 | [root@localhost test6]# ps -ef|grep ssh 139 | root 2720 1 0 Nov02 ? 00:00:00 /usr/sbin/sshd 140 | root 17394 2720 0 14:58 ? 00:00:00 sshd: root@pts/0 141 | root 17465 17398 0 15:57 pts/0 00:00:00 grep ssh 142 | 143 | 144 | 实例5:将与这次登入的 PID 与相关信息列示出来 145 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 146 | :: 147 | 148 | [root@localhost test6]# ps -l 149 | F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 150 | 4 S 0 17398 17394 0 75 0 - 16543 wait pts/0 00:00:00 bash 151 | 4 R 0 17469 17398 0 77 0 - 15877 - pts/0 00:00:00 ps 152 | 153 | 实例6:列出目前所有的正在内存中的程序 154 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 155 | :: 156 | 157 | [root@localhost test6]# ps aux 158 | USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND 159 | root 1 0.0 0.0 10368 676 ? Ss Nov02 0:00 init [3] 160 | root 2 0.0 0.0 0 0 ? S< Nov02 0:01 [migration/0] 161 | root 3 0.0 0.0 0 0 ? SN Nov02 0:00 [ksoftirqd/0] 162 | root 4 0.0 0.0 0 0 ? S< Nov02 0:01 [migration/1] 163 | root 5 0.0 0.0 0 0 ? SN Nov02 0:00 [ksoftirqd/1] 164 | root 6 0.0 0.0 0 0 ? S< Nov02 29:57 [events/0] 165 | root 7 0.0 0.0 0 0 ? S< Nov02 0:00 [events/1] 166 | root 8 0.0 0.0 0 0 ? S< Nov02 0:00 [khelper] 167 | root 49 0.0 0.0 0 0 ? S< Nov02 0:00 [kthread] 168 | root 54 0.0 0.0 0 0 ? S< Nov02 0:00 [kblockd/0] 169 | root 55 0.0 0.0 0 0 ? S< Nov02 0:00 [kblockd/1] 170 | root 56 0.0 0.0 0 0 ? S< Nov02 0:00 [kacpid] 171 | 172 | 173 | -------------------------------------------------------------------------------- /tool/pstack.rst: -------------------------------------------------------------------------------- 1 | .. _pstack: 2 | 3 | pstack 跟踪进程栈 4 | ==================== 5 | 6 | 此命令可显示每个进程的栈跟踪。pstack 命令必须由相应进程的属主或 root 运行。可以使用 pstack 来确定进程挂起的位置。此命令允许使用的唯一选项是要检查的进程的 PID。请参见 proc(1) 手册页。 7 | 8 | 这个命令在排查进程问题时非常有用,比如我们发现一个服务一直处于work状态(如假死状态,好似死循环),使用这个命令就能轻松定位问题所在;可以在一段时间内,多执行几次pstack,若发现代码栈总是停在同一个位置,那个位置就需要重点关注,很可能就是出问题的地方; 9 | 10 | 示例:查看bash程序进程栈:: 11 | 12 | /opt/app/tdev1$ps -fe| grep bash 13 | tdev1 7013 7012 0 19:42 pts/1 00:00:00 -bash 14 | tdev1 11402 11401 0 20:31 pts/2 00:00:00 -bash 15 | tdev1 11474 11402 0 20:32 pts/2 00:00:00 grep bash 16 | /opt/app/tdev1$pstack 7013 17 | #0 0x00000039958c5620 in __read_nocancel () from /lib64/libc.so.6 18 | #1 0x000000000047dafe in rl_getc () 19 | #2 0x000000000047def6 in rl_read_key () 20 | #3 0x000000000046d0f5 in readline_internal_char () 21 | #4 0x000000000046d4e5 in readline () 22 | #5 0x00000000004213cf in ?? () 23 | #6 0x000000000041d685 in ?? () 24 | #7 0x000000000041e89e in ?? () 25 | #8 0x00000000004218dc in yyparse () 26 | #9 0x000000000041b507 in parse_command () 27 | #10 0x000000000041b5c6 in read_command () 28 | #11 0x000000000041b74e in reader_loop () 29 | #12 0x000000000041b2aa in main () 30 | 31 | -------------------------------------------------------------------------------- /tool/sar.rst: -------------------------------------------------------------------------------- 1 | .. _sar: 2 | 3 | sar 找出系统瓶颈的利器 4 | ====================== 5 | 6 | sar是System Activity Reporter(系统活动情况报告)的缩写。sar工具将对系统当前的状态进行取样,然后通过计算数据和比例来表达系统的当前运行状态。它的特点是可以连续对系统取样,获得大量的取样数据;取样数据和分析的结果都可以存入文件,所需的负载很小。sar是目前Linux上最为全面的系统性能分析工具之一,可以从14个大方面对系统的活动进行报告,包括文件的读写情况、系统调用的使用情况、串口、CPU效率、内存使用状况、进程活动及IPC有关的活动等,使用也是较为复杂。 7 | 8 | sar是查看操作系统报告指标的各种工具中,最为普遍和方便的;它有两种用法; 9 | 10 | 1. 追溯过去的统计数据(默认) 11 | 2. 周期性的查看当前数据 12 | 13 | 追溯过去的统计数据 14 | ------------------ 15 | 16 | 默认情况下,sar从最近的0点0分开始显示数据;如果想继续查看一天前的报告;可以查看保存在/var/log/sysstat/下的sa日志; 17 | 使用sar工具查看:: 18 | 19 | $sar -f /var/log/sysstat/sa28 \| head sar -r -f 20 | /var/log/sysstat/sa28 21 | 22 | .. image:: /_static/sar1.png 23 | :width: 800 24 | 25 | 查看CPU使用率 26 | ------------- 27 | sar -u : 默认情况下显示的cpu使用率等信息就是sar -u; 28 | 29 | .. image:: /_static/sar2.png 30 | :width: 800 31 | 32 | 可以看到这台机器使用了虚拟化技术,有相应的时间消耗; 各列的指标分别是: 33 | 34 | - %user 用户模式下消耗的CPU时间的比例; 35 | - %nice 通过nice改变了进程调度优先级的进程,在用户模式下消耗的CPU时间的比例 36 | - %system 系统模式下消耗的CPU时间的比例; 37 | - %iowait CPU等待磁盘I/O导致空闲状态消耗的时间比例; 38 | - %steal 利用Xen等操作系统虚拟化技术,等待其它虚拟CPU计算占用的时间比例; 39 | - %idle CPU空闲时间比例; 40 | 41 | 查看平均负载 42 | ------------ 43 | sar -q: 查看平均负载 44 | 45 | 指定-q后,就能查看运行队列中的进程数、系统上的进程大小、平均负载等;与其它命令相比,它能查看各项指标随时间变化的情况; 46 | 47 | - runq-sz:运行队列的长度(等待运行的进程数) 48 | - plist-sz:进程列表中进程(processes)和线程(threads)的数量 49 | - ldavg-1:最后1分钟的系统平均负载 ldavg-5:过去5分钟的系统平均负载 50 | - ldavg-15:过去15分钟的系统平均负载 51 | 52 | .. image:: /_static/sar3.png 53 | :width: 800 54 | 55 | 56 | 查看内存使用状况 57 | ---------------- 58 | sar -r: 指定-r之后,可查看物理内存使用状况; 59 | 60 | .. image:: /_static/sar4.png 61 | :width: 800 62 | 63 | - kbmemfree:这个值和free命令中的free值基本一致,所以它不包括buffer和cache的空间. 64 | - kbmemused:这个值和free命令中的used值基本一致,所以它包括buffer和cache的空间. 65 | - %memused:物理内存使用率,这个值是kbmemused和内存总量(不包括swap)的一个百分比. 66 | - kbbuffers和kbcached:这两个值就是free命令中的buffer和cache. 67 | - kbcommit:保证当前系统所需要的内存,即为了确保不溢出而需要的内存(RAM+swap). 68 | - %commit:这个值是kbcommit与内存总量(包括swap)的一个百分比. 69 | 70 | 查看页面交换发生状况 71 | -------------------- 72 | sar -W:查看页面交换发生状况 73 | 74 | 页面发生交换时,服务器的吞吐量会大幅下降;服务器状况不良时,如果怀疑因为内存不足而导致了页面交换的发生,可以使用这个命令来确认是否发生了大量的交换; 75 | 76 | .. image:: /_static/sar5.png 77 | :width: 800 78 | 79 | - pswpin/s:每秒系统换入的交换页面(swap page)数量 80 | - pswpout/s:每秒系统换出的交换页面(swap page)数量 81 | 82 | 要判断系统瓶颈问题,有时需几个 sar 命令选项结合起来; 83 | 84 | - 怀疑CPU存在瓶颈,可用 sar -u 和 sar -q 等来查看 85 | - 怀疑内存存在瓶颈,可用sar -B、sar -r 和 sar -W 等来查看 86 | - 怀疑I/O存在瓶颈,可用 sar -b、sar -u 和 sar -d 等来查看 87 | 88 | 安装 89 | ---- 90 | 91 | 1. 有的linux系统下,默认可能没有安装这个包,使用apt-get install sysstat 来安装; 92 | 2. 安装完毕,将性能收集工具的开关打开: vi /etc/default/sysstat 93 | 设置 ENABLED="true" 94 | 3. 启动这个工具来收集系统性能数据: /etc/init.d/sysstat start 95 | 96 | sar参数说明 97 | ----------- 98 | 99 | - -A 汇总所有的报告 100 | - -a 报告文件读写使用情况 101 | - -B 报告附加的缓存的使用情况 102 | - -b 报告缓存的使用情况 103 | - -c 报告系统调用的使用情况 104 | - -d 报告磁盘的使用情况 105 | - -g 报告串口的使用情况 106 | - -h 报告关于buffer使用的统计数据 107 | - -m 报告IPC消息队列和信号量的使用情况 108 | - -n 报告命名cache的使用情况 109 | - -p 报告调页活动的使用情况 110 | - -q 报告运行队列和交换队列的平均长度 111 | - -R 报告进程的活动情况 112 | - -r 报告没有使用的内存页面和硬盘块 113 | - -u 报告CPU的利用率 114 | - -v 报告进程、i节点、文件和锁表状态 115 | - -w 报告系统交换活动状况 116 | - -y 报告TTY设备活动状况 117 | -------------------------------------------------------------------------------- /tool/scp.rst: -------------------------------------------------------------------------------- 1 | .. _scp: 2 | 3 | scp 跨机远程拷贝 4 | ===================== 5 | scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的。当你服务器硬盘变为只读 read only system时,用scp可以帮你把文件移出来。 6 | 7 | .. note:: 8 | 9 | 类似的工具有rsync;scp消耗资源少,不会提高多少系统负荷,在这一点上,rsync就远远不及它了。rsync比scp会快一点,但当小文件多的情况下,rsync会导致硬盘I/O非常高,而scp基本不影响系统正常使用。 10 | 11 | 命令格式: 12 | -------------------- 13 | scp [参数] [原路径] [目标路径] 14 | 15 | 命令参数: 16 | -------------------- 17 | - -1 强制scp命令使用协议ssh1 18 | - -2 强制scp命令使用协议ssh2 19 | - -4 强制scp命令只使用IPv4寻址 20 | - -6 强制scp命令只使用IPv6寻址 21 | - -B 使用批处理模式(传输过程中不询问传输口令或短语) 22 | - -C 允许压缩。(将-C标志传递给ssh,从而打开压缩功能) 23 | - -p 留原文件的修改时间,访问时间和访问权限。 24 | - -q 不显示传输进度条。 25 | - -r 递归复制整个目录。 26 | - -v 详细方式显示输出。scp和ssh(1)会显示出整个过程的调试信息。这些信息用于调试连接,验证和配置问题。 27 | - -c cipher 以cipher将数据传输进行加密,这个选项将直接传递给ssh。 28 | - -F ssh_config 指定一个替代的ssh配置文件,此参数直接传递给ssh。 29 | - -i identity_file 从指定文件中读取传输时使用的密钥文件,此参数直接传递给ssh。 30 | - -l limit 限定用户所能使用的带宽,以Kbit/s为单位。 31 | - -o ssh_option 如果习惯于使用ssh_config(5)中的参数传递方式, 32 | - -P port 注意是大写的P, port是指定数据传输用到的端口号 33 | - -S program 指定加密传输时所使用的程序。此程序必须能够理解ssh(1)的选项。 34 | 35 | 使用说明 36 | ----------- 37 | 从本地服务器复制到远程服务器 38 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 39 | 复制文件:: 40 | 41 | $scp local_file remote_username@remote_ip:remote_folder 42 | $scp local_file remote_username@remote_ip:remote_file 43 | $scp local_file remote_ip:remote_folder 44 | $scp local_file remote_ip:remote_file 45 | 46 | 指定了用户名,命令执行后需要输入用户密码;如果不指定用户名,命令执行后需要输入用户名和密码; 47 | 48 | 复制目录:: 49 | 50 | $scp -r local_folder remote_username@remote_ip:remote_folder 51 | $scp -r local_folder remote_ip:remote_folder 52 | 53 | 第1个指定了用户名,命令执行后需要输入用户密码; 54 | 第2个没有指定用户名,命令执行后需要输入用户名和密码; 55 | 56 | .. note:: 57 | 从远程复制到本地的scp命令与上面的命令一样,只要将从本地复制到远程的命令后面2个参数互换顺序就行了。 58 | 59 | 使用示例 60 | -------------------- 61 | 实例1:从远处复制文件到本地目录 62 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 63 | :: 64 | 65 | $scp root@10.6.159.147:/opt/soft/demo.tar /opt/soft/ 66 | 67 | 说明: 68 | 从10.6.159.147机器上的/opt/soft/的目录中下载demo.tar 文件到本地/opt/soft/目录中 69 | 70 | 实例2:从远处复制到本地 71 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 72 | :: 73 | 74 | $scp -r root@10.6.159.147:/opt/soft/test /opt/soft/ 75 | 76 | 说明: 77 | 从10.6.159.147机器上的/opt/soft/中下载test目录到本地的/opt/soft/目录来。 78 | 79 | 实例3:上传本地文件到远程机器指定目录 80 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 81 | :: 82 | 83 | $scp /opt/soft/demo.tar root@10.6.159.147:/opt/soft/scptest 84 | 85 | 说明: 86 | 复制本地opt/soft/目录下的文件demo.tar 到远程机器10.6.159.147的opt/soft/scptest目录 87 | 88 | 实例4:上传本地目录到远程机器指定目录 89 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 90 | :: 91 | 92 | $scp -r /opt/soft/test root@10.6.159.147:/opt/soft/scptest 93 | 94 | 说明: 95 | 上传本地目录 /opt/soft/test到远程机器10.6.159.147上/opt/soft/scptest的目录中 96 | 97 | -------------------------------------------------------------------------------- /tool/size.rst: -------------------------------------------------------------------------------- 1 | .. _size: 2 | 3 | size 查看程序内存映像大小 4 | ============================ 5 | 6 | 作用:查看程序被映射到内存中的映像所占用的大小信息。 7 | 8 | 程序映射到内存中,从低地址到高地址依次为下列段: 9 | 10 | - 代码段: 只读,可共享; 代码段(code segment/text segment )通常是指用来存放程序执行代码的一块内存区域。这部分区域的大小在程序运行前就已经确定,并且内存区域通常属于只读, 某些架构也允许代码段为可写,即允许修改程序。在代码段中,也有可能包含一些只读的常数变量,例如字符串常量等。 11 | 12 | - 数据段: 储存已被初始化了的静态数据。数据段(data segment )通常是指用来存放程序中已初始化的全局变量的一块内存区域。数据段属于静态内存分配。 13 | 14 | - BSS 段:未初始化的数据段. BSS 段(bss segment )通常是指用来存放程序中未初始化的全局变量的一块内存区域。BSS 是英文Block Started by Symbol 的简称。BSS 段属于静态内存分配。 15 | 16 | - 堆(heap ): 堆是用于存放进程运行中被动态分配的内存段,它的大小并不固定,可动态扩张或缩减。当进程调用malloc 等函数分配内存时,新分配的内存就被动态添加到堆上(堆被扩张);当利用free 等函数释放内存时,被释放的内存从堆中被剔除(堆被缩减) 17 | 18 | - 栈(stack) :栈又称堆栈,是用户存放程序临时创建的局部变量,也就是说我们函数括弧“{} ”中定义的变量(但不包括static 声明的变量,static 意味着在数据段中存放变量)。除此以外,在函数被调用时,其参数也会被压入发起调用的进程栈中,并且待到调用结束后,函数的返回值也会被存放回栈中。由于栈的先进先出特点,所以栈特别方便用来保存/ 恢复调用现场。从这个意义上讲,我们可以把堆栈看成一个寄存、交换临时数据的内存区。 19 | 20 | 另外, 在高地址还储存了命令行参数及环境变量. 21 | 22 | 因为内存程序映像中的各段可能位于不同的地址空间中, 它们不一定位于连续的内存块中. 操作系统将程序映像映射到地址空间时, 通常将内存程序映像划分为大小相同的块(也就是page, 页). 只有该页被引用时, 它才被加载到内存中. 不过对于程序员来说, 可以视内存程序映像在逻辑上是连续的. 23 | 24 | 25 | :: 26 | 27 | /opt/app/todeav1/colin/tests#size main 28 | text data bss dec hex filename 29 | 1259 540 16 1815 717 main 30 | 31 | 关于程序内存映像,这篇文章讲的很好:http://blog.chinaunix.net/uid-9012903-id-2011435.html 32 | 33 | 34 | -------------------------------------------------------------------------------- /tool/strace.rst: -------------------------------------------------------------------------------- 1 | .. _strace: 2 | 3 | strace 跟踪进程中的系统调用 4 | =========================== 5 | strace常用来跟踪进程执行时的系统调用和所接收的信号。 在Linux世界,进程不能直接访问硬件设备,当进程需要访问硬件设备(比如读取磁盘文件,接收网络数据等等)时,必须由用户态模式切换至内核态模式,通过系统调用访问硬件设备。strace可以跟踪到一个进程产生的系统调用,包括参数,返回值,执行消耗的时间。 6 | 7 | 输出参数含义 8 | -------------------- 9 | 每一行都是一条系统调用,等号左边是系统调用的函数名及其参数,右边是该调用的返回值。 10 | strace 显示这些调用的参数并返回符号形式的值。strace 从内核接收信息,而且不需要以任何特殊的方式来构建内核。 11 | 12 | :: 13 | 14 | $strace cat /dev/null 15 | execve("/bin/cat", ["cat", "/dev/null"], [/* 22 vars */]) = 0 16 | brk(0) = 0xab1000 17 | access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) 18 | mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29379a7000 19 | access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) 20 | ... 21 | 22 | 23 | 参数 24 | --------------------- 25 | :: 26 | 27 | -c 统计每一系统调用的所执行的时间,次数和出错的次数等. 28 | -d 输出strace关于标准错误的调试信息. 29 | -f 跟踪由fork调用所产生的子进程. 30 | -ff 如果提供-o filename,则所有进程的跟踪结果输出到相应的filename.pid中,pid是各进程的进程号. 31 | -F 尝试跟踪vfork调用.在-f时,vfork不被跟踪. 32 | -h 输出简要的帮助信息. 33 | -i 输出系统调用的入口指针. 34 | -q 禁止输出关于脱离的消息. 35 | -r 打印出相对时间关于,,每一个系统调用. 36 | -t 在输出中的每一行前加上时间信息. 37 | -tt 在输出中的每一行前加上时间信息,微秒级. 38 | -ttt 微秒级输出,以秒了表示时间. 39 | -T 显示每一调用所耗的时间. 40 | -v 输出所有的系统调用.一些调用关于环境变量,状态,输入输出等调用由于使用频繁,默认不输出. 41 | -V 输出strace的版本信息. 42 | -x 以十六进制形式输出非标准字符串 43 | -xx 所有字符串以十六进制形式输出. 44 | -a column 45 | 设置返回值的输出位置.默认 为40. 46 | -e expr 47 | 指定一个表达式,用来控制如何跟踪.格式如下: 48 | [qualifier=][!]value1[,value2]... 49 | qualifier只能是 trace,abbrev,verbose,raw,signal,read,write其中之一.value是用来限定的符号或数字.默认的 qualifier是 trace.感叹号是否定符号.例如: 50 | -eopen等价于 -e trace=open,表示只跟踪open调用.而-etrace!=open表示跟踪除了open以外的其他调用.有两个特殊的符号 all 和 none. 51 | 注意有些shell使用!来执行历史记录里的命令,所以要使用\\. 52 | -e trace=set 53 | 只跟踪指定的系统 调用.例如:-e trace=open,close,rean,write表示只跟踪这四个系统调用.默认的为set=all. 54 | -e trace=file 55 | 只跟踪有关文件操作的系统调用. 56 | -e trace=process 57 | 只跟踪有关进程控制的系统调用. 58 | -e trace=network 59 | 跟踪与网络有关的所有系统调用. 60 | -e strace=signal 61 | 跟踪所有与系统信号有关的 系统调用 62 | -e trace=ipc 63 | 跟踪所有与进程通讯有关的系统调用 64 | -e abbrev=set 65 | 设定 strace输出的系统调用的结果集.-v 等与 abbrev=none.默认为abbrev=all. 66 | -e raw=set 67 | 将指 定的系统调用的参数以十六进制显示. 68 | -e signal=set 69 | 指定跟踪的系统信号.默认为all.如 signal=!SIGIO(或者signal=!io),表示不跟踪SIGIO信号. 70 | -e read=set 71 | 输出从指定文件中读出 的数据.例如: 72 | -e read=3,5 73 | -e write=set 74 | 输出写入到指定文件中的数据. 75 | -o filename 76 | 将strace的输出写入文件filename 77 | -p pid 78 | 跟踪指定的进程pid. 79 | -s strsize 80 | 指定输出的字符串的最大长度.默认为32.文件名一直全部输出. 81 | -u username 82 | 以username 的UID和GID执行被跟踪的命令 83 | 84 | 命令实例 85 | -------------------- 86 | 跟踪可执行程序 87 | ^^^^^^^^^^^^^^^^^^^^ 88 | :: 89 | 90 | strace -f -F -o ~/straceout.txt myserver 91 | -f -F选项告诉strace同时跟踪fork和vfork出来的进程,-o选项把所有strace输出写到~/straceout.txt里 面,myserver是要启动和调试的程序。 92 | 93 | 跟踪服务程序 94 | ^^^^^^^^^^^^^^^^^^^^ 95 | :: 96 | 97 | strace -o output.txt -T -tt -e trace=all -p 28979 98 | 跟踪28979进程的所有系统调用(-e trace=all),并统计系统调用的花费时间,以及开始时间(并以可视化的时分秒格式显示),最后将记录结果存在output.txt文件里面。 99 | -------------------------------------------------------------------------------- /tool/vmstat.rst: -------------------------------------------------------------------------------- 1 | .. _vmstat: 2 | 3 | vmstat 监视内存使用情况 4 | ========================== 5 | vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可实时动态监视操作系统的虚拟内存、进程、CPU活动。 6 | 7 | vmstat的语法 8 | -------------------- 9 | 10 |   vmstat [-V] [-n] [delay [count]] 11 | 12 | * -V表示打印出版本信息; 13 | * -n表示在周期性循环输出时,输出的头部信息仅显示一次; 14 | * delay是两次输出之间的延迟时间; 15 | * count是指按照这个时间间隔统计的次数。 16 | 17 | 18 | :: 19 | 20 | /root$vmstat 5 5 21 | procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- 22 | r b swpd free buff cache si so bi bo in cs us sy id wa st 23 | 6 0 0 27900472 204216 28188356 0 0 0 9 1 2 11 14 75 0 0 24 | 9 0 0 27900380 204228 28188360 0 0 0 13 33312 126221 22 20 58 0 0 25 | 2 0 0 27900340 204240 28188364 0 0 0 10 32755 125566 22 20 58 0 0 26 | 27 | 28 | 字段说明 29 | ----------------- 30 | Procs(进程): 31 | * r: 运行队列中进程数量 32 | * b: 等待IO的进程数量 33 | 34 | Memory(内存): 35 | * swpd: 使用虚拟内存大小 36 | * free: 可用内存大小 37 | * buff: 用作缓冲的内存大小 38 | * cache: 用作缓存的内存大小 39 | 40 | Swap: 41 | * si: 每秒从交换区写到内存的大小 42 | * so: 每秒写入交换区的内存大小 43 | 44 | IO:(现在的Linux版本块的大小为1024bytes) 45 | * bi: 每秒读取的块数 46 | * bo: 每秒写入的块数 47 | 48 | system: 49 | * in: 每秒中断数,包括时钟中断 50 | * cs: 每秒上下文切换数 51 | 52 | CPU(以百分比表示) 53 | * us: 用户进程执行时间(user time) 54 | * sy: 系统进程执行时间(system time) 55 | * id: 空闲时间(包括IO等待时间) 56 | * wa: 等待IO时间 57 | 58 | -------------------------------------------------------------------------------- /tool/wget.rst: -------------------------------------------------------------------------------- 1 | .. _wget: 2 | 3 | wget 文件下载 4 | ============== 5 | 6 | Linux系统中的wget是一个下载文件的工具,它用在命令行下。对于Linux用户是必不可少的工具,我们经常要下载一些软件或从远程服务器恢复备份到本地服务器。wget支持HTTP,HTTPS和FTP协议,可以使用HTTP代理。 7 | 8 | wget 可以跟踪HTML页面上的链接依次下载来创建远程服务器的本地版本,完全重建原始站点的目录结构。这又常被称作”递归下载”。在递归下载的时候,wget 遵循Robot Exclusion标准(/robots.txt). wget可以在下载的同时,将链接转换成指向本地文件,以方便离线浏览。 9 | 10 | wget 非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性.如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕。如果是服务器打断下载过程,它会再次联到服务器上从停止的地方继续下载。这对从那些限定了链接时间的服务器上下载大文件非常有用。 11 | 12 | 命令格式 13 | -------------------- 14 | wget [参数] [URL地址] 15 | 16 | 17 | 命令参数: 18 | -------------------- 19 | 启动参数: 20 | ~~~~~~~~~~~~~~~~~~~~~ 21 | - -V, –version 显示wget的版本后退出 22 | - -h, –help 打印语法帮助 23 | - -b, –background 启动后转入后台执行 24 | - -e, –execute=COMMAND 执行'.wgetrc'格式的命令,wgetrc格式参见/etc/wgetrc或~/.wgetrc 25 | 26 | 记录和输入文件参数 27 | ~~~~~~~~~~~~~~~~~~~~ 28 | - -o, –output-file=FILE 把记录写到FILE文件中 29 | - -a, –append-output=FILE 把记录追加到FILE文件中 30 | - -d, –debug 打印调试输出 31 | - -q, –quiet 安静模式(没有输出) 32 | - -v, –verbose 冗长模式(这是缺省设置) 33 | - -nv, –non-verbose 关掉冗长模式,但不是安静模式 34 | - -i, –input-file=FILE 下载在FILE文件中出现的URLs 35 | - -F, –force-html 把输入文件当作HTML格式文件对待 36 | - -B, –base=URL 将URL作为在-F -i参数指定的文件中出现的相对链接的前缀 37 | –sslcertfile=FILE 可选客户端证书 38 | –sslcertkey=KEYFILE 可选客户端证书的KEYFILE 39 | –egd-file=FILE 指定EGD socket的文件名 40 | 41 | 下载参数 42 | ~~~~~~~~~~ 43 | - -bind-address=ADDRESS 指定本地使用地址(主机名或IP,当本地有多个IP或名字时使用) 44 | - -t, –tries=NUMBER 设定最大尝试链接次数(0 表示无限制). 45 | - -O –output-document=FILE 把文档写到FILE文件中 46 | - -nc, –no-clobber 不要覆盖存在的文件或使用.#前缀 47 | - -c, –continue 接着下载没下载完的文件 48 | - -progress=TYPE 设定进程条标记 49 | - -N, –timestamping 不要重新下载文件除非比本地文件新 50 | - -S, –server-response 打印服务器的回应 51 | - -T, –timeout=SECONDS 设定响应超时的秒数 52 | - -w, –wait=SECONDS 两次尝试之间间隔SECONDS秒 53 | - -waitretry=SECONDS 在重新链接之间等待1…SECONDS秒 54 | - -random-wait 在下载之间等待0…2*WAIT秒 55 | - -Y, -proxy=on/off 打开或关闭代理 56 | - -Q, -quota=NUMBER 设置下载的容量限制 57 | - -limit-rate=RATE 限定下载输率 58 | 59 | 目录参数 60 | ~~~~~~~~~~~~~~ 61 | - -nd –no-directories 不创建目录 62 | - -x, –force-directories 强制创建目录 63 | - -nH, –no-host-directories 不创建主机目录 64 | - -P, –directory-prefix=PREFIX 将文件保存到目录 PREFIX/… 65 | - -cut-dirs=NUMBER 忽略 NUMBER层远程目录 66 | 67 | HTTP 选项参数 68 | ~~~~~~~~~~~~~~~~~ 69 | - -http-user=USER 设定HTTP用户名为 USER. 70 | - -http-passwd=PASS 设定http密码为 PASS 71 | - -C, –cache=on/off 允许/不允许服务器端的数据缓存 (一般情况下允许) 72 | - -E, –html-extension 将所有text/html文档以.html扩展名保存 73 | - -ignore-length 忽略 'Content-Length'头域 74 | - -header=STRING 在headers中插入字符串 STRING 75 | - -proxy-user=USER 设定代理的用户名为 USER 76 | - proxy-passwd=PASS 设定代理的密码为 PASS 77 | - referer=URL 在HTTP请求中包含 'Referer: URL'头 78 | - -s, –save-headers 保存HTTP头到文件 79 | - -U, –user-agent=AGENT 设定代理的名称为 AGENT而不是 Wget/VERSION 80 | - no-http-keep-alive 关闭 HTTP活动链接 (永远链接) 81 | - cookies=off 不使用 cookies 82 | - load-cookies=FILE 在开始会话前从文件 FILE中加载cookie 83 | - save-cookies=FILE 在会话结束后将 cookies保存到 FILE文件中 84 | 85 | FTP 选项参数 86 | ~~~~~~~~~~~~~~ 87 | - -nr, –dont-remove-listing 不移走 '.listing'文件 88 | - -g, –glob=on/off 打开或关闭文件名的 globbing机制 89 | - passive-ftp 使用被动传输模式 (缺省值). 90 | - active-ftp 使用主动传输模式 91 | - retr-symlinks 在递归的时候,将链接指向文件(而不是目录) 92 | 93 | 递归下载参数 94 | ~~~~~~~~~~~~~~~ 95 | - -r, –recursive 递归下载--慎用! 96 | - -l, –level=NUMBER 最大递归深度 (inf 或 0 代表无穷) 97 | - -delete-after 在现在完毕后局部删除文件 98 | - -k, –convert-links 转换非相对链接为相对链接 99 | - -K, –backup-converted 在转换文件X之前,将之备份为 X.orig 100 | - -m, –mirror 等价于 -r -N -l inf -nr 101 | - -p, –page-requisites 下载显示HTML文件的所有图片 102 | 递归下载中的包含和不包含(accept/reject): 103 | - -A, –accept=LIST 分号分隔的被接受扩展名的列表 104 | - -R, –reject=LIST 分号分隔的不被接受的扩展名的列表 105 | - -D, –domains=LIST 分号分隔的被接受域的列表 106 | - -exclude-domains=LIST 分号分隔的不被接受的域的列表 107 | - -follow-ftp 跟踪HTML文档中的FTP链接 108 | - -follow-tags=LIST 分号分隔的被跟踪的HTML标签的列表 109 | - -G, –ignore-tags=LIST 分号分隔的被忽略的HTML标签的列表 110 | - -H, –span-hosts 当递归时转到外部主机 111 | - -L, –relative 仅仅跟踪相对链接 112 | - -I, –include-directories=LIST 允许目录的列表 113 | - -X, –exclude-directories=LIST 不被包含目录的列表 114 | - -np, –no-parent 不要追溯到父目录 115 | wget -S –spider url 不下载只显示过程 116 | 117 | 使用实例 118 | --------------- 119 | 实例1:使用wget下载单个文件 120 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 121 | :: 122 | 123 | $wget http://www.minjieren.com/wordpress-3.1-zh_CN.zip 124 | 125 | 说明:以上例子从网络下载一个文件并保存在当前目录,在下载的过程中会显示进度条,包含(下载完成百分比,已经下载的字节,当前下载速度,剩余下载时间)。 126 | 127 | 实例2:使用wget -O下载并以不同的文件名保存 128 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 129 | :: 130 | 131 | $wget -O wordpress.zip http://www.minjieren.com/download.aspx?id=1080 132 | 133 | wget默认会以最后一个符合”/”的后面的字符来命令,对于动态链接的下载通常文件名会不正确。 134 | 135 | 实例3:使用wget –limit -rate限速下载 136 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 137 | :: 138 | 139 | $wget --limit-rate=300k http://www.minjieren.com/wordpress-3.1-zh_CN.zip 140 | 141 | 当你执行wget的时候,它默认会占用全部可能的宽带下载。但是当你准备下载一个大文件,而你还需要下载其它文件时就有必要限速了。 142 | 143 | 实例4:使用wget -c断点续传 144 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 145 | :: 146 | 147 | $wget -c http://www.minjieren.com/wordpress-3.1-zh_CN.zip 148 | 149 | 使用wget -c重新启动下载中断的文件,对于我们下载大文件时突然由于网络等原因中断非常有帮助,我们可以继续接着下载而不是重新下载一个文件。需要继续中断的下载时可以使用-c参数。 150 | 151 | 实例5:使用wget -b后台下载 152 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 153 | :: 154 | 155 | $wget -b http://www.minjieren.com/wordpress-3.1-zh_CN.zip 156 | Continuing in background, pid 1840. 157 | Output will be written to 'wget-log'. 158 | 159 | 160 | 对于下载非常大的文件的时候,我们可以使用参数-b进行后台下载。 161 | 162 | 你可以使用以下命令来察看下载进度:: 163 | 164 | $tail -f wget-log 165 | 166 | 实例6:伪装代理名称下载 167 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 168 | :: 169 | 170 | wget --user-agent="Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16" http://www.minjieren.com/wordpress-3.1-zh_CN.zip 171 | 172 | 有些网站能通过根据判断代理名称不是浏览器而拒绝你的下载请求。不过你可以通过–user-agent参数伪装。 173 | 174 | 175 | 实例7:使用wget -i下载多个文件 176 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 177 | 首先,保存一份下载链接文件,接着使用这个文件和参数-i下载:: 178 | 179 | $cat > filelist.txt 180 | url1 181 | url2 182 | url3 183 | url4 184 | 185 | $wget -i filelist.txt 186 | 187 | 实例8:使用wget –mirror镜像网站 188 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 189 | :: 190 | 191 | $wget --mirror -p --convert-links -P ./LOCAL URL 192 | 193 | 194 | 下载整个网站到本地 195 | - -miror:开户镜像下载 196 | - -p:下载所有为了html页面显示正常的文件 197 | - -convert-links:下载后,转换成本地的链接 198 | - -P ./LOCAL:保存所有文件和目录到本地指定目录 199 | 200 | 201 | 实例9: 使用wget -r -A下载指定格式文件 202 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 203 | :: 204 | 205 | $wget -r -A.pdf url 206 | 207 | 可以在以下情况使用该功能: 208 | * 下载一个网站的所有图片 209 | * 下载一个网站的所有视频 210 | * 下载一个网站的所有PDF文件 211 | 212 | 实例10:使用wget FTP下载 213 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 214 | :: 215 | 216 | $wget ftp-url 217 | $wget --ftp-user=USERNAME --ftp-password=PASSWORD url 218 | 219 | 可以使用wget来完成ftp链接的下载 220 | * 使用wget匿名ftp下载:wget ftp-url 221 | * 使用wget用户名和密码认证的ftp下载:wget --ftp-user=USERNAME --ftp-password=PASSWORD url 222 | 223 | 编译安装 224 | ----------------- 225 | 使用如下命令编译安装:: 226 | 227 | tar zxvf wget-1.9.1.tar.gz 228 | cd wget-1.9.1 229 | ./configure 230 | make 231 | make install 232 | 233 | -------------------------------------------------------------------------------- /top.md: -------------------------------------------------------------------------------- 1 | Linux命令工具 top详解 2 | 3 | top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器。top是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终止该程序为止.比较准确的说,top命令提供了实时的对系统处理器的状态监视.它将显示系统中CPU最“敏感”的任务列表.该命令可以按CPU使用.内存使用和执行时间对任务进行排序;而且该命令的很多特性都可以通过交互式命令或者在个人定制文件中进行设定。 4 | 常在linux系统下玩,这是必须掌握的命令之一; 5 | 下面详细说说这个命令: 6 | 7 | 敲入top进入: 8 | ``` 9 | top - 09:14:56 up 264 days, 20:56, 1 user, load average: 0.02, 0.04, 0.00 10 | Tasks: 87 total, 1 running, 86 sleeping, 0 stopped, 0 zombie 11 | Cpu(s): 0.0%us, 0.2%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.2%st 12 | Mem: 377672k total, 322332k used, 55340k free, 32592k buffers 13 | Swap: 397308k total, 67192k used, 330116k free, 71900k cached 14 | PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 15 | 1 root 20 0 2856 656 388 S 0.0 0.2 0:49.40 init 16 | 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 17 | 3 root 20 0 0 0 0 S 0.0 0.0 7:15.20 ksoftirqd/0 18 | 4 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 19 | 20 | ``` 21 | 22 | ## 第一行 23 | 09:14:56 : 系统当前时间 24 | 264 days, 20:56 : 系统开机到现在经过了多少时间 25 | 1 users : 当前2用户在线 26 | load average: 0.02, 0.04, 0.00: 系统1分钟、5分钟、15分钟的CPU负载信息 27 | 28 | ## 第二行 29 | Tasks:任务; 30 | 87 total:很好理解,就是当前有87个任务,也就是87个进程。 31 | 1 running:1个进程正在运行 32 | 86 sleeping:86个进程睡眠 33 | 0 stopped:停止的进程数 34 | 0 zombie:僵死的进程数 35 | 36 | ## 第三行 37 | Cpu(s):表示这一行显示CPU总体信息 38 | 0.0%us:用户态进程占用CPU时间百分比,不包含renice值为负的任务占用的CPU的时间。 39 | 0.7%sy:内核占用CPU时间百分比 40 | 0.0%ni:改变过优先级的进程占用CPU的百分比 41 | 99.3%id:空闲CPU时间百分比 42 | 0.0%wa:等待I/O的CPU时间百分比 43 | 0.0%hi:CPU硬中断时间百分比 44 | 0.0%si:CPU软中断时间百分比 45 | 注:这里显示数据是所有cpu的平均值,如果想看每一个cpu的处理情况,按1即可;折叠,再次按1; 46 | 47 | ## 第四行 48 | Men:内存的意思 49 | 8175320kk total:物理内存总量 50 | 8058868k used:使用的物理内存量 51 | 116452k free:空闲的物理内存量 52 | 283084k buffers:用作内核缓存的物理内存量 53 | 54 | ## 第五行 55 | Swap:交换空间 56 | 6881272k total:交换区总量 57 | 4010444k used:使用的交换区量 58 | 2870828k free:空闲的交换区量 59 | 4336992k cached:缓冲交换区总量 60 | 61 | ## 进程信息 62 | 再下面就是进程信息: 63 | PID:进程的ID 64 | USER:进程所有者 65 | PR:进程的优先级别,越小越优先被执行 66 | NInice:值 67 | VIRT:进程占用的虚拟内存 68 | RES:进程占用的物理内存 69 | SHR:进程使用的共享内存 70 | S:进程的状态。S表示休眠,R表示正在运行,Z表示僵死状态,N表示该进程优先值为负数 71 | %CPU:进程占用CPU的使用率 72 | %MEM:进程使用的物理内存和总内存的百分比 73 | TIME+:该进程启动后占用的总的CPU时间,即占用CPU使用时间的累加值。 74 | COMMAND:进程启动命令名称 75 | 76 | ## top命令交互操作指令 77 | 下面列出一些常用的 top命令操作指令 78 | ``` 79 | q:退出top命令 80 | :立即刷新 81 | s:设置刷新时间间隔 82 | c:显示命令完全模式 83 | t::显示或隐藏进程和CPU状态信息 84 | m:显示或隐藏内存状态信息 85 | l:显示或隐藏uptime信息 86 | f:增加或减少进程显示标志 87 | S:累计模式,会把已完成或退出的子进程占用的CPU时间累计到父进程的MITE+ 88 | P:按%CPU使用率排行 89 | T:按MITE+排行 90 | M:按%MEM排行 91 | u:指定显示用户进程 92 | r:修改进程renice值 93 | kkill:进程 94 | i:只显示正在运行的进程 95 | W:保存对top的设置到文件~/.toprc,下次启动将自动调用toprc文件的设置。 96 | h:帮助命令。 97 | q:退出 98 | ``` 99 | 100 | 注:强调一下,使用频率最高的是P、T、M,因为通常使用top,我们就想看看是哪些进程最耗cpu资源、占用的内存最多; 101 | 注:通过”shift + >”或”shift + <”可以向右或左改变排序列 102 | 如果只需要查看内存:可用free命令。只查看uptime信息(第一行),可用uptime命令; 103 | 104 | ## 实例 105 | ### 实例1:多U多核CPU监控 106 | 在top基本视图中,按键盘数字“1”,可监控每个逻辑CPU的状况; 107 | ``` 108 | [rdtfr@bl685cb4-t ~]$ top 109 | top - 09:10:44 up 20 days, 16:51, 4 users, load average: 3.82, 4.40, 4.40 110 | Tasks: 1201 total, 10 running, 1189 sleeping, 0 stopped, 2 zombie 111 | Cpu0 : 1.3%us, 2.3%sy, 0.0%ni, 96.4%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st 112 | Cpu1 : 1.3%us, 2.6%sy, 0.0%ni, 96.1%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st 113 | Cpu2 : 1.0%us, 2.0%sy, 0.0%ni, 92.5%id, 0.0%wa, 0.0%hi, 4.6%si, 0.0%st 114 | Cpu3 : 3.9%us, 7.8%sy, 0.0%ni, 83.2%id, 0.0%wa, 0.0%hi, 5.2%si, 0.0%st 115 | Cpu4 : 4.2%us, 10.4%sy, 0.0%ni, 63.8%id, 0.0%wa, 0.0%hi, 21.5%si, 0.0%st 116 | Cpu5 : 6.8%us, 12.7%sy, 0.0%ni, 80.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st 117 | Cpu6 : 2.9%us, 7.2%sy, 0.0%ni, 85.3%id, 0.0%wa, 0.0%hi, 4.6%si, 0.0%st 118 | Cpu7 : 6.2%us, 13.0%sy, 0.0%ni, 75.3%id, 0.0%wa, 0.0%hi, 5.5%si, 0.0%st 119 | Mem: 32943888k total, 32834216k used, 109672k free, 642704k buffers 120 | Swap: 35651576k total, 5761928k used, 29889648k free, 16611500k cached 121 | ``` 122 | 123 | ### 实例2:高亮显示当前运行进程 124 | ``` 125 | 在top基本视图中,按键盘“b”(打开/关闭加亮效果); 126 | ``` 127 | 128 | ### 实例3:显示完整的程序命令 129 | 命令:top -c 130 | ``` 131 | [rdtfr@bl685cb4-t ~]$ top -c 132 | top - 09:14:35 up 20 days, 16:55, 4 users, load average: 5.77, 5.01, 4.64 133 | Tasks: 1200 total, 5 running, 1192 sleeping, 0 stopped, 3 zombie 134 | Cpu(s): 4.4%us, 6.0%sy, 0.0%ni, 83.8%id, 0.2%wa, 0.0%hi, 5.5%si, 0.0%st 135 | Mem: 32943888k total, 32842896k used, 100992k free, 591484k buffers 136 | Swap: 35651576k total, 5761808k used, 29889768k free, 16918824k cached 137 | PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 138 | 2013 apache 18 0 403m 88m 5304 S 25.0 0.3 6:37.44 /usr/sbin/httpd 139 | 18335 pubtest 22 0 65576 996 728 R 7.8 0.0 0:00.24 netstat -naltp 140 | 16499 rdtfare 15 0 13672 2080 824 R 2.6 0.0 0:00.38 top -c 141 | 29684 rdtfare 15 0 1164m 837m 14m S 2.3 2.6 148:47.54 ./autodata data1.txt 142 | 12976 pubtest 18 0 238m 9000 1932 S 1.6 0.0 439:28.44 tscagent -s TOEV_P 143 | ``` 144 | 145 | ### 实例4:显示指定的进程信息 146 | 命令:top -p pidid 147 | ``` 148 | /opt/app/tdv1/config#top -p 17265 149 | top - 09:17:34 up 455 days, 17:55, 2 users, load average: 3.76, 4.56, 4.46 150 | Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie 151 | Cpu(s): 7.8%us, 1.9%sy, 0.0%ni, 89.2%id, 0.0%wa, 0.1%hi, 1.0%si, 0.0%st 152 | Mem: 8175452k total, 8103988k used, 71464k free, 268716k buffers 153 | Swap: 6881272k total, 4275424k used, 2605848k free, 6338184k cached 154 | PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 155 | 17265 tdv1 15 0 56504 828 632 S 0.0 0.0 195:53.25 redis-server 156 | ``` 157 | 158 | 159 | Posted by: 大CC | 14JUL,2014 160 | 博客:[blog.me115.com](http://blog.me115.com) [[订阅](http://feed.feedsky.com/me115)] 161 | 微博:[新浪微博](http://weibo.com/bigcc115) 162 | 163 | -------------------------------------------------------------------------------- /top.rst: -------------------------------------------------------------------------------- 1 | Linux命令工具 top详解 2 | 3 | top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器。top是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终止该程序为止.比较准确的说,top命令提供了实时的对系统处理器的状态监视.它将显示系统中CPU最“敏感”的任务列表.该命令可以按CPU使用.内存使用和执行时间对任务进行排序;而且该命令的很多特性都可以通过交互式命令或者在个人定制文件中进行设定。 4 | 常在linux系统下玩,这是必须掌握的命令之一; 5 | 下面详细说说这个命令: 6 | 7 | 敲入top进入: 8 | :: 9 | 10 | top - 09:14:56 up 264 days, 20:56, 1 user, load average: 0.02, 0.04, 0.00 11 | Tasks: 87 total, 1 running, 86 sleeping, 0 stopped, 0 zombie 12 | Cpu(s): 0.0%us, 0.2%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.2%st 13 | Mem: 377672k total, 322332k used, 55340k free, 32592k buffers 14 | Swap: 397308k total, 67192k used, 330116k free, 71900k cached 15 | PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 16 | 1 root 20 0 2856 656 388 S 0.0 0.2 0:49.40 init 17 | 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 18 | 3 root 20 0 0 0 0 S 0.0 0.0 7:15.20 ksoftirqd/0 19 | 4 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 20 | 21 | 22 | 第一行 23 | ------------- 24 | 09:14:56 : 系统当前时间 25 | 264 days, 20:56 : 系统开机到现在经过了多少时间 26 | 1 users : 当前2用户在线 27 | load average: 0.02, 0.04, 0.00: 系统1分钟、5分钟、15分钟的CPU负载信息 28 | 29 | 第二行 30 | ------------- 31 | Tasks:任务; 32 | 87 total:很好理解,就是当前有87个任务,也就是87个进程。 33 | 1 running:1个进程正在运行 34 | 86 sleeping:86个进程睡眠 35 | 0 stopped:停止的进程数 36 | 0 zombie:僵死的进程数 37 | 38 | 第三行 39 | ------------- 40 | Cpu(s):表示这一行显示CPU总体信息 41 | 0.0%us:用户态进程占用CPU时间百分比,不包含renice值为负的任务占用的CPU的时间。 42 | 0.7%sy:内核占用CPU时间百分比 43 | 0.0%ni:改变过优先级的进程占用CPU的百分比 44 | 99.3%id:空闲CPU时间百分比 45 | 0.0%wa:等待I/O的CPU时间百分比 46 | 0.0%hi:CPU硬中断时间百分比 47 | 0.0%si:CPU软中断时间百分比 48 | 注:这里显示数据是所有cpu的平均值,如果想看每一个cpu的处理情况,按1即可;折叠,再次按1; 49 | 50 | 第四行 51 | ------------- 52 | Men:内存的意思 53 | 8175320kk total:物理内存总量 54 | 8058868k used:使用的物理内存量 55 | 116452k free:空闲的物理内存量 56 | 283084k buffers:用作内核缓存的物理内存量 57 | 58 | 第五行 59 | ------------- 60 | Swap:交换空间 61 | 6881272k total:交换区总量 62 | 4010444k used:使用的交换区量 63 | 2870828k free:空闲的交换区量 64 | 4336992k cached:缓冲交换区总量 65 | 66 | 进程信息 67 | ---------------- 68 | 再下面就是进程信息: 69 | PID:进程的ID 70 | USER:进程所有者 71 | PR:进程的优先级别,越小越优先被执行 72 | NInice:值 73 | VIRT:进程占用的虚拟内存 74 | RES:进程占用的物理内存 75 | SHR:进程使用的共享内存 76 | S:进程的状态。S表示休眠,R表示正在运行,Z表示僵死状态,N表示该进程优先值为负数 77 | %CPU:进程占用CPU的使用率 78 | %MEM:进程使用的物理内存和总内存的百分比 79 | TIME+:该进程启动后占用的总的CPU时间,即占用CPU使用时间的累加值。 80 | COMMAND:进程启动命令名称 81 | 82 | top命令交互操作指令 83 | ------------------------------- 84 | 下面列出一些常用的 top命令操作指令 85 | :: 86 | 87 | q:退出top命令 88 | :立即刷新 89 | s:设置刷新时间间隔 90 | c:显示命令完全模式 91 | t::显示或隐藏进程和CPU状态信息 92 | m:显示或隐藏内存状态信息 93 | l:显示或隐藏uptime信息 94 | f:增加或减少进程显示标志 95 | S:累计模式,会把已完成或退出的子进程占用的CPU时间累计到父进程的MITE+ 96 | P:按%CPU使用率排行 97 | T:按MITE+排行 98 | M:按%MEM排行 99 | u:指定显示用户进程 100 | r:修改进程renice值 101 | kkill:进程 102 | i:只显示正在运行的进程 103 | W:保存对top的设置到文件~/.toprc,下次启动将自动调用toprc文件的设置。 104 | h:帮助命令。 105 | q:退出 106 | 107 | 注:强调一下,使用频率最高的是P、T、M,因为通常使用top,我们就想看看是哪些进程最耗cpu资源、占用的内存最多; 108 | 注:通过”shift + >”或”shift + <”可以向右或左改变排序列 109 | 如果只需要查看内存:可用free命令。只查看uptime信息(第一行),可用uptime命令; 110 | 111 | 实例 112 | ---------- 113 | 实例1:多U多核CPU监控 114 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 115 | 在top基本视图中,按键盘数字“1”,可监控每个逻辑CPU的状况; 116 | :: 117 | 118 | [rdtfr@bl685cb4-t ~]$ top 119 | top - 09:10:44 up 20 days, 16:51, 4 users, load average: 3.82, 4.40, 4.40 120 | Tasks: 1201 total, 10 running, 1189 sleeping, 0 stopped, 2 zombie 121 | Cpu0 : 1.3%us, 2.3%sy, 0.0%ni, 96.4%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st 122 | Cpu1 : 1.3%us, 2.6%sy, 0.0%ni, 96.1%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st 123 | Cpu2 : 1.0%us, 2.0%sy, 0.0%ni, 92.5%id, 0.0%wa, 0.0%hi, 4.6%si, 0.0%st 124 | Cpu3 : 3.9%us, 7.8%sy, 0.0%ni, 83.2%id, 0.0%wa, 0.0%hi, 5.2%si, 0.0%st 125 | Cpu4 : 4.2%us, 10.4%sy, 0.0%ni, 63.8%id, 0.0%wa, 0.0%hi, 21.5%si, 0.0%st 126 | Cpu5 : 6.8%us, 12.7%sy, 0.0%ni, 80.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st 127 | Cpu6 : 2.9%us, 7.2%sy, 0.0%ni, 85.3%id, 0.0%wa, 0.0%hi, 4.6%si, 0.0%st 128 | Cpu7 : 6.2%us, 13.0%sy, 0.0%ni, 75.3%id, 0.0%wa, 0.0%hi, 5.5%si, 0.0%st 129 | Mem: 32943888k total, 32834216k used, 109672k free, 642704k buffers 130 | Swap: 35651576k total, 5761928k used, 29889648k free, 16611500k cached 131 | 132 | 实例2:高亮显示当前运行进程 133 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 134 | :: 135 | 136 | 在top基本视图中,按键盘“b”(打开/关闭加亮效果); 137 | 138 | 实例3:显示完整的程序命令 139 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 140 | 命令:top -c 141 | :: 142 | 143 | [rdtfr@bl685cb4-t ~]$ top -c 144 | top - 09:14:35 up 20 days, 16:55, 4 users, load average: 5.77, 5.01, 4.64 145 | Tasks: 1200 total, 5 running, 1192 sleeping, 0 stopped, 3 zombie 146 | Cpu(s): 4.4%us, 6.0%sy, 0.0%ni, 83.8%id, 0.2%wa, 0.0%hi, 5.5%si, 0.0%st 147 | Mem: 32943888k total, 32842896k used, 100992k free, 591484k buffers 148 | Swap: 35651576k total, 5761808k used, 29889768k free, 16918824k cached 149 | PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 150 | 2013 apache 18 0 403m 88m 5304 S 25.0 0.3 6:37.44 /usr/sbin/httpd 151 | 18335 pubtest 22 0 65576 996 728 R 7.8 0.0 0:00.24 netstat -naltp 152 | 16499 rdtfare 15 0 13672 2080 824 R 2.6 0.0 0:00.38 top -c 153 | 29684 rdtfare 15 0 1164m 837m 14m S 2.3 2.6 148:47.54 ./autodata data1.txt 154 | 12976 pubtest 18 0 238m 9000 1932 S 1.6 0.0 439:28.44 tscagent -s TOEV_P 155 | 156 | 实例4:显示指定的进程信息 157 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 158 | 命令:top -p pidid 159 | :: 160 | 161 | /opt/app/tdv1/config#top -p 17265 162 | top - 09:17:34 up 455 days, 17:55, 2 users, load average: 3.76, 4.56, 4.46 163 | Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie 164 | Cpu(s): 7.8%us, 1.9%sy, 0.0%ni, 89.2%id, 0.0%wa, 0.1%hi, 1.0%si, 0.0%st 165 | Mem: 8175452k total, 8103988k used, 71464k free, 268716k buffers 166 | Swap: 6881272k total, 4275424k used, 2605848k free, 6338184k cached 167 | PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 168 | 17265 tdv1 15 0 56504 828 632 S 0.0 0.0 195:53.25 redis-server 169 | 170 | 171 | Posted by: 大CC | 14JUL,2014 172 | 博客:[blog.me115.com](http://blog.me115.com) [[订阅](http://feed.feedsky.com/me115)] 173 | 微博:[新浪微博](http://weibo.com/bigcc115) 174 | 175 | --------------------------------------------------------------------------------