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[@]}