0%

linux系列之问题汇总

apt-get国内太慢

ubuntu和debian的镜像源都要换:

1
2
sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

还原:

1
sed -i s@/mirrors.aliyun.com/@/deb.debian.org/@g /etc/apt/sources.list

更换163的镜像:

1
2
3
4
5
6
#更新apt-get源 使用163的源
mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list && \
echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list && \
echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list && \
echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list

apk命令更换源

1
2
3
echo "http://mirrors.aliyun.com/alpine/v3.8/main" > /etc/apk/repositories \
&& echo "http://mirrors.aliyun.com/alpine/v3.8/community" >> /etc/apk/repositories \
&& apk update upgrade \

将命令的返回值赋值给变量(Shell命令)

  • A=ls -la 反引号,运行里面的命令,并把结果返回给变量A
  • A=$(ls -la)等价于反引号

linux shell通过curl获取HTTP请求的状态码

1
curl -I -m 10 -o /dev/null -s -w %{http_code} www.baidu.com

shell获取系统当前时间并格式化

1
time=$(date "+%Y-%m-%d %H:%M:%S")

安装包打包命令

1
rpmbuild / dpkg-deb 可以制作 rpm / deb package

命令行特殊字符

用双引号括起来

1
sshpass -p "R.XXXXXXXxxxx;/g4~" ssh root@81.70.99.173