【Linux】Coder的Linux复习课(二):常用的Linux文件目录类命令

目录

文件目录类

1. pwd:用于打印当前工作目录的绝对路径

2. ls:用于列出当前目录的内容

3. cd:切换目录

4. mkdir:创建一个新目录

5. rmdir:删除一个空项目

6. touch:创建空文件夹

7. cp复制文件或目录

8.  rm:删除文件或目录

9.  mv:移动文件与目录或重命名

10.  cat:查看文件内容

11. more:文件内容分屏查看器

12. less:分屏显示文件内容

13. head:显示文件头部内容

14. tail:显示文件尾部内容


文件目录类

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 [数字] 文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值