码迷,mamicode.com
首页 > 其他好文 > 详细

笔记4

时间:2017-05-22 23:14:37      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:exist   启动   也会   chess   连接   sgid   min   脚本   http   

[root@localhost ~]# declare -i i=10
[root@localhost ~]# declare -i j=10 declare -i
[root@localhost ~]# n=i+j
[root@localhost ~]# echo $n
i+j
[root@localhost ~]# n=$i+$j
[root@localhost ~]# echo $n
10+10
[root@localhost ~]# declare -i n=i+j
[root@localhost ~]# echo $n
20
----------------------------------------------------------------------------------------------------------
+/-:"-"可用来指定变量的属性,"+"则是取消变量所设的属性;
-f:仅显示函数;
r:将变量设置为只读;
x:指定的变量会成为环境变量,可供shell以外的程序来使用;
i:[设置值]可以是数值,字符串或运算式。


---------------------------------------------------------------------------------------------------------
[root@localhost ~]# echo {2..100..2}|tr " " "+"|bc 2+4+6+..100
----------------------------------------------------------------------------------------------------------
2550
----------------------------------------------------------------------------------------------------------
[root@localhost ~]# ping -w100 -c20 172.16.0.1 -w1为拼一次 -c1拼一秒
----------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------
[root@localhost ~]# n=minh w=bing
----------------------------------------------------------------------------------------------------------
[root@localhost ~]# test $n = $w 判断两个变量是否相同
----------------------------------------------------------------------------------------------------------
[root@localhost ~]# echo $?
----------------------------------------------------------------------------------------------------------
1 1为不同
----------------------------------------------------------------------------------------------------------
[root@localhost ~]# n=bing
----------------------------------------------------------------------------------------------------------
[root@localhost ~]# test $n = $w
----------------------------------------------------------------------------------------------------------
[root@localhost ~]# echo $?
----------------------------------------------------------------------------------------------------------
0 只有0是相同的
----------------------------------------------------------------------------------------------------------
[root@localhost ~]# [ $n = $w ] 也可以判断
----------------------------------------------------------------------------------------------------------
[root@ming ~]# id ming &> /dev/null && echo the user is exist
----------------------------------------------------------------------------------------------------------
the user is exist 查看是否有ming这个用户 &&为短路于 &&前面的命令执行成功了,&&后面的命令才会执行
echo打印这句话the user is exist
----------------------------------------------------------------------------------------------------------
[root@ming ~]# id ppxia &> /dev/null || useradd ppxia ||为短路或,||前面的命令不执行,||后面的命令才会执行
---------------------------------------------------------------------------------------------------------
查看是否有ppxia这个用户,如果没有就创建,如果有就不创建

[root@ming ~]# getent passwd ppxia 查看ppxia用户
----------------------------------------------------------------------------------------------------------
ppxia:x:502:504::/home/ppxia:/bin/bash
----------------------------------------------------------------------------------------------------------

[root@ming ~]# m=ming
[root@ming ~]# id $m &> /dev/null && echo $m is exist || useradd $m
----------------------------------------------------------------------------------------------------------
查看是否有这个用户 如果有就把is exist显示出来 没有就创建一个新用户
----------------------------------------------------------------------------------------------------------

ping 172.16.0.1 &>把输出的结果输入到w3文件中

如果172.16.0.1ping通了就显示the host is up 如果没有ping通就显示the host is down
[root@ming ~]# ping -c1 -w1 172.16.0.1 &> w3 && echo the host is up || echo the host is down
----------------------------------------------------------------------------------------------------------
the host is up

 

 

 


----------------------------------------------------------------------------------------------------------
[root@ming ~]# m=10
[root@ming ~]# n=20
[root@ming ~]# [ "$m" -gt "$n" ] && echo ‘m > n‘ 如果$m大于$n就显示m > n
----------------------------------------------------------------------------------------------------------
[root@ming ~]# [ "$m" -gt "$n" ] && echo ‘m > n‘ ||echo ‘m <= n‘
----------------------------------------------------------------------------------------------------------
m<n 比较m和n 如果m大于n就显示m > n 如果m小于n或者等于n 就显示 m <= n

