find pathname -options [-print -exec -ok]
-name 按照文件名查找
find ~ -name "*.txt" -print ~代表$HOME
find . ~name *.txt" -print .当前目录
find /etc ~name "[A-Z]*" -print
find / ~name "*" -print
-perm 文件权限查找
find . -perm 755 -print
-prune 忽略某个目录
find /apps -name "/apps/bin" -prune -o -print
-user 文件属主来查找[group]
find ~ -user jshen -print
-mtime 更改时间
find / -mtime -5 -print 更改时间在5日内
find /etc -mtime +3 -print 在3日以前的
-newer file1!file2比文件file1新比file2旧的文件
find . -newer age.awk ! -newer belts.awk -exec ls -l {} \;
-type 文件类型
find /etc -type d -print
find . ! -type l -print
使用exec或者ok来执行shell命令
find . -type f -exec ls -l {} \;
find logs -type f -mtime +5 -ok rm {} \;
输入与输出
echo string
\c不换行 \t跳格 \n换行 \f 进纸
echo -n "What is your name : " -n禁止换行
echo -e "\007Your name is $HOME, you are connected on `tty`" -e转义符生效
echo "abcd" >myfile 重定向到myfile
echo "123456" >>myfile 追加
read 从键盘后者文件中某一行文本读入信息,赋值给一个变量
read name1 name2 input name1 name2 name3
echo name1 name2[name2 + name3]
cat
cat myfile | more
cat file1 file2
cat file1 file2 > bigfile
cat > myfile [CTRL+D结束]
tee 输出的同时,同时存入一个文件
tee -a file -a表示追加到一个文件末尾
who | tee who.out
标准输入输出 0,1,2
文件重定向
command > filename
command >>f ilename
command 1>filename
command >filename 2>&1 标准输入输出一起重定向到一个文件中
command 2>filename
command 2>>filename
command >>filename 2>&1
command <filename >filename2 以filename为标准输入,filename2为标准输出
command <filename
command <&m 文件描述符m做为标准输入
command >&m标准输出的重定向到文件描述符m
command <<delimiter [EOF]
cat >>myfile <<MONDAY 创建file文件,使用分解符MONDAY
>bye $name
>MONDAY
exec command
command是shell脚本
[
exec 4<&0 0<stock.txt
read line1
read line2
exec 0<&4
echo $line1
echo $line2
]
后台执行命令
crontab [-u user] -e -l -r 保存调度信息 [编辑、列出、删除]
分<>时<>日<>月<>星期<>要运行的命令
vi shenjieCron
30 21 * * * /apps/bin/cleanup.sh 每晚21点30运行/apps/bin目录下的backup.sh
45 4 1,10,22 * * /apps/bin/backup.sh 每月的1,,10,22日4点45执行
10 1 * * 6,0 /bin/find -name "core" -exec rm {} \; 每周六周日
0,30 18-23 * * * /apps/bin/dbcheck.sh 每天的18到23小时,每隔30分钟运行
crontab shenjieCron; crontab -l; crontab -e;crontab -r
at [-f script ] [-m -l -r] [time] [date]
-f 要提交的脚本命令 -m作业完成后给用户发邮件 -l 列出当前所有等待的作业 -r清除作业 time格式灵活H HH.HHMM HH:MM H:M a.m p.m
at 21:30
at> find / -name "passwd" -print
at><EOT>
at -l
atrm job 3 [ atrm job no]
后台运行 &
ps aux | grep " "
kill -9 no
命令执行顺序
如果这个命令执行成功 && 那么执行这个命令
如果这个命令执行失败 || 那么执行这个命令
组命令 (命令1;命令2;命令3) {命令1;命令2;命令3}
comet month_end.txt || exit
comet month_end.txt || echo "hello" | mail shenjie; exit 只执行exit
comet month_end.txt || (echo "hello" | mail shenjie; exit) 括号中全执行