1、防火墙
#1.iptables (centos 6.x)
#a.开关
chkconfig iptables on #开启,重启后生效
chkconfig iptables off #关闭,重启后生效
service iptables start #开启,即时生效,重启后失效
service iptables stop #关闭,即时生效,重启后失效
#b.使用
iptables -L -n #line number 显示规则和相对应的编号
iptables -F #清除所有规则
#2.firewalld (centos 7.x)
#a.开关
systemctl enable firewalld.service #开启,重启后生效
systemctl disable firewalld.service #关闭,重启后生效
systemctl start firewalld.service #开启,即时生效,重启后失效
systemctl stop firewalld.service #关闭,即时生效,重启后失效
#b.使用
3、压缩
#1.压缩
zip -r a.zip a #压缩a文件夹为a.zip
tar -cvf a.tar a #把a目录归档为a.tar,并不会压缩
tar -cvzf a.tar.gz a #把a目录归档为a.tar,并且压缩为a.tar.gz
#2.解压
unzip a.zip #解压zip
unzip a.zip -d /home/ #解压a.zip到home目录
tar -xvf a.tar #解开a.tar包
tar -xzvf a.tar.gz #解压tar.gz
tar –xZvf a.tar.Z #解压tar.Z
tar -xjvf a.tar.bz2 #解压 tar.bz2
#3.参数
-c #创建新的档案文件。如果用户想备份一个目录或是一些文件,就要选择这个选项。
-f #指定档案文件名或设备名,这个选项通常是必选的。
-v #详细报告tar处理的文件信息。如无此选项,tar不报告文件信息。
-x #从档案文件中释放文件。
-z #用gzip来压缩/解压缩文件,加上该选项后可以将档案文件进行压缩,但还原时也一定要使用该选项进行解压缩。
-j #有bz2属性的
-Z #有compress属性的
-O #将文件解开到标准输出
-r #把要存档的文件追加到档案文件的未尾。例如用户已经做好备份文件,又发现还有一个目录或是一些文件忘记备份了,这时可以使用该选项,将忘记的目录或文件追加到备份文件中。
-t #列出档案文件的内容,查看已经备份了哪些文件。
-u #更新文件。就是说,用新增的文件取代原备份文件,如果在备份文件中找不到要更新的文件,则把它追加到备份文件的最后。
-k #保存已经存在的文件。例如把某个文件还原,在还原的过程中遇到相同的文件,不会进行覆盖。
-m #在还原文件时,把所有文件的修改时间设定为现在。
-M #创建多卷的档案文件,以便在几个磁盘中存放。
-w #每一步都要求确认。
4、时间
#1.查看
date #显示当前时间
watch -n 1 date #实时查看时间
#2.修改
date -s '+10 second' #当前时间加10秒
date -s '-12 hour' #当前时间减去12个小时
#3.同步
service ntpd status #查看ntp状态
service ntpd stop #关闭ntp
yum remove ntp* #卸载ntp
ps -ef | grep ntp* #查看ntp进程
yum -y install ntp ntpdate
ntpdate cn.pool.ntp.org
#ubunt查看时区
timedatectl status
#回显
Local time: 一 2019-12-02 22:38:21 UTC
Universal time: 一 2019-12-02 22:38:21 UTC
RTC time: 一 2019-12-02 22:40:17
Time zone: n/a (UTC, +0000)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
#含义
UTC 世界标准时间,比北京时间慢8小时
RTC 硬件时钟时间,即BIOS时间
#当前北京时间2019-12-02 22:40:17,故
RTC 时间错误,硬件时间应该为世界标准时间
#快速修正时间
1.修正硬件时间为世界标准时间 date -s '-8 hour',同步至硬件时间hwclock --systohc(重要!!!无此命令RTC时间不变)
2.设置时区 timedatectl set-timezone "Asia/Shanghai"
3.查看回显确认修改生效 timedatectl statu
timedatectl status
Local time: 一 2019-12-02 22:43:31 CST
Universal time: 一 2019-12-02 14:43:31 UTC
RTC time: 一 2019-12-02 14:43:31
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
5、权限
#1.bash显示
$ #普通用户名字后缀
# #root用户名字后缀
sudo #使用管理员权限运行命令
#2.权限标识
dewxr-xr— #三组权限(文件所属用户、文件所属组、其它),每一组三个权限分别为读,写,执行
#3.修改权限
chmod -R 777 * #当前目录下所有文件给最高权限
6、进程
#1.查找
ps -ef | grep python
ps aux |grep node
netstat -nao
#2.启动
nohup node new.js & #后台运行
#开机启动
#3.停止
kill -quit 1278
#4.分析
top #查看cpu、内存占用
7、磁盘
#1.查看
df -h #查看磁盘剩余空间
du -sh * #列出来当前文件夹每个文件的大小
#2.挂载
8、其他
shutdown -h now 立即关机
shutdown -r now 立即重启,reboot也可
firefox &后台运行,不影响命令行
history输入的历史命令记录
ctrl + r搜索历史命令
ctrl + z暂停某个程序
cd .. 切换到上级目录
cd ~ 切换到用户家目录,直接cd回车也可
cd - 切换到上一个目录
find /home -name *.txt 在home目录中查找所有名字为txt文件
echo "hello world" > outfile将stdout重定向到outfile(覆盖)
echo "hello world" >> outfile 将stdout重定向到outfile(追加)
echo "hello world" 2> outfile 将stderr重定向到outfile(追加)
echo "hello world" 2> outfile 将stdout和stderr结合重定向到outfile(追加)
| 管道,将第一个命令的stdout作为另外一个命令的stdin,由左至右传递
lsattr 显示属性
chattr -i /home/wwwroot/yoursite/.user.ini 更改属性
清除历史命令,两个命令配合使用,然后退出shell
rm -rf .bash_history
history -cw