----------------------------------------------------------------------------------------------------------
[root@ming mmm]# a=abcd
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# [[ "$a" =~ "ab" ]] && echo true 查看$a中是否含有ab 如果含有就显示true
----------------------------------------------------------------------------------------------------------
true
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# [[ "$a" =~ "ad" ]] && echo true ad不会显示
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# [[ "$a" =~ a..d ]] && echo true
----------------------------------------------------------------------------------------------------------
true
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# a=abcde
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# [[ "$a" =~ a..e ]] && echo true 这样就不会显示
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# [[ "$a" =~ a...e ]] && echo true a和e中间相隔几个字母需要加上几个小数点
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# [[ "$a" =~ a*e ]] && echo true 加上*可以
----------------------------------------------------------------------------------------------------------

 

[root@ming ~]# updatedb 更新数据库
----------------------------------------------------------------------------------------------------------
[root@ming ~]# locate mmm 在数据库中搜索包含有mmm字母,的文件和目录 locate 不能实时搜索
----------------------------------------------------------------------------------------------------------
[root@ming ~]# locate -i mmm 搜索时不分大小写
----------------------------------------------------------------------------------------------------------
[root@ming ~]# locate -in 3 sh 搜索前三个含有sh的
/bin/bash
/bin/csh
/bin/dash
----------------------------------------------------------------------------------------------------------
[root@localhost ~]# locate -r "\.cfg" 搜索以.cfg结尾的
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find -name chess2.sh find为精确查找chess2.sh 文件名需要写全 当前目录下搜索
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find -maxdepth 3 -name sh.sh 搜索三层目录 查找sh.sh
----------------------------------------------------------------------------------------------------------
[root@ming ~]# mkdir -p mmm/d1/d2/d3/d4/d5/d6/d7/d8/d9 -p可以同时创建d1 d2 d3 d4 d5 d6 d7 d8 d9 目录
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find -mindepth 1 -name d9 最少从第一层开始找
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find -mindepth 2 -maxdepth 2 -name d1 精确查找,只搜索第二层
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find -mindepth 2 -maxdepth 2 查找第二层所有文件和目录
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find -mindepth 2 -maxdepth 2 |wc - 查看第二层有多少个文件和目录
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find -name "f*" 使用*需要加上双引号
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find -name "f?" 搜索f开头的一个字符 ?代表一个一般 加上双引号是通配符
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find -name "*.sh" 搜索以.sh结尾的
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find -name "*.sh*" 搜索包含.sh结尾的
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find -iname "F*" 不区分大小写以F开头的文件和目录
----------------------------------------------------------------------------------------------------------
[root@ming ~]# ll -io 查看文件和目录的ID号
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find -inum 917525 按照ID号查找
----------------------------------------------------------------------------------------------------------
[root@ming ~]# ln w3 / 把w3的硬链接放到家目录下
[root@ming ~]# find -samefile w3 搜索w3
./w3
[root@ming ~]# find / -samefile w3 在根目录下搜索 搜索内存会报错,不用管它
/root/w3
/w3
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find / -samefile w3 2> /dev/null 把错误信息隐藏
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find -links 2 搜索链接数为2的目录
----------------------------------------------------------------------------------------------------------
文件的链接数起始值是1 创建几个硬链接就会有几个链接数
----------------------------------------------------------------------------------------------------------
目录的链接数起始值是2 一个目录下有几个子目录加是2就是它的链接数 文件对目录的链接数不会产生影响
----------------------------------------------------------------------------------------------------------
为一个文件创建软连接,不会影响它的链接数
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /etc/ -regex ".*\.conf$" 搜索以.conf结尾的
----------------------------------------------------------------------------------------------------------
[root@ming ~]# echo ${10} $10 需要加上双引号
----------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------
[root@ming ~]# echo $$ 查看在哪个进程
----------------------------------------------------------------------------------------------------------
[root@ming ~]# echo $PPID查看父进程
----------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------
[root@ming ~]# ! true !是取反
[root@ming ~]# echo $?
1
[root@ming ~]# true
[root@ming ~]# echo $?
0
----------------------------------------------------------------------------------------------------------
[root@ming ~]# false
[root@ming ~]# echo $?
1
[root@ming ~]# ! false !是取反
[root@ming ~]# echo $?
0
----------------------------------------------------------------------------------------------------------
[root@ming ~]# num=80
----------------------------------------------------------------------------------------------------------
[root@ming ~]# [ $num -gt 60 -a $num -lt 100 ] && echo pass 如果$num大于60 小于100 就打印出pass
----------------------------------------------------------------------------------------------------------
pass
----------------------------------------------------------------------------------------------------------
[root@ming ~]# n=1
----------------------------------------------------------------------------------------------------------
[root@ming ~]# expr $n + 0 &> /dev/null && echo $n is number 变量$n非0的情况下会判断出$n是数字几
----------------------------------------------------------------------------------------------------------
1 is number $n是零以上不包括零的,时候执行echo命令 打印出number
----------------------------------------------------------------------------------------------------------

 


