(权限、文件用户、文件长度、文件类型等)
名称查找
find / -name "passwd" #找根下所有passwd文件或目录
find /tmp/ -name *.conf #查找tmp下所有.conf结尾的
find /tmp -name "[a-z][a-z][a-z].conf"
#查找/tmp 下前三位为字母以.conf结尾的
find /tmp -name "[a-z]??.conf"
#查找/tmp下第一个字符为字母 2、3 是字母或数字结尾的
find /tmp -name [a-z]][0-9].conf
#查找 /tmp下第一字符为字母第二字符为数字
权限查找
find /home/ -perm 700 -ls
#查找/home权限为700的 列出
find /home -perm 700 -ls | awk '{print $3}'
find /home/ -user alex
#查找所属用户为alex的文件
find /home -group alex
#查找所属组为alex的文件
find /home ! alex -group root
#查找所属用户不为alex 组为root 的
#用户没删除干净会没有所属用户和所属组
find /home -nouser -nogroup
#找出没有所属用户的 没有所属组
find -user alex -group alex
#查找所属组与所有者都为alex 的文件
find / tmp/ -mtime -2
#/tmp查找两天前被更改过的文件
find /tmp -mtime +1
#查找/tmp下一天前更改过的文件
find /tmp -type d
#查找为文件夹的
一块为512字节
find /tmp -size 823c -ls
#查找/tmp下大小为823字节的文件
find /tmp +823c ls
#查找大于823字节的文件
find /tmp -size -823c -ls
#查找小于823字节的文件
find /tmp -size +20k -ls
#查找大于20K的文件
-exec #执行择项
find /tmp -name "yum.conf" -exec cp {} alex \;
#查找/tmp下名字为yum.conf文件拷贝成一个名为alex执行结束。\结束
find /tmp -name alex -exec rm -f {} \;
#查找/tmp下alex移除它
find /tmp ! -name "yum.conf " ! -name "sos.conf" -exec rm {} -f \; #查/tmp下名字不为yum.conf 名字不为sos.conf的文件执行删除结束
! 这个是链接符
这里加r 递归就会把你搜的最高级全部删除
ll -h #查看文件的大小 ll -Z #长格式查看文件属性
注: 1 block =512 byte
ls
xargs 后面可以接命令
ls sos.conf | xargs chmod 777
#找到sos.conf文件,执行赋权777
ls sos.conf | xargs rm -f
#找到sos. conf 并执行删除
find /home -perm 755 | xargs chmod o+w
#找到权限为755的文件,然后执行赋予other可写权限
文本查看工具:
head more cat tail less # -n 接行
cat 文本全部屏幕输出
head 前面十行 # head -n1
tail 后十行 # tail -n1
less 分页查看 #PgIp,PgDn
more 83%查看
grep
grep root /etc/passwd
过滤出来含有root关键字的行
cat /etc/passwd | grep root -v
-v 取反,把没有含有root的过滤出来
cat /etc/passwd | grep -E "root|11"
这里的|是或者的意思,-E是一个扩展的选项后面接正则
cat /etc/passwd | grep -Ei "root|11|privil"
cat /etc/passwd | grep -i privil
-i 是忽略大小写
cat /etc/passwd | grep -E "^a|^r"
-E是以行,以a或r开头的
cut #提取
cut -c 1-4 /etc/passwd
cat /etc/passwd | cut -c 1-4
#提取1-4列字符关键字
cut -c 1 /etc/passwd
#提取第一列字符关键字
echo abc
#输出abc
echo abc | cut -c 2
#提取 c 参照物的的第二个 ,-d以什么做参照
echo abc | cut -d "a" -f1
#提取abc。以a做参照物a的前面什么也没有第一行为空
echo abc | cut -d "a" -f2
#提取 abc 以a做参照a的后面有bc 相当于第二行
echo abc | cut -d "a" -f2 | cut -d "c" -f1
#提取之前的bc 以c做参照物第一行为b
echo abc | cut -d "a" - f2 |cut -d ""c -f2
cat /etc/passwd | cut -d ":" -f1
#取第一个:前面的用户名
-c 为字符顺序提前
-d 是以某个字符为提前
[root@desktop71 tmp]# for a in $(cat /etc/passwd | cut -d ":" -f1 | tail -n3)
> do
> echo redhat | passwd --stdin $a
> done
Changing password for user user.
passwd: all authentication tokens updated successfully.
Changing password for user a.
passwd: all authentication tokens updated successfully.
Changing password for user linhutlll.
passwd: all authentication tokens updated successfully.
awk:
awk -F : '{print $1,$2}' /etc/passwd
取第一和第二列(以 : 为分隔符)
cat /etc/passwd | awk -F : '{print $1,%2}' /etc/passwd
匹配:
cat /etc/passwd | awk -F : '($3==0){print $1}'
以:分列,第三列为0的打印出来第一列
-F 是指定分割符
df -h | awk '{print $1,$NF}'
$NF是最后一列
df -h | awk '{print $1 "----" $NF}'
“”在这里当拼接符
df -h | awk BEGIN {print "------DEVICE-----"}'{print "-------"$1"---"} END {print "END DONE"}'
BEGIN添加标题
END添加结尾
cat /etc/passwd | awk -F : '/^r/ {print $1}'
以r为开头的显示第一列,以:为分隔符 /正则表达式/
cat /etc/passwd | awk -F : '/^[a-z]*t:.*/ {print $1}'
cat /etc/passwd | cut -d ":" -f1 | grep t$
cat /etc/passwd | awk -F : '{print $1}'| grep t$
以t结尾的输出第一列
wc #统计
wc -l /etc/passwd
#显示文件的行数 #line
wc -w /etc/passwd
#显示文件的单词数 #word
wc -c /etc/passwd
# 显示文件的字节数 #counts 字节
sort
sort /etc/passwd | less | cut -c1 | sort -u
#以升序排列,/etc/passwd 第一列字符,有时也可以去重复
-u升序
sort /etc/passwd | less | cut -c1 | sort -r
# 查看/etc/passwd 以降序排列 第一列字符
-r降序
cat /etc/passwd | sort -u | grep ^root
#升序排列以root开头的行
sort -k 2 -n
#以第二列去排序,-n为数字排序
> #为左边的文件 < #为右边的文件
&& #与 || #否则
$ 在grep里的空白
' ' 为永不转义 打印出第一列参数
[root@desktop71 opt]# mkdir /opt/hehe &> /dev/null || echo "it is wrong"
it is wrong
创建文件夹,然后全部到黑洞,失败就屏幕输出it is wrong
tail
#以c做参照物第二行为空白的
tail /etc/passwd
tail /etc/passwd | cut -d ":" - f1
#提取/etc/passwd 以:为分割点 ,截取第一列
tail /etc/passwd | cut -d ":" f7
#提取/etc/passwd 以:为分割点 ,截取第七列
mkdir /tmp/haha &> /dev/null || mkdir ziziz
#创建haha目录 无论成功与否重定向到null中 ,前面的操作成功则创建zizi
cp /etc/passwd /tmp/defaule
更改其中的内容
diff /etc/passwd /tmp/default
#查找两个文件的不同之处
awk -F : '{print $(NF)}' /etc/passwd
# NF=倒数第一列 ,以: 分割 打印出倒数第一列
awk -F : {'print $(NF-1)}' /etc/passwd
#以: 分割打印出倒数第二列
awk -F : {'print $1,$3,NF'} /etc/passwd
# 以:为分割符 打印出 1,3,最后一列
awk -F : {'BEGIN''{print "’}====userlist==="}{print $1 } END {print "======done======="}' /etc/passwd
#以F为分隔符 开头打印出====userlist===" 截取第一列 尾部打应出 "======done======="}'
awk -F : '/^r/ {print $1}' /etc/passwd
#以:为分隔符 打印出第一列参数为r 开头的
awk -F : '/^[a-z]*t:.*/ {print $1}' /etc/passwd
或:
awk -F : '/^[a-z]*t:/ {print $1}' /jieya/passwd
#以:为分隔符 打印出第一列以单词开头t结尾的
sar -q
df -h | awk "print $3,$4"
ifconfig | grep ^$ -v| grep errors | sort -u | awk '{print $2}' | sort -u | cut -d r -f3 | wc -w | passwd --stdin alex
先打印ifconfig \
排除空格 \
过滤含义errors的行 \
再正序排序 \
$2 是第二列($NF 最后一列 $NF-1 倒数第二列 ,相连 )\
去重 \
这里的cut -d 是后面接分割符并分割后面再接-f1为分隔符前一列 \ wc是统计(-c 统计字节数。 -l 统计行数。 -m 统计字符 。-w 统计字数。-L 打印最长行的长度。)
\ 并把结果输出为alex密码
评论