Shell

来源:互联网 发布:淘宝子账号被限制登录 编辑:程序博客网 时间:2024/06/06 00:01

/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置.
/etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取.

[root@localhost ~]# date ;who20170330日 星期四 17:18:53 CSTroot     pts/0        2017-03-30 10:24 root     pts/1        2017-03-30 11:04 shell脚本:命令、消息、变量[root@mcs-slave-2 shell]# cat test1#!/bin/bash# liangzhiyuanwhoQQ=http://finance.qq.com/echo ${QQ}testing=$(date)echo $testing[root@mcs-slave-2 shell]# test1bash: test1: 未找到命令...[root@mcs-slave-2 shell]# echo $PATH/usr/local/mysql/bin:/usr/java/jdk1.8.0_112/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/maven3/bin:/root/bin[root@mcs-slave-2 shell]# ./test1-bash: ./test1: 权限不够[root@mcs-slave-2 shell]# ll -ls4 -rw-r--r-- 1 root root 34 330 17:11 test1[root@mcs-slave-2 shell]# chmod u+x test1[root@mcs-slave-2 shell]# ll -ls4 -rwxr--r-- 1 root root 34 330 17:11 test1[root@mcs-slave-2 shell]# ./test1root     pts/0        2017-03-30 10:24 root     pts/1        2017-03-30 11:04 http://finance.qq.com/20170331日 星期五 09:38:10 CST重定向输入与输出 date > test2   wc < test2[root@mcs-slave-2 shell]# wc << EOF> GGG> KKK> EOF2 2 8管道:|[root@mcs-slave-2 shell]# rpm -qa | sort | more abattis-cantarell-fonts-0.0.16-3.el7.noarchabrt-2.1.11-36.el7.centos.x86_64abrt-addon-ccpp-2.1.11-36.el7.centos.x86_64数学运算:expr、$[]、bc[root@mcs-slave-2 shell]# expr 1+51+5[root@mcs-slave-2 shell]# expr 1 + 56[root@mcs-slave-2 shell]# expr 5 * 2expr: 语法错误[root@mcs-slave-2 shell]# expr 5 \* 210[root@mcs-slave-2 shell]# expr 12 \* 2.2expr: 非整数参数[root@mcs-slave-2 shell]# bc12 * 5.464.8quit退出状态码:$?、exit结构化命令:if-then fi、if-then-else ficase in pattern esacfor var in list do commands donewhile test command do ocommand doneuntil test command do ocommand donetest命令:数值比较、字符串比较、文件比较记录消息:[root@mcs-slave-2 shell]# date | tee testfile20170331日 星期五 14:31:46 CST[root@mcs-slave-2 shell]# cat testfile20170331日 星期五 14:31:46 CST[root@mcs-slave-2 shell]#作业控制:[root@mcs-slave-2 shell]# jobs[1]-  已停止               rpm -qa | sort | more[2]+  已停止               vim test2[root@mcs-slave-2 shell]# jobs -l[1]-  1682 完成                  rpm -qa      1683                       | sort      1684 停止                  | more[2]+ 25786 停止                  vim test2执行作业:[root@mcs-slave-2 shell]# at -f test1 nowjob 3 at Fri Mar 31 16:54:00 2017[root@mcs-slave-2 shell]# at -M -f test1 teatimejob 5 at Sat Apr  1 16:00:00 2017[root@mcs-slave-2 shell]# at -M -f test1 tomorrowjob 6 at Sat Apr  1 17:01:00 2017[root@mcs-slave-2 shell]# atq5       Sat Apr  1 16:00:00 2017 a root6       Sat Apr  1 17:01:00 2017 a root[root@mcs-slave-2 shell]# atrm 5[root@mcs-slave-2 shell]# atq6       Sat Apr  1 17:01:00 2017 a root定期执行的脚本:cron anacronmin hour dayofmonth month dayofweek command00 12 * * * if ['date +%d -d tomorrow'=01] ;then ;command[root@mcs-slave-2 cron.hourly]# crontab -lno crontab for root[root@mcs-slave-2 home]# ls /etc/cron.*ly/etc/cron.daily:0yum-daily.cron  logrotate  man-db.cron  mlocate/etc/cron.hourly:0anacron  0yum-hourly.cron  docker-cleanup/etc/cron.monthly:/etc/cron.weekly:nice    内核根据进程的nice值决定进程需要多少处理器时间. nice值的取值范围是是: -2019.renice  可以给正在运行的进程设置调度优先级.  fork  在子命令执行完后再执行父级命令。子级的环境变量不会影响到父级。exec  执行子级的命令后,不再执行父级命令。source 执行子级命令后继续执行父级命令,同时子级设置的环境变量会影响到父级的环境变量。shell函数:脚本代码块 函数定义:function name { commands } name() { commands }函数使用:name param函数库:source(.)在.bashrc文件中定义函数:直接定义函数,读取函数文件(source)

编辑器:sed graw 区别于交互式的vim

[root@mcs-master ~]# cat lzydata.txt hi world[root@mcs-master ~]# sed 's/hi/hello/' lzydata.txthello world[root@mcs-master ~]# cat lzydata.txt hi worldhello china[root@mcs-master ~]# gawk '{print $1}' lzydata.txt hihello

linux正则表达式引擎:BRE/ERE

纯文本特殊字符: .*[]^${}\+?|()锚字符:锁定在行首^、锁定在行尾$、组合锚点:查找特定文本模式、过滤数据流中的空白行 sed '/^$/d'点号字符: .任意单个字符字符组: [] 解析拼错的单词排出型字符组: [^]特殊字符组: [[:alpha:]]区间: [0-9]、[a-z]、[a-ch-m]、[A-Za-z0-9]星号: 出现0次或多次问号: 出现0次或1次加号: 出现1次或多次花括号: {m,n}管道符号: OR表达式分组: ()