linux命令
在线命令查询
https://tool.lu/command/index.html
shutdown 开关机
shutdown -r now 立刻重启
shutdown -h now 立刻关机
shutdown +5 "system will shutdown" 5分钟后关机
halt 关机
reboot 重启
systemctl 服务
centos服务
开启 重启 关闭服务
systemctl start httpd.service
systemctl restart httpd.service
systemctl stop httpd.service
systemctl try-start httpd.service
开机自启动和关闭
systemctl enable httpd.service
systemctl disenable httpd.service
systemctl status httpd.service
时区timedatectl
timedatectl set-timezone Asia/Shanghai
dpkg
deb打包
deb包结构
├── DEBIAN
│ ├── control
│ ├── postinst
│ └── postrm
└── usr
└── src
usr/src下是我们的要安装的文件 安装到 /usr/src
DEBIAN/control文件是包描述文件
//示例
Package: mysoftware
Version: 2016-02-26
Section: free
Priority: optional
Depends: libssl.0.0.so, libstdc++2.10-glibc2.2
Suggests: Openssl
Architecture: i386
Installed-Size: 66666
Maintainer: Simon @ newdivide7037#gmail.com
Provides: mysoftware
Description: just for test
//控制文件
preinst 安装前执行脚本 关闭服务
postinst 安装后执行脚本 创建连接
prerm 卸载前执行脚本 关闭服务
postrm 卸载后执行脚本 删除连接
//打包
dpkg -b . exca_1.0.1_ubuntu_16.04_amd64.deb #第一个参数为将要打包的目录名,
#第二个参数为生成包的名称
dpkg -i mydeb.deb 安装
dpkg -r mysoftware 卸载
dpkg -s mysoftware 查看是否安装
dpkg -c mydeb.deb 查看包内容
dpkg -X mydeb.deb mydeb解压
dpkg -e mydeb.deb mydeb/DEBIAN
//重装
sudo apt-get -f --reinstall install libvlc0
//强制卸载
sudo rm /var/lib/dpkg/info/libvlc*
sudo dpkg -r --force-depends --force-remove-reinstreq libvlc0
Shell语法
变量
first_var="123"
echo $first_var
echo ${first_var}
readonly first_var="1111"
unset first_var
字符串
str="Hello, I know you are \"$your_name\"! \n"
# 使用双引号拼接
greeting="hello, "$your_name" !"
# 使用单引号拼接
greeting_2='hello, '$your_name' !'
string="abcd"
echo ${#string} #输出 4
#获取元素长度
内部执行
echo `pwd`
echo $(pwd)
数组
array_name=(value0 value1 value2 value3)
array_name[0]=value0
valuen=${array_name[n]}
使用 @ 符号可以获取数组中的所有元素,例如:
echo ${array_name[@]}