linux常用命令
真香命令:
- find通常用于查找文件
find 路径 -name 文件名 操作(option)
案例: find /opt -name '*.txt' 翻译: 在/opt目录下,匹配所有.txt文件
find /opt -name '*.txt' -delete 翻译: 在/opt目录下,匹配所有.txt文件、并执行删除操作
- grep过滤查询,通常配合|管道过滤符使用 (过滤进程、文本较多)。
grep 查询文本 文件
案例:
使用grep搜索文件内容:假设你想在文件sample.txt中搜索包含单词"hello"的行
grep "hello" sample.txt
使用grep搜索多个文件:如果你想在所有扩展名为.txt的文件中搜索包含单词"hello"的行
grep "hello" *.txt
grep 进程过滤
ps aux|grep mysql
ps -ef|grep mysql
查看ip:
- ifconfig
修改ip信息:
- vim /etc/sysconfig/network-scripts/ifcfg-ens33
修改主机名称:
- vim /etc/hostname
修改hosts 映射:
- vim /etc/hosts
linux防火墙:
-
开启自启动:systemctl enable firewalld.service
-
关闭自启动:systemctl disable firewalld.service
-
临时关闭:systemctl stop firewalld
-
临时开启:systemctl start firewalld
关机重启:
- reboot 重启
- shutdown now 立刻关机
- shutdown 1 一分钟后关机 (后面参数单位分钟)
- shutdown -r now 重启 等价于reboot
文件目录类命令:
-
pwd 、cd、ls 、ll 、mkdir、rmdir、touch、cp、rm 、mv、cat、tail、>覆写、>>追加 、ln链接、history、find、grep
-
gzip解压缩:压缩:gzip houge.txt、 解压:gunzip houge.txt.gz
-
zip解压缩:压缩:zip mypackage.zip houge.txt
解压:unzip mypackage.zip
-
tar打包:压缩:tar -zcvf houma.tar.gz houge.txt
解压:tar -zxvf houma.tar.gz
进程管理类命令:
- kill 终止进程,-9表示强迫进程立即停止
RPM(RedHat Package Manager)命令:
- RPM 查询命令(rpm -qa)
- RPM 卸载命令(rpm -e)
- RPM 安装命令(**rpm -ivh)
YUM软件包管理器(可以自动处理依赖性关系):
面试题:
vim常用命令
复制:
- yy 复制当前行
- y数字y 多行复制 (y5y)
粘贴:
- p
剪切:
- x 剪切一个字母
- X 剪切一个字母
删除:
- dd 删除当前行
- d数字d 多行删除
插入:
- i 当前插入
- o 换行插入
- a 追加插入
基本语法: