1. 显示计算机的基本信息
显示系统信息:
uname
显示所有内容:(内核版本)
uname -a
2. 查看硬盘
fdisk -l
df -h
3. 查看某一个文件夹占用空间
du –h –max-depth=N
(N为遍历文件夹的深度)
4. 查看内存
free
5. 查看cpu
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq –c
可见有2核,酷睿的型号。
6. 查看网卡信息
dmesg | grep -i eth
7. 查看网关
route -n
8. 查看ip
Ifconfig -a
9. 查看主机名
hostname
10. 修改主机名
在/etc/sysconfig目录下有个文件:network。内容如下:
NETWORKING=yes
HOSTNAME=localhost.localdomain
直接改为:
NETWORKING=yes
HOSTNAME=zoo1.localdomain
在/etc目录下有个hosts文件,内容如下:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
改为:
127.0.0.1 localhost zoo1.localdomain localhost4 localhost4.localdomain4
::1 localhost zoo1.localdomain localhost6 localhost6.localdomain6
再次输入hostname,查看结果:
Centos7上面的方法不管用,使用如下命令:
hostnamectl set-hostname zoo1
11. 修改hosts文件
12. 关闭防火墙
sudo service iptables stop
sudo chkconfig iptables off
第一条命令表示关闭防火墙服务,第二条命令表示系统启动时不需要启动防火墙服务.由于是系统命令,所以需要添加sudo关键字。
查看防火墙状态:
service iptables status
-------------------------------------------------------------------------------------------------------------------------------
上面是centos6中的命令,安装centos7后使用不了,提示:
查看本机的 iptables 的版本:rpm -qa iptables
发现有这个包,可能是没有安装,安装一下(或者卸载后从网上重下一个相同版本的安装)
注:
卸载 iptables 包: rpm -e --nodeps iptables-1.4.21-xxx.xx 这里需要加上 --nodeps 不考虑依赖,强制卸载。
卸载完毕,安装: rpm -ivh iptables-1.4.21-xxx.xx.rpm
这里没有使用上面的“注”。
安装:yum install iptables-services
设置开机启动:systemctl enable iptables
重启iptables: systemctl restart iptables.service,
查看iptables状态:systemctl status iptables.service。
------------------------------------------------------------------------------------------------
忽略上面那一段,centos7使用如下命令操作防火墙:
#查看firewall
systemctl status firewalld.service
#启动firewall
systemctl start firewalld.service
#停止firewall
systemctl stop firewalld.service
#禁止firewall开机启动
systemctl disable firewalld.service
13. 查看时区
timedatectl
14. 修改时区
timedatectl set -timezone Asia/Shanghai
15. 同步时间
timedatectl set -ntp yes
16. 中英文操作界面互换
17. 常见网络服务命令
18. 查看端口占用
netstat -lntup
netstat -antp
查看某个进程占用了哪些端口:
netstat -nap | grep pid
Windows下:
netstat -aon|findstr "443"
19. 当前时间
date
20. 日历
cal
全年日历
cal -y