常识
root 超级管理员 /root 家目录
jepson 普通用户 界面创建 /home/jepson 普通用户
ruoze /home/ruoze
clear 清空屏幕
默认系统是这样 除非指定用户的家目录为其他目录
Linux系统的目录是从根目录开始 /
[root@hadoop001 home]# ls -l /home
total 76
drwxr-xr-x权限 3 root用户 root 用户组 096 Mar 13 01:39时间 1 名称
命令
pwd 查看当前光标所在的目录 显示从根目录 / 开始绝对路径
ls ll 查看
ls / 只显示该目录下的文件或文件夹的名称
ls -l / 显示该目录下的文件或文件夹的明细信息 ls -l = ll
ll -h 查看文件的大小
ll -rt 从小到大按时间排序 想要找出最新的文件或文件夹 = ls -l -r -t =ls -lrt
ll -a 查看隐藏文件夹或文件 隐藏是以.
du -sh 查看文件夹或文件大小
du -sh Desktop/ 文件夹的大小
du -sh install.log 文件的大小
cd切换目录
cd 切家目录
cd ~ 切家目录 **~标识
cd /root 用户的家目录的绝对路径
cd - 回到当前目录的上一次目录
cd …/ 回退当前目录的上一层目录
cd …/…/ 回退当前目录的2个目录
路径:1:绝对路径 /根目录开始 2相对路径 不以/根目录开始
在[root@hadoop001 ~]# cd /root/5566/ 绝对路径 /根目录开始
[root@hadoop001 5566]#
[root@hadoop001 ~]# ls
1 2 3 44 5566 6677 78910 chenxiaoer d root ruozetada win wt
1. 222 33 55 6 7788 chenqian chenyi d66 ruoze test wr ww
[root@hadoop001 ~]# cd 6677/ 相对路径,不以/开始
[root@hadoop001 6677]#
创建文件夹
mkdir xxx 只能创建1个
[root@hadoop001 ~]# mkdir 20190618
[root@hadoop001 ~]# cd /root/20190618
[root@hadoop001 20190618]#
mkdir -p xxx/xxxx/xxxx/xxxx 级联创建 文件夹 串行
[root@hadoop001 20190618]# mkdir -p 0618/0619/0620/0621
/root/20190618/0618/0619/0620/0621
mkdir xxx xxx xxx xxx 并行
创建文件以及vi命令
touch chenbqian.log 创建空文件
vi chenbqian.log 创建编辑内容
1.命令行模式 i进入编辑模式
2.esc 回退到命令行模式
3.shift+:尾行模式 wq保存退出
[root@hadoop001 ~]# touch chenqian.log 创建空文件
[root@hadoop001 ~]# vi chenqian.log 编辑模式:1. i 进入编辑模式 ,
2.esc 回退到命令行模式
3.shift+:尾行模式 wq保存退出
[root@hadoop001 ~]# tail -f chenqian.log 查看编辑的内容
jianchi
nuli
stuy
big data
^C
[root@hadoop001 ~]#
mv 移动 只有一份
mv chenqian.log wet 移动文件到新的地方 名称不变
[root@hadoop001 ~]# mv chenqian.log wt
[root@hadoop001 ~]# cd wt/
[root@hadoop001 wt]# ll
total 12
-rw-r--r-- 1 root root 27 Jun 18 12:49 chenqian.log
-rw-r--r-- 1 root root 47 Jun 17 18:55 wt
drwxr-xr-x 2 root root 4096 Jun 17 17:51 ww
[root@hadoop001 wt]#
mv chenqian.log 6/chenqian.log1 移动文件到新的地方 名称变
[root@hadoop001 wt]# mv chenqian.log ww/chenqian.log1
[root@hadoop001 wt]# ll
total 8
-rw-r--r-- 1 root root 47 Jun 17 18:55 wt
drwxr-xr-x 2 root root 4096 Jun 18 17:53 ww
[root@hadoop001 wt]# cd ww/
[root@hadoop001 ww]# ll
total 4
-rw-r--r-- 1 root root 27 Jun 18 12:49 chenqian.log1
[root@hadoop001 ww]#
mv ww wt 移动文件夹
[root@hadoop001 ~]# mv ww wt
[root@hadoop001 ~]# cd wt/
[root@hadoop001 wt]# ll
total 8
-rw-r--r-- 1 root root 47 Jun 17 18:55 wt
drwxr-xr-x 2 root root 4096 Jun 17 17:51 ww
cp拷贝 2份 原有的还在
cp ruoze.log ruozedata/
cp -r 7 6/ 文件夹拷贝 需要-r参数
命令帮助 xx --help
Usage: ls [OPTION]… [FILE]… []代表可以省略
[root@hadoop001 ~]# tail --help
Usage: tail [OPTION]... [FILE]... []代表可以省略
文件内容 离线查看
cat 文件内容一下子全部显示 适用字节内容较少
more 文件内容一页一页的往下翻 按空格键往下 回退不了 按q退出 适用字节内容稍多的
less 文件内容 一行行 按箭头上下 按q退出
结合生产配套使用:
1文件(log)的内容 ERROR 定位错误
假如文件超大 10m 发送给window电脑,通过editplus 全局搜索
2 假如文件 假如100m+
cat install.log | grep -C 10 "ERROR"
3 假如 ERROR筛选的结果 特多
cat install.log | grep -C 10 "ERROR" > error.log
附加命令意义:
| 管道符 表示 管道符前面命令的输出作为后面命令的输入 的意思
grep 过滤
grep -C 10 上下文共20行各10行
> 重定向输出 到文件 覆盖
>> 追加
实时查看:tail -f taif -F -F=-f+retry
[root@hadoop001 ~]# touch tail11.log
[root@hadoop001 ~]# touch tail22.log
[root@hadoop001 ~]# echo "55">> tail11.log
[root@hadoop001 ~]# echo "55">> tail22.log
[root@hadoop001 ~]# mv tail11.log tail11.log1
[root@hadoop001 ~]# touch tail11.log
[root@hadoop001 ~]# mv tail22.log tail22.log1
[root@hadoop001 ~]# touch tail22.log
[root@hadoop001 ~]# echo "7755">> tail11.log
[root@hadoop001 ~]# echo "55">> tail22.log
[root@hadoop001 ~]# echo "55">> tail22.log
[root@hadoop001 ~]# echo "55">> tail22.log
[root@hadoop001 ~]# echo "7755">> tail22.log
[root@hadoop001 ~]#
说明-f 不够强大 文件只要被移走 就算新的一模一样 也不会实时监控
反之-F 强大 实时监控
生产案例 需求:查看倒数10 行
tail -10f xxx.log