目录
文件目录类
1. pwd:用于打印当前工作目录的绝对路径
语法:pwd
[root@hadoop101 ~]# pwd
/root
2. ls:用于列出当前目录的内容
语法:ls [选项] [目录或文件]
[root@hadoop101 ~]# ls -l /
总用量 28
drwxr-xr-x. 2 root root 6 10月 20 08:27 23340201
lrwxrwxrwx. 1 root root 7 2月 25 2025 bin -> usr/bin

注:ls -l也可以写成ll
3. cd:切换目录
语法:cd [参数]

实践操作:
(1)使用绝对路径切换到 root 目录
[root@hadoop101 ~]# cd /root/
(2)返回到自己的家目录
[root@hadoop101 linuxprobe]# cd ~
[root@hadoop101 ~]#
(3)返回到当前目录的上一级
[root@hadoop101 linuxprobe]# cd ..
[root@hadoop101 ~]#
4. mkdir:创建一个新目录
语法:mkdir [选项] 要创建的目录

实践操作:
(1) 在根目录下创建一个名字叫"coder"的目录
[root@hadoop101 ~]# mkdir /root/coder
(2) 在"coder"目录下创建"test1",并在"test1"下创建"test2"。
[root@hadoop101 ~]# mkdir -p /coder/test1/test2
[root@hadoop101 ~]# cd /coder/
[root@hadoop101 coder]# ls
test1
[root@hadoop101 coder]# cd test1/
[root@hadoop101 test1]# ls
test2
5. rmdir:删除一个空项目
语法:rmdir [目录路径]
实践操作:
(1)删除一个空文件夹
[root@hadoop101 test1]# rmdir /coder/test1/test2/
6. touch:创建空文件夹
语法:touch [文件名称]
[root@hadoop101 test1]# touch test.txt
[root@hadoop101 test1]# ls
test.txt
7. cp复制文件或目录
语法:cp [选项] 原文件路径 目的文件路径

[root@hadoop101 test1]# cp test.txt /coder
[root@hadoop101 test1]# cd ..
[root@hadoop101 coder]# ls
test1 test.txt
8. rm:删除文件或目录
语法:rm [选项] 要删除的文件

[root@hadoop101 ~]# rm -rf coder/
[root@hadoop101 ~]#
9. mv:移动文件与目录或重命名
语法:①重命名:rm oldNameFile newNameFile
②移动文件:rm /temp/movefile /targetFolder
①重命名
[root@hadoop101 cptest]# ls
b.txt coder
[root@hadoop101 cptest]# mv b.txt coder.txt
[root@hadoop101 cptest]# ls
coder coder.txt
[root@hadoop101 cptest]#
②移动文件
[root@hadoop101 ~]# mv coder cptest/
[root@hadoop101 ~]#
10. cat:查看文件内容
语法:cat [选项] 要查看的文件

[root@hadoop101 cptest]# cat coder.txt
hello Coder
congralation,10000 reads
11. more:文件内容分屏查看器
语法:more 要查看的文件


12. less:分屏显示文件内容
语法:less 要查看的文件

13. head:显示文件头部内容
语法:head 文件 (默认显示前10行)
head -n [数字] 文件 (数字为任意数)

[root@hadoop101 ~]# head -n 3 info
anaconda-ks.cfg
hello1
info
14. tail:显示文件尾部内容
语法:tail 文件
tail -n [数字] 文件


被折叠的 条评论
为什么被折叠?



