很实用的Linux 系统运维常用命令及常识(超实用)

2019-09-23 09:17:29丽君

else
echo $current >>tmp
((n++))
fi
done
rq=`awk 'NR==1{print}' tmp`
##################################
打印提示
cat <<EOF
#内容
EOF
登陆远程执行命令(特殊符号需要转义)
ssh root@ip << EOF
#执行命令
EOF
登陆mysql 执行命令
mysql -uroot -ppasswd -S mysql.sock --default-character-set=gbk -A<<EOF>outtmp
#mysql 命令
EOF
##################################
数学计算的小算法
#!/bin/sh
A=1
B=1
while [ $A -le 10 ]
do
SUM=`expr $A * $B`
echo "$SUM"
if [ $A = 10 ]
then
B=`expr $B + 1`
A=1
fiA
=`expr $A + 1`
done
##################################
竖行转横行(三种)
cat file|tr 'n' ' '
echo $(cat file)
#!/bin/sh
for i in `cat file`
do
a=${a}" "${i}
done
echo $a
##################################
取用户的根目录
#! /bin/bash
#showhome.sh
IFS=:
while read name pass uid gid gecos home shell
do
echo $home
done
执行./showhome.sh < /etc/passwd
##################################
把汉字转成encode 格式:
echo 论坛| tr -d "n" | xxd -i | sed -e "s/ 0x/%/g" | tr -d " ,n"
%c2%db%cc%b3
大写的:
echo 论坛| tr -d "n" | xxd -i | sed -e "s/ 0x/%/g" | tr -d " ,n" | tr "[a-f]" "[A-F]"
%C2%DB%CC%B3
##################################
把带有大写字母的文件名改为全部小写
#!/bin/bash
for f in *;do
mv $f `echo $f |tr "[A-Z]" "[a-z]"`
done
##################################
查找连续多行,在不连续的行前插入
#/bin/bash
lastrow=null
i=0
cat incl|while read line
do
i=`expr $i + 1`
if echo "$lastrow" | grep "#include <[A-Z].h>"
then
if echo "$line" | grep -v "#include <[A-Z].h>"
then
sed -i ''$i'i//All header files are include' incl
i=`expr $i + 1`
fi
fi
lastrow="$line"
done
##################################
====================================================================
----------------------------------
9 服务配置
----------------------------------
samba
修改配置文
/etc/samba/smb.conf
[global]
workgroup = WORKGROUP
server string = sambaserver
security=share
hosts allow=网络主机
[file]
comment=home directories
path=/etc/samba/xuesong
public=yes
writable=yes
browseable=yes
重启
service smb restart
linux 访问windows 共享
smbclient -L //ip 地址或计算机名
##################################
DNS 服务器
DNS 主配置文件,moon.com 域名,zone.moon.com 域的配置文件
vi /etc/named.conf
zone "moon.com" IN {