Home » 未分类 » Linux 学习笔记 五

Linux 学习笔记 五

在douban.fm中有一点就是你永远也不会有可能上一曲,这也就是像生活中的我们一样,过了就是过了,你永远也是没有机会后悔后退的,过去了就只能下一曲,继续往前走

那么如果我是两个相关的指令,第一个 command1 如果执行结果有错误,第二个就不被执行,可以这样做吗?当然可以

command1 && command2

command1 || command2

[test @test test]# ls -al 1> list.txt 2> list.err

将显示的数据,正确的输出到 list.txt 错误的数据输出到 list.err

[test @test test]# ls -al 1> list.txt 2>&1

将显示的数据,不论正确或错误均输出到 list.txt 当中!

/dev/null 代表空NULL

eg  find / -name testing 1>list_right 2>list_error

last  可以查看这个月的登录数据

tee 可以在查看了数据并把数据送出给下一个管道的时候还显示在屏幕上

 

tr [-ds] SET1

-d:删除SET1这个字符串

-s:   取代掉重复的字符

 

EG: cat list_right|tr -d testing

 

split

-l 以行数来分

eg:split -l 5 /etc/passwd test

会被分成五个

 

正规表示式 ( Regular Expression, 底下简称 RE )

 

grep [-acinv] ‘搜寻字符串’ filename

参数说明:

-a :将 binary 档案以 text 档案的方式搜寻数据

-c :计算找到 ‘搜寻字符串’ 的次数

-i :忽略大小写的不同,所以大小写视为相同

-n :顺便输出行号

-v :反向选择,亦即显示出没有 ‘搜寻字符串’ 内容的那一行!

 

宣告变量内容

[test @test test]# declare [-afirx]

参数说明:

-a  :定义为数组 array

-f  :定义为函数 function

-i  :定义为整数 integer

-r  :定义为『只读』

-x  :定义为透过环境输出变量

eg:

[test @test test]# declare -i a=3

[test @test test]# declare -i b=5

[test @test test]# declare -i c=$a*$b

[test @test test]# echo $c

15

 

myscript opt1 opt2 opt3

 

$0 myscript 也就是代表script这个档案

$1 opt1 代表是第一个附加参数,

$2 opt2  代表是第二个附加参数

也就是说script可以带参数运行

eg:

./sh pa1 pa2

则在sh的script里面取$1则是 pa1 $2则是 pa2 $0则是script本身

 

 

for (( 条件一; 条件二; 条件三 ))

for variable in variable1 variable2 …..

while [ condition1 ] && { || } [ condition2 ] …

until [ condition1 ] && { || } [ condition2 ] …

for 是已经知道有多少个 run 了,即是已经知道要跑几次了,至于 until 与 while 则分别是:

『until:直到条件相同的时候才离开程序』;

『while:当条件相同的时候,就继续做!』

 

记住在使用if 时 条件里面的都要使用空格间隔,不然条件将是无效的。

可以使用以下测试script测试脚本的执行情况

[test @test test]# sh [-nvx] scripts

-n :不要执行 scripts ,查询 scripts 内的语法,若有错误则予以列出!

-v :在执行 scripts 之前,先将 scripts 的内容显示在屏幕上;

-x :将有使用到的 scripts 内容显示在屏幕上,与 -v 稍微不同!

 

at : 这个工作仅执行一次就从 Linux 系统中的排程中取消;

crontab : 这个工作将持续例行性的作下去!

 

只要你编辑完 /etc/crontab 这个档案,并且将他储存之后,呵呵!那么 crontab 的设定就自动的会来执行了!

This entry was posted in 未分类. Bookmark the permalink.