常用命令
链接:https://pan.baidu.com/s/1BwooEhXyGy5GgDFQ8z-Ycg 提取码:gk99
复制这段内容后打开百度网盘手机App,操作更方便哦
1)系统
who -> 最近登录日志信息
who am i -> 当前用户
clear -> 清屏
ifconfig -> 查看网络IP地址
pwd -> 当前位置
Linux文件目录
/
子目录
孙目录
ls -> 查看子目录列表
ls -l 等价于 ll 目录详情
ls -a 查看所有目录(隐藏目录文件 .XXX)
cd -> 切换目录 (服务器只有键盘)
cd / 根目录
cd ~ 家目录
root家目录 : /root
redhat01家目录 : /home/redhat01
cd .. 返回上一级目录
ps -> 进程管理
ps -ef -> 查看当前进程 (任务管理器)
ps -ef | grep {key} -> 关键字定位进程
kill
kill -9 {pid} -> 根据进程id 强制结束进程
systemctl ->服务管理
systemctl status firewalld.service 查看防火墙状态
systemctl stop firewalld.service 关闭防火墙
-> 开发环境可以考虑 实施环境中不可取(开放特点端口方式处理)
systemctl disable firewalld.service 禁用防火墙
systemctl start firewalld.service 启动防火墙
systemctl start mysqld.service 启动MySql服务
软件安装
rpm -ivh XXX.rpm -> 直接安装
tar -xzvf XXX.tar.gz -> 解压安装
yum install XXX.yum -> 挂载安装(批处理)
注意:
tab 补全
上下箭头 获取历史命令
支持通配符 *
2)文件夹/文件
创建 mkdir
mkdir 文件夹
mkdir 文件夹1 文件夹2 文件夹3
mkdir -p 文件夹4/文件夹5
拷贝 cp
cp 文件 目标文件
cp -r 文件夹 目标文件夹(不存在)
cp -r 文件夹1,文件夹2 文件夹3(存在) ->文件夹1,文件夹2 拷贝到 文件夹3中
移动 mv
mv 文件夹 目标文件夹(不存在) -> 更名
mv 文件夹1,文件夹2 文件夹3(存在) ->文件夹1,文件夹2 移动到 文件夹3中
删除 rm
rm 文件 ->删除文件
rm -r 文件夹 ->删除有提示
rm -rf 文件夹 ->直接删除
3)文档(文档)
vi
只读模式 vi 文件
文件存在打开文件 文件不存在新建文件
"dd" 删除当前行
"a" "i" -> 只读模式进入编辑模式
":" -> 只读模式进入命令模式
编辑模式
注意:不存在快捷键 Ctrl+C Ctrl+V
说明:复制 选中内容后点击鼠标左键 | 粘贴 点击鼠标右键
Esc -> 编辑模式返回只读模式
命令模式
:q! -> 不保存退出
:wq -> 保存退出
:/{key} -> 定位匹配关键所在的行
:set number ->打开行号
:set nonumber -> 关闭行号
head ->读取文件前多少行
head -n 5 hello.txt -> 仅显示hello.txt前5行数据
head -n 5 hello.txt > hello1.txt -> 将hello.txt前5行数据写入到hello1.txt
tail ->读取文件后多少行
tail -n 5 hello.txt -> 仅显示hello.txt后5行数据
tail -n 5 hello.txt > hello2.txt -> 将hello.txt后5行数据写入到hello2.txt
cat ->查看文件内容
cat -n hello.txt > hello3.txt -> 配合行号将hello.txt数据写入新的文件hello3.txt
练习题:获取某文件中的10-20行数据并写入到指定文件中并添加行号
head -n 20 file.txt > temp1.txt
tail -n 10 temp1.txt > temp2.txt
cat -n temp2.txt > temp3.txt
cat -n file.txt | head -n 20 | tail -n 10 > temp.txt
cat -n file.txt | sed -n 10,20p >temp.txt
echo ->打印数据
echo 'Hello World' > hello.txt -> 将Hello World文本 写入到hello.txt文件中
注意: > 将文本内容写入文件
4)文件权限
权限 r(读) w(写) x(可执行)
-rw-r--r--. 1 root root 80 May 10 17:02 hello.txt
-rw-r--r--. 1 root root 24 May 10 17:19 spring.txt
-rw-r--r--. 1 root root 66 May 10 17:16 temp1.txt
-rw-r--r--. 1 root root 55 May 10 17:13 temp.txt
drwxr-xr-x. 2 root root 6 May 10 17:21 test1
drwxr-xr-x. 2 root root 6 May 10 17:21 test2
[1] 文件类型
- -> 文件 rw
d -> 文件夹 rwx
[3] 用户
rwx 等价于 111(2) = 7(10)
rw- 等价于 110(2) = 6(10)
r-- 等价于 100(2) = 4(10)
--- 等价于 000(2) = 0(10)
[3] 用户所在组
[3] 其他组的用户
授权 chmod [权限编码] 文件|文件夹