【Bash学习笔记】
赵一弘
这个作者很懒,什么都没留下…
展开
-
bash学习笔记1 变量
#!/bin/sh #定义与打印变量name="zhaoyh" echo $name#数据变量 初始化myarray=(10 11 12 13 14)#访问方法echo ${myarray[0]}#另一种初始化方式fruit=([0]=derri [1]=harry)echo ${fruit[1]}#打印全部的数组内容echo ${myarray[@]}echo原创 2014-01-14 10:51:51 · 434 阅读 · 0 评论 -
sed学习笔记 -n 只打印匹配行
public@share:~/zhaoyh$ cat input # Instruction Guides1. Linux Sysadmin, Linux Scripting etc.2. Databases - Oracle, mySQL etc.3. Security (Firewall, Network, Online Security etc)4. Storage in原创 2014-03-23 12:57:04 · 2188 阅读 · 0 评论 -
Unix Sed Tutorial 2 : Delete File Lines Using Address and Patterns
In the previous sed tutorial we discussed about Unix sed command basics and printing lines from a file using sed address and patterns.In this article, let us review how to delete lines from a fi转载 2014-03-24 11:07:32 · 477 阅读 · 0 评论 -
Unix Sed Tutorial4 : How To Write to a File Using Sed
This article is part of Unix Sed Tutorial series. In previous articles, we discussed about sed print operation , sed delete operation and sed find and replace.In this article, let us review ho转载 2014-03-24 11:21:07 · 596 阅读 · 0 评论 -
Unix Sed Tutorial 5: How To Execute Multiple Sed Commands
Question: Is it possible for me to combine multiple sed commands? Can I combine two sed commands and execute it as single sed command?Answer: In our previous articles we learned sed with single comm转载 2014-03-24 11:46:37 · 591 阅读 · 0 评论 -
Unix Sed Tutorial6 : Append, Insert, Replace, and Count File Lines
This article is part of the on going Unix sed command tutorial series. In our previous articles we learned sed with single commands — printing, deletion, substitute and file write.Sed provides lot转载 2014-03-24 12:20:16 · 744 阅读 · 0 评论 -
Unix Sed Tutorial3 : Find and Replace Text Inside a File Using RegEx
his article is part of on-going Unix Sed Tutorial series. In previous articles, we discussed about sed print operation andsed delete operation.In this article let us review how to use sed substi转载 2014-03-23 13:12:41 · 555 阅读 · 0 评论 -
Unix Sed Tutorial 7 : Advanced Sed Substitution Examples
This article is part of the on-going Unix Sed Tips and Tricksseries.In our previous sed articles we learned — sed printing, sed deletion, sed substitute , sed file write, and sed multiple comm转载 2014-03-24 15:21:54 · 619 阅读 · 0 评论 -
Unix Sed Tutorial 1 : Printing File Lines using Address and Patterns
Let us review how to print file lines using address and patterns in this first part of sed tutorial.We’ll be posting several awesome sed tutorials with examples in the upcoming weeks.Unix转载 2014-03-24 10:38:37 · 652 阅读 · 0 评论 -
Unix Sed Tutorial8 : Multi-Line File Operation with 6 Practical Examples
As part of our on going UNIX sed tutorial series earlier we covered the printing, deletion, substitution, file write, file manipulation commands etc., with the single line in the pattern space.I翻译 2014-03-25 22:27:26 · 681 阅读 · 0 评论 -
bash 生成N位随机字符串
#!/bin/shfunction usage(){ echo "输出N位随机字符串" echo "$0 N(N<16)"}if [ $# != 1 -o $1 -gt 16 ];then usage exit 1fistrSrc="123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcd原创 2014-06-30 11:30:44 · 1036 阅读 · 0 评论 -
grep 与 egrep , 正则表达式与延伸正则表达式
grep 预设是不支持延伸正则表达式的yansh原创 2014-05-29 10:07:46 · 490 阅读 · 0 评论 -
vim 替换和搜索
命令名称意义/word自当前光标位置向下搜索名字为word的字符串?word自当前光标位置向上搜索名字为word的字符串:n1,n2s/word1/word2/g在n1行与n2行之间搜索名字为word1的字符串,并将其替换为word2:1,$s/word1/word2原创 2014-03-23 10:24:59 · 373 阅读 · 0 评论 -
bash 多个后台程序顺序执行
{ command1 && command2 } &原创 2014-03-20 15:49:20 · 646 阅读 · 0 评论 -
vim使用:自动加载模板
如何在新建一个文档时就有默认的模板内容呢?非常简单的执行以下操作: cd ~ mkdir -p .vim/template vim .vim/template/html.tpl 在html.tpl里随便写一些内容,如: New Document转载 2014-03-30 22:48:25 · 714 阅读 · 0 评论 -
curl命令总结
curl命令总结curl 是一个利用URL语法在命令行方式下工作的文件传输工具。它支持很多协议:FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE 以及 LDAP。1、获得一张页面 使用命令:curl http://curl.haxx.se 这是最简单的使用方法。用这个命令获得了http://curl转载 2014-01-15 17:01:24 · 645 阅读 · 0 评论 -
bash学习笔记2 使用结构化命令
1 if 结构 1.1 if thenbash 中会运行if后面的命令,如果该命令的退出码为0(运行成功),then后面的语句才会继续进行if 后面要加个空格例子:testuser=spiderif grep $testuser /etc/passwdthen echo -n "the bash file for user $testuser is "原创 2014-02-24 12:36:29 · 473 阅读 · 0 评论 -
搜索解析网页url中的关键词
echo "http://baidu.com?q=abc&n=hha" | awk '{match($0,/^.*q=([^&]*).*/,a);print a[1] }'原创 2014-02-19 17:11:47 · 419 阅读 · 0 评论 -
Bash学习笔记03 : 更多结构化命令 for和 while
For1 基本格式:for var in list docommanddone举例:for test in Beijing Tianjin Wuhando echo "the next station is $test"done结果:the next station is Beijingthe next station is Tianj原创 2014-03-03 13:52:15 · 490 阅读 · 0 评论 -
head tail icovn
tail xxx 显示文件最后10行tail -n 20 显示文件最后20行tail -c 100 显示文件最后100字节tail -f 强制显示文件最后10行,如果文件刷新,会自动显示head xxx 显示文件前10行head 也支持 -n 与 -cicovn 转换文件格式icovn -f utf-8 -t gbk xxx > yyy 将文件由ut原创 2014-03-10 20:34:02 · 473 阅读 · 0 评论 -
ps df du sort 的用法
查看进程ps aux 查看所有进程 ps elf 查看当前用户的进程 df 查看磁盘使用情况df -h 显示单位du 查看当前目录以子目录下所有目录的大小du -h 显示单位du -c 显示总大小sort 排序sort将以字符顺序排序 1 10 11 2 20 21 这样的顺序sort -n 以数字顺序排序sort -r原创 2014-03-12 10:54:25 · 644 阅读 · 0 评论 -
grep 的用法
原文: http://www.thegeekstuff.com/2009/03/15-practical-unix-grep-command-examples/首先创建我们练习grep命令时需要用到的demo文件demo_file。$ cat demo_fileTHIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.this line is转载 2014-03-12 11:39:23 · 361 阅读 · 0 评论 -
tar 总结
参数c是创建 x 解压v 显示过程f输出到文件z 使用gzip压缩或解压j 使用bzip2压缩或解压-C 指定输出目录---------------------------------------------------------------平时经常用的gz压缩tar zcvf test.tgz test.sh解压tar zxvf test.tgz原创 2014-03-12 11:50:17 · 348 阅读 · 0 评论 -
bash 守护进程的写法
如果一个服务进程想要一直运行,在崩溃或被停止后自动运行,则它需要一个守护进程.脚本的编写流程为:while true{ 检测被守护进程的状态 若被守护进程终止则启动它sleep 使程序周期性运行}脚本范例: 守护一个service#!/bin/bash SERVICE="/xxx/xxx/abc.sh"SERVICE_LOG="/xxx/xxx原创 2014-03-11 18:53:19 · 881 阅读 · 0 评论 -
Bash学习笔记01 : 赋值和运算
1 变量: 赋值为$ 取值有$var1=10var2=$var1echo $var2注意赋值时变量,等号,值之间不能有空格2 反引号:将shell命令的输出赋给变量testing=`date`echo $testing3 重定向 3.1 输出重定向将命令的输出 重定向到文件,重定向的文件若不存在则直接创建 结合date 可以有这样的用原创 2014-02-21 12:22:57 · 416 阅读 · 0 评论 -
unexpected EOF while looking for matching `"'
出现这个问题时,虽然debug信息给你指明了是哪一行,但发现这行` `确实是配对的那么问题出在前面的行, 前面少个结束的` 我看这篇找到的问题:http://blog.163.com/lgh_2002/blog/static/4401752620103137416540/原创 2014-03-13 13:51:52 · 2419 阅读 · 0 评论 -
bash逐行读取文件
方法一,指定换行符读取:#! /bin/bash IFS=" " for LINE in `cat /etc/passwd` do echo $LINE done注意:这里写的是不全面的/当行中有空格时,这个是不能读的,此时要将IFS=`\r` 或者 \r\n 方法二,文件重定向给read转载 2014-06-12 14:15:33 · 1754 阅读 · 0 评论