标签:shel acl conf links log echo useradd link amp
/etc/passwd 密码清空 救援模式清空密码cp -r /etc/skel /home/git ; chown -R git.git /home/git ;chmod 700 /home/git
u+s u+t lsattr chattr -i chattr +a
setfacl -m u:luo rwx getfacl f.log setfacl -x u:luo f.log
setfacl -b f.log
目录=777-umask 文件=666-umask 结果有奇数+1
head -c# 获取前几字节 head -n#获取前几行 tail-n1
tail -f f.log cut -d -f 1,3-4 /etc/passwd
ifconfig eth0|head -n2 |tail -n1| tr -s ‘ ‘ | cut -d ‘ ‘ -f3
tr -d paste a.log b.log paste -d 分隔符
seq 10 |paste -sd+ |bc
wc f.txt
df|tr -s " " %|cut -d% -f5|sort -nr
seq 55|sort -R |head -n1 随机排序= echo $[RANDOM%55+1]
cut -d" " -f1 access_log |sort -u|wc -l
cat -E cat-ns
tac rev nl uniq a.log相邻字符 sort a.log |uniq -c
diff -u a.log b.log grep -f grep.log /etc/passwd
ls |grep "...log" .表示任意字符串
grep o /etc/passwd 表示o重复了几次 .任意长度的任意字符
grep “go{2}gle" f1.log
df |grep "/dev/sd" |grep -o "[[:digit:]]+%" |tr -d %|sort -nr
ip地址表示
[0-9] [[:digit:]] 0到9
[1-9][0-9] 10到99
1[0-9]{2} 100到199
2[0-4][0-9] 200到249
25[0-5] 250到255
(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])
echo abcabcabc123 |grep "(abc){3}"
%s/(root)/a\1b/g
扩展正则表达式不用\
grep -E "^(.)\>.\<\1$" /etc/passwd
shell脚本
#!/bin/bash
执行 ./hello.sh bash hello.sh
lscpu|grep "Model name"|tr -s " "|cut -d: -f2
free -h |grep Mem|tr -s " "|cut -d " " -f2
变量
date=‘date +%F‘
let N=2*3 echo $N echo$[23] echo$((23))
10.9
username=jie; id $username &> /dev/null && echo $username is exist
||(useradd $username;echo $username is created)
=~后面跟正则表达式
file=a.log; [[ "$file"=~ .log$]] && echotrue || echo false
file=hello.sh;[[ "$file" =~ .sh$ ]] && chmod +x $file || echo false
==支持通配符
file=hello.txt ;[[ "$file" == *.txt ]] &&echo txt file
file=hello.txt; [[ "$file" =~ .(sh|txt)$ ]] && echo txt or sh file
[ $i -gt $j ] && echo true || echo false
n=99;[ "$n" -gt 90 -a "$n" -lt 100 ] && echo true ||echo false
i="123" ;
file=/etc/issue;[ -f "$file" -a -r "$file" ] && echo true || echo false
i="23"; [[ $i =~ ^[[:digit:]]+$ ]] && echo digit || echo no digit
{ echo hello ;exit; }
df -i |grep "^/dev/sd" | grep -Eo "[0-9]+%" | grep -Eo "[0-9]+"|sort -nr|head -n1
read -p "Please input your name:" NAME
2 read -sp "Please input your passwd:" PASSWD
3 echo
4 echo "your name is $NAME"
5 echo "yourpasswd is $PASSWD"
locate -r "passwd$" locate -r ".conf$"
find /root -maxdepth 2 -mindepth 1
find -name ".sh"
find /data -inum 139 find /data -links 2
find /home -user luo -ls
find /data -type d -empty
find /home -type d -a -name "luo*"
find /data -size -2M
find / -size +10M | xargs ls -lh
find /data -perm 444 -ls
ls l*| xargs rm
标签:shel acl conf links log echo useradd link amp
原文地址:https://blog.51cto.com/14319741/2442136