linux

实战Linux Shell编程与服务器管理

2019-02-23  本文已影响128人  SkTj

shell


image.png

shell 调试
sh -x checknetty94.sh

服务器登录后,执行的shell为

.bash_profile
.bash_login
.profile

注销主机后,执行的shell为

.bash_logout

执行交互式shell时,

.bashrc

执行非交互式shell,会执行变量设置的BASH_ENV

例如:export BASH_ENV="/root/test.sh"

image.png

type echo 查看命令种类
echo -n xx 不换行
echo -e "a\nb" -e让\n表示成换行
printf 格式化输出


image.png

cd - 回到先前的目录
.=source
alias unalias
exit 1
logout
umask
history /root/.bash_history
HISTFILESIZE
fc -l 登录主机后执行的命令
set -o //bash 的开关状态
shopt 查看
shopt -s 开启选项
shopt -u 关闭选项
read -p 'aa' aa
${a[2]}
读变量


image.png
eval 读取变量内容,并执行
eval "ls -l"
date "+%Y-%m-%d %H:%M:%S"
date -d "-1 day" "+%Y-%m-%d %H:%M:%S"
date -d "1 months" "+%Y-%m-%d %H:%M:%S"

who 谁在登录主机
ls -a
cat >a.txt<<EOF
dxx
EOF
wc -l -c -w
ln -s -sf
mkdir -p
find / -name x
find . -name x -exec rm -rf {} ;
find / -cnewer /etc/passwd //创建时间比较
tar cvzf
tar xvfz -C /data
tar cvf - test2|gzip -9 > save.tar.gz
basename dirname
sort xx
sort -n xx
sort -k 2
sort -kn 2
uniq
uniq -c
cut -c2 xx
cut -c 2-10 xx
cut -c2- xx
cut -c1-3,4-29
cut -d: -f1 /etc/passwd
cut -d: -f1,3 /etc/passwd
paste 文件合并
paste file1 file2
paste -d "#" file1 file2

tr -d l<a.txt
tr s S<a.txt
tr [a-z] [A-Z]<a.txt
tr : +

grep "lfjl" * 将含有字符串的文件和行显示出来
grep -l "ss" * 含有字符串的文件显示出来
grep -A 10
grep -B 10
grep -C 10
find . -type f|xargs -n 2 diff
xargs 把标准输出分成两个一组,传给diff
export 查看当前环境的变量
unset

declare 声明变量 -a 数组 -i 整数 -r 只读 -x 环境变量
alias ll=''
b=(1 2 3 4)
b[@]{#b[@]}
if [ ? -eq 0 ];then xx else fi((9+9))算术
(ls -lh){}
{name-'aaa'} 不存才就传回'aaa'{name:-'aaa'} 不存在就给name赋值,并传回

上一篇 下一篇

猜你喜欢

热点阅读