06 2015 档案

tShell 程序设计
摘要:1. 设计一个shell程序,在每月第一天备份并压缩/etc目录的所有内容,存放在/root/bak目录里,且文件名为如下形式yymmdd_etc,yy为年,mm为月,dd为日。Shell程序fileback存放在/usr/bin目录下1)首先编写备份文件的脚本fileback.sh#!/bin/b... 阅读全文

posted @ 2015-06-11 13:52 karenwang 阅读(2471) 评论(0) 推荐(0)

强大的grep
摘要:语法# grep match_pattern filename //将会输出符合match_pattern规定的内容,match pattern为通配符# grep -E match_pattern filename //这里的match_pattern为正则表达式# grep -o -E matc... 阅读全文

posted @ 2015-06-07 13:20 karenwang 阅读(156) 评论(0) 推荐(0)

流程控制与比较
摘要:shell中值的比较条件通常放在封闭的中括号内。注意在括号[ ]与操作数之间必须有一个空格。如果没有空格,就会报错。正确的使用方式:# if [ $var -gt 0 ]; then echo "pass"; fi //注意 if与[之间的空格 $var之前的空格 0之后的空格 都是必须有的pass... 阅读全文

posted @ 2015-06-05 18:16 karenwang 阅读(186) 评论(0) 推荐(0)

获取/设置/重置系统时间
摘要:日期内容 格式 星期 %a (例如: Sat)%A (例如Saturday) 月%b(例如:NOV)%B(例如November) 日... 阅读全文

posted @ 2015-06-05 14:49 karenwang 阅读(754) 评论(0) 推荐(0)

获取终端信息
摘要:在编写shell时,需要处理大量当前终端的信息,比如行数,列数,光标位置,隐藏密码等。tput和stty是两款中断处理工具。获取终端的行数和列数# tput cols67# tput lines24将光标移动到指定位置# tput cup 10 20设置终端颜色tput setf no //no可以... 阅读全文

posted @ 2015-06-05 12:32 karenwang 阅读(511) 评论(0) 推荐(0)

用shell定义和访问数组
摘要:定义数组arr=(1 2 3 4 5)访问数组# echo ${arr[0]}1打印数组中所有的值#echo ${arr[*]}1 2 3 4 5打印数组长度# echo ${#arr[*]}5以上定义的数组,索引只能为数字,下面将介绍关联数组关联数组首先需要用单独的语句将变量声明为关联数组# de... 阅读全文

posted @ 2015-06-05 12:19 karenwang 阅读(2809) 评论(0) 推荐(0)

文件描述符和重定向
摘要:文件描述符是一个打开的文件或数据流相关联的证书0-------stdin 标准输入1-------stdout 标准输出2-------stderr 标准错误# echo “this is a file” > file.txt //将this is a file 重定向到文件file.txt中# e... 阅读全文

posted @ 2015-06-04 22:31 karenwang 阅读(390) 评论(0) 推荐(0)

基本shell命令
摘要:设置环境变量#Set JAVA_HOME=/root/deploy_ws/jre1.8.0#PATH="$PATH:/home/user/bin"计算字符串的长度#var="12345"#echo ${#var}当前使用的shell#echo $SHELL查询当前用户的角色#echo $UID //... 阅读全文

posted @ 2015-06-04 21:45 karenwang 阅读(196) 评论(0) 推荐(0)

如何输出部分文件
摘要:在一个文件很大时,不可能使用cat把文件的所有内容都输出。有时候我们只关注前10行或者后10行,如何输出呢?# head file.txt //输出前10行# cat file.txt | head //输出前10行# head -n 4 file.txt //输出前4行# head -n -1 f... 阅读全文

posted @ 2015-06-04 15:52 karenwang 阅读(317) 评论(0) 推荐(0)

发现symbolic link以及它的target
摘要:创建symbolic link# ln -s target symbolic_link_name例如:# ln -s /root/deploy_ws/jre1.9.0/lib/i386/libnpjp2.so /usr/lib/firefox/plugins/libnpjp2.so (在linux上... 阅读全文

posted @ 2015-06-04 14:48 karenwang 阅读(570) 评论(0) 推荐(0)

使用touch创建空文件以及修改文件的timestamp
摘要:touch filename如果一个文件存在,touch将更新与这个文件相关的所有timestamp到当前时间touch -a filename //只修改访问时间touch -m filename //只修改更新时间使用touch -d 可以指定timestamp,如:touch -d "Fr... 阅读全文

posted @ 2015-06-04 13:54 karenwang 阅读(330) 评论(0) 推荐(0)

如何查看和修改文件权限
摘要:查看文件权限# ls -ltotal 59056-rw-r--r-- 1 root root 36 Jun 3 05:20 A.txt-rw-r--r-- 1 root root 27 Jun 3 05:20 B.txt-rw-r--r-- 1 root root ... 阅读全文

posted @ 2015-06-04 13:40 karenwang 阅读(7763) 评论(0) 推荐(0)

shell command cat/find/tr/mkdir
摘要:1. cat cat is used to read, display, or concatenate the contents of a filecat file.txt //show the content of file.txt 显示file.txt中的内容cat file.txt... 阅读全文

posted @ 2015-06-02 13:54 karenwang 阅读(233) 评论(0) 推荐(0)

How to solve "/bin/sh^M:bad interpreter: No such file or directory"
摘要:1. The issue is because windows and linux has different file system.2. Use vim to open the file3. Type :set ff?, you will see the text "fileformat=dos... 阅读全文

posted @ 2015-06-01 18:47 karenwang 阅读(137) 评论(0) 推荐(0)

导航