[root@ming ~]# test -a 12.com && echo 12.conf isas || echo 1234 如果文件存在就打印12.conf isas不存在就打印1234
----------------------------------------------------------------------------------------------------------
12.conf isas
[root@ming ~]# [ -a 12.conf ] && echo 12.conf isas || echo 1234
12.conf isas 效果和test一样


-a<文件>:真实如果文件存在。
-b<文件>:如果文件为一个块特殊文件,则为真;
-c<文件>:如果文件为一个字符特殊文件,则为真;
-d<文件>:如果文件为一个目录,则为真;
-e<文件>:如果文件存在,则为真;
-f<文件>:如果文件为一个普通文件,则为真;
-g<文件>:如果设置了文件的SGID位,则为真;
-G<文件>:如果文件存在且归该组所有,则为真;
-k<文件>:如果设置了文件的粘着位,则为真;
-O<文件>:如果文件存在并且归该用户所有,则为真;
-p<文件>:如果文件为一个命名管道,则为真;
-r<文件>:如果文件可读,则为真;
-s<文件>:如果文件的长度不为零,则为真;
-S<文件>:如果文件为一个套接字特殊文件,则为真;
-u<文件>:如果设置了文件的SUID位,则为真;
-w<文件>:如果文件可写,则为真;
-x<文件>:如果文件可执行,则为真。
- o文件真实如果文件实际上是属于你。
- g文件真正的如果文件实际上是属于你的。
- z真的如果字符串是空字符串。
- n字符串
-o选项真正如果shell选项选项启用
来自: http://man.linuxde.net/test

