linux常用命令
<h2>文件目录操作</h2>
<pre><code class="language-shell"># 创建目录
mkdir -p test_dir
# 创建文件
touch file_name
# 复制
cp –r test/ newtest
# 移动、重命名
mv old_file new_file
# 查找配置文件所在位置
find / -name ngnix.conf
ps -ef | grep nginx
# 删除当前目录下所有文件
pwd
rm -rf ./*
回车之前一定要再次确认一下,避免删除错误。</code></pre>
<h2>查看磁盘</h2>
<pre><code class="language-shell"># 查看磁盘空间
df -hl
# 查看文件索引节点
df -i
# 查看目录所用空间
du -sh *</code></pre>
<h3>目录权限</h3>
<pre><code class="language-shell"># 目录授权,所有人,所属组
chown -R www-data:www-data /var/www/controlRoomManage
#
chmod -R 755 /var/www/controlRoomManage</code></pre>
<h2>压缩</h2>
<ul>
<li>压缩建议步骤
<ul>
<li>把要压缩目录复制</li>
<li>压缩复制目录</li>
</ul></li>
</ul>
<pre><code class="language-shell"># 压缩成zip
zip -q -r html.zip /home/html
# 解压zip
unzip html.zip
# 压缩(tar)
tar -czf jpg.tar.gz *.jpg
# 将目录里所有jpg文件打包成jpg.tar后,并且将其用gzip压缩,生成一个gzip压缩过的包,命名为jpg.tar.gz
tar -xzf file.tar.gz # 解压tar.gz </code></pre>
<h2>服务</h2>
<pre><code class="language-shell"># 查看正在运行服务
# 查看运行的进程
ps -aux
ps -aux | less
# 查看端口
netstat -a
# 查看服务cpu利用
top
# 重启nginx
service nginx restart
/etc/init.d/nginx stop
/etc/init.d/nginx start</code></pre>
<h2>系统信息、操作</h2>
<pre><code class="language-shell"># 显示发行版本信息
lsb_release -a
# 统计网络接口流量状态
ifstat
# 查看所有用户信息
/etc/group
/etc/shadow
/etc/passwd
# 查看所有用户
cat /etc/passwd |cut -f 1 -d :
# 定时任务
crontab -l
crontab -e -u 用户名
# 重启服务器
reboot</code></pre>
<h2>防火墙</h2>
<ul>
<li>
<p>service方式</p>
<pre><code class="language-shell"># 查看防火墙
service iptables status
# 开启防火墙
service iptables start
# 关闭防火墙
service iptables stop</code></pre>
</li>
<li>
<p>iptables方式</p>
<pre><code class="language-shell"># 查看防火墙
cd /etc/init.d/
/etc/init.d/iptables status
# 开启防火墙
/etc/init.d/iptables start
# 关闭防火墙
/etc/init.d/iptables stop
# 重启iptables
/etc/init.d/iptables restart</code></pre>
</li>
<li>
<p>Failed to start iptables.service: Unit not found</p>
<ul>
<li><a href="https://blog.csdn.net/c233728461/article/details/52679558/">https://blog.csdn.net/c233728461/article/details/52679558/</a></li>
</ul>
<pre><code class="language-shell">systemctl stop firewalld
systemctl mask firewalld
# 安装iptables-services
yum install iptables-services
# 设置开机启动
systemctl enable iptables
# iptables启动操作
systemctl stop iptables
systemctl start iptables
systemctl restart iptables
systemctl reload iptables
# 保存设置
service iptables save</code></pre>
<ul>
<li>开放某个端口</li>
</ul>
<pre><code class="language-shell"># 在/etc/sysconfig/iptables里添加
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT</code></pre>
</li>
<li>
<p>查看防火墙</p>
<pre><code class="language-shell"># 查看状态
firewall-cmd --state
# 停止防火墙
systemctl stop firewalld.service
# 禁止防火墙开机启动
systemctl disable firewalld.service
# 查看已经开放的端
firewall-cmd --list-ports</code></pre>
</li>
</ul>