5. (提示if判断)编写ArguCheck.sh脚本:检查脚本的输出参数,如果输入的参数个数不是3个,则打印“参数错误,脚本退出”,否则打印所有的输入参数
[root@ming mmm]# vim ArguCheck.sh
#!/bin/bash
[ $# -eq 3 ] && echo "$@" || exit | echo "$@ 参数错误,脚本退出"

 

 

----------------------------------------------------------------------------------------------------------
[root@ming ~]# vim sddd
#!/bin/bash
[ $# -ne 1 ] && echo the paramter number mnst be one && exit 10
[ -e $1 ] || { echo $1 is not exist ; exit 20; }
echo continue
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# vim sddd
----------------------------------------------------------------------------------------------------------
#!/bin/bash
----------------------------------------------------------------------------------------------------------
[ $# -ne 1 ] && echo the paramter number mnst be one && exit 10 如果文件存在就显示the paramter number mnst be one
----------------------------------------------------------------------------------------------------------
如何退出当前进程并显示10

[ -e $1 ] || { echo $1 is not exist ; exit 20; } 如果不存在就显示 你所输入的字符和is not exist并退出
----------------------------------------------------------------------------------------------------------
echo continue 是目录就显示continue 硬链接和软连接都会显示
----------------------------------------------------------------------------------------------------------
[ 表达式 ] test
( 子进程 ) 开子shell
{ cmd;cmd; } 不会开shell

----------------------------------------------------------------------------------------------------------
[root@ming mmm]# [[ "abc.sh" =~ \.sh ]] && echo true 只要包含.sh后缀 就执行echo 显示true
----------------------------------------------------------------------------------------------------------
true
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# vim yiwen
----------------------------------------------------------------------------------------------------------
#!/bin/bash
----------------------------------------------------------------------------------------------------------
echo -n "what do you like?" echo -n 会提问你喜欢什么
----------------------------------------------------------------------------------------------------------
read -p "who do you like: " name read -p会提问你喜欢谁:
----------------------------------------------------------------------------------------------------------
echo "your choose is $name" echo打印你的选择是
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# bash yiwen
----------------------------------------------------------------------------------------------------------
what do you like?who do you like: b
----------------------------------------------------------------------------------------------------------
your choose is b
----------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------
read
-p指定要显示的提示
-s 静默输入的字符长度N
----------------------------------------------------------------------------------------------------------
-d ‘字符’ 输入结束符 [root@ming mmm]# read -d q -t 3 输入q退出 不输入3秒钟后退出
----------------------------------------------------------------------------------------------------------
-t ‘数字’ 多少秒后显示 [root@ming mmm]# read -t 3 || echo "yes" 等待3秒后显示yes
----------------------------------------------------------------------------------------------------------
read 从标准输入中读取值,给每个单词分配一个变量,所有剩余单词都被分配给最后一个变量
----------------------------------------------------------------------------------------------------------
read -p “ecnter a filename:”FILE
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# read -s qw 输入的东西你看不见

----------------------------------------------------------------------------------------------------------
[root@ming mmm]# echo $qw 静默输入
qqqqqq
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# wq=123 设置变量
[root@ming mmm]# read wq < 80 通过read 将文件80的内容变成变量wq的内容
[root@ming mmm]# echo $wq 显示变量
#!/bin/bash 只有一行 只可以导入一行
[root@ming mmm]# cat 80 查看文件80的内容
#!/bin/bash
#description: Display information about this system!
#version:1.0.0
#Author:ming
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# read a b c <<< "xxx yyy zzz" 同时执行多行
[root@ming mmm]# echo $a $b $c
xxx yyy zzz
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# read q w e <<< "$a $b $c" 将变量a b c 导向 q w e 变量
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# echo $q $w $e
xxx yyy zzz
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# read 1 2 3 <<< "$a $b $c"
-bash: read: `1‘: not a valid identifier 数字不可以
----------------------------------------------------------------------------------------------------------
[root@ming ~]# vim /etc/profile.d/w.sh 需要把文件放在/etc/profil.d/目录下和~
----------------------------------------------------------------------------------------------------------
#!/bin/bash 登陆的时候系统会执行.sh 结尾的文件 root用户可以普通用户没有权限
touch 123123
----------------------------------------------------------------------------------------------------------
-rw-r--r--. 1 root root 0 May 11 19:05 123123
----------------------------------------------------------------------------------------------------------
env命令用于显示系统中已存在的环境变量
----------------------------------------------------------------------------------------------------------
[root@ming ~]# env
----------------------------------------------------------------------------------------------------------
[root@ming ~]# env -i 开始一个新的空的环境
----------------------------------------------------------------------------------------------------------
[root@ming ~]# env -u rm 从当前环境中删除指定的变量rm
----------------------------------------------------------------------------------------------------------
set命令作用主要是显示系统中已经存在的shell变量,以及设置shell变量的新变量值。使用set更改shell特性时,
符号"+"和"-"的作用分别是打开和关闭指定的模式。set命令不能够定义新的shell变量。如果要定义新的变量,
可以使用declare命令以变量名=值的格式进行定义即可。
----------------------------------------------------------------------------------------------------------
set
-a:标示已修改的变量,以供输出至环境变量。
-b:使被中止的后台程序立刻回报执行状态。
-C:转向所产生的文件无法覆盖已存在的文件。
-d:Shell预设会用杂凑表记忆使用过的指令,以加速指令的执行。使用-d参数可取消。
-e:若指令传回值不等于0,则立即退出shell。
-f:取消使用通配符。
-h:自动记录函数的所在位置。
-H Shell:可利用"!"加<指令编号>的方式来执行history中记录的指令。
-k:指令所给的参数都会被视为此指令的环境变量。
-l:记录for循环的变量名称。
-m:使用监视模式。
-n:只读取指令,而不实际执行。
-p:启动优先顺序模式。
-P:启动-P参数后,执行指令时,会以实际的文件或目录来取代符号连接。
-t:执行完随后的指令,即退出shell。
-u:当执行时使用到未定义过的变量,则显示错误信息。
-v:显示shell所读取的输入值。
-x:执行指令后,会先显示该指令及所下的参数。
----------------------------------------------------------------------------------------------------------
declare mylove=‘Visual C++‘ #定义新环境变量
----------------------------------------------------------------------------------------------------------
set -a mylove #设置为环境变量
----------------------------------------------------------------------------------------------------------
env | grep mylove #显示环境变量值
----------------------------------------------------------------------------------------------------------

[root@ming mmm]# source a.sh 执行a.sh脚本 使用source不会开子shell会在当前shell中执行,也会与环境变量冲突

----------------------------------------------------------------------------------------------------------
[root@ming mmm]# bash a.sh 使用bash执行脚本会开一个子进程 在子进程中执行
----------------------------------------------------------------------------------------------------------
普通变量不能在子进程中执行
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# bash sddd qwe 执行脚本最好用bash
qwe is not exist
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# chmod +x sdd
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# ./sddd qwe 有权限可以使用./来执行脚本
continue
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# . sddd 文件没有权限也可以执行脚本 . 最好不要执行脚本,因为结果完全不是你想要的结果
----------------------------------------------------------------------------------------------------------
脚本中的变量会和环境变量冲突
----------------------------------------------------------------------------------------------------------
用 . 和source 来执行脚本会选择环境变量
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# cd /etc/proile.d/ 可以将阿帕奇的一些软件,二进制文件放到proile.d/目录下
----------------------------------------------------------------------------------------------------------
[root@ming ~]# vim /etc/profile.d/httb.sh
----------------------------------------------------------------------------------------------------------
PATH=$PATH:/usr/local/apache/bin 保留原来的路径并增加一个路径/usr/local/apache/bin
----------------------------------------------------------------------------------------------------------
[root@ming ~]# echo $PATH
----------------------------------------------------------------------------------------------------------
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
----------------------------------------------------------------------------------------------------------
[root@ming ~]# cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin 先运行/etc/profile.d/httb.sh然后运行.bash_profile脚本对$PATH变量进行更改
----------------------------------------------------------------------------------------------------------
shell登录两种方式
----------------------------------------------------------------------------------------------------------
交互式登录
----------------------------------------------------------------------------------------------------------
1直接通过终端输入账号密码登录;
----------------------------------------------------------------------------------------------------------
2使用“su - UserName” 切换用户
----------------------------------------------------------------------------------------------------------
执行顺序
----------------------------------------------------------------------------------------------------------
/etc/profile ----> /etc/profile.d/*.sh ----> ~/.bash_profile ----> ~/.bashrc ----> /etc/bashrc
----------------------------------------------------------------------------------------------------------
非交互式登录
----------------------------------------------------------------------------------------------------------
(1)su UserName
----------------------------------------------------------------------------------------------------------
(2)图形界面下打开的终端
----------------------------------------------------------------------------------------------------------
(3)执行脚本
----------------------------------------------------------------------------------------------------------
执行顺序: ~/.bashrc ----> /etc/bashrc ----> /etc/profile.d/*.sh
----------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------
[root@ming ~]# echo "alias cdnet=‘cd /etc/sysconfig/network-scripts/‘" >>.bashrc
----------------------------------------------------------------------------------------------------------
为cd /etc/sysconfig/network-scripts/定义别名cdnet alias是定义别名 并输入到.bashrc脚本中可以在开机中执行
----------------------------------------------------------------------------------------------------------
[root@ming ~]# exit 退出当前终端就可以使用了
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /etc/ 搜索/etc/目录下的文件和目录
任何位于参数之前的字符串都将被视为欲查找的目录名。
如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。 find默认是-a 不用加
并且将查找到的子目录和文件全部进行显示。
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /etc/ -type f 搜索所有普通文件 -type f 为必须是普通文件
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /etc/ -type f -maxdepth 1 -maxdepth只搜索/etc/目录下第一层
----------------------------------------------------------------------------------------------------------
/etc/ld.so.conf
/etc/cron.deny
/etc/login.defs
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /etc/ -type f -maxdepth 1 -ls -ls查看文件的详细信息
----------------------------------------------------------------------------------------------------------
1048688 4 -rw-r--r-- 1 root root 449 Nov 23 00:30 /etc/krb5.conf
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /etc/ -maxdepth 1 -name "*.conf" -type f -ls
----------------------------------------------------------------------------------------------------------
-name "*.conf" 通过-name搜索以.conf结尾的文件
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /etc/ \( -name "*.conf" -o -type f \) -ls
----------------------------------------------------------------------------------------------------------
搜索/etc/目录下以.conf结尾 或者普通文件 都显示出来 -o为或者
----------------------------------------------------------------------------------------------------------
()需要转义用反斜杠 小括号为将小括号里的结为一个整体
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /etc/ -not -name "*.conf" -ls [root@ming ~]# find /etc/ ! -name "*.conf" -ls
----------------------------------------------------------------------------------------------------------
搜索/etc/目录下结尾不是.conf结尾的 !感叹号和-not是一个意思 都是取反
----------------------------------------------------------------------------------------------------------
与-a 或-o 非-not !
----------------------------------------------------------------------------------------------------------
德.摩根定律: 和=与-a 或-o 非-not !
-------------------------------------------------------------------------------------------------------
(非 A )或(非 Q)= 非(P 且 Q) 不是P也不是Q,是P和Q以外的=不是P且不是Q,是P和Q以外的
----------------------------------------------------------------------------------------------------------
(非 A )且(非 Q)= 非(P 或 Q)
----------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------
(不是P)也不是(不是Q)也不是P和Q相连接的区域=不是(可能是P,可能是Q,可能是P和Q相连接的区域)=1
----------------------------------------------------------------------------------------------------------
是P和Q和,PQ之间,以外的区域
----------------------------------------------------------------------------------------------------------
P是2 Q是3 P和Q线连接的区域是4 以外的区域为1
----------------------------------------------------------------------------------------------------------
不是P不是Q不是4=1
----------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /etc/ \( -not -type f -a -name "*.conf" \) -ls
----------------------------------------------------------------------------------------------------------
搜索 (不是普通文件并且不是.conf结尾的)
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /etc/ "*.conf" |wc -l find默认是和
----------------------------------------------------------------------------------------------------------
2395
搜索包含结尾是.conf和所有 2395 是多少个
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /etc/ |wc -l
----------------------------------------------------------------------------------------------------------
2395 搜索所有
----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /etc/ -not \( -type f -a -name "*.conf" \) -ls |wc -l
----------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /tmp \( -not -user root -a -not -name ‘f*‘ \) -ls
----------------------------------------------------------------------------------------------------------
搜索/tmp目录下,属主不是root,且文件名不以f开头的文件
[root@ming ~]# find /tmp/ -not \( -user root -o -name ‘f*‘ \) -ls|wc -l
----------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------
[root@ming ~]# find /etc/ \( -path "/etc/sane.d" -o -path "/etc/modprobe.d" \) -a -prune -o -name "*.conf" |grep modprobe
----------------------------------------------------------------------------------------------------------
满足/etc/sane.d或/etc/modprobe.d就剪掉
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# find -size 20c 搜索内存大小为20字节的文件
----------------------------------------------------------------------------------------------------------
./a.sh
----------------------------------------------------------------------------------------------------------
更多详细信息请查看本地网页ifnd命令
----------------------------------------------------------------------------------------------------------
[root@ming mmm]# file q2
----------------------------------------------------------------------------------------------------------
q2: Bourne-Again shell script text executable q2:Bourne-Again shell脚本文本可执行

笔记4

标签:exist   启动   也会   chess   连接   sgid   min   脚本   http   

原文地址:http://www.cnblogs.com/ming01/p/6891771.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!