【Linux】文件目录类解析,彻底帮你搞懂

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Linux运维全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上运维知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024b (备注运维)
img

正文

cat查看文件内容指令


cat查看文件内容

基本语法:cat   [选项]  要查看的文件

常用选项:-n  :显示行号

示例:查看hello.java

[root@kongchao02 home]# vim hello.java

[root@kongchao02 home]# ls

hello.java kongchao kongchao1 kongchao2 text3 text4

[root@kongchao02 home]# cat -n hello.java

1 public class Hello{

2 public static void main (String[] args){

3 System.out.println(“hello java”);

4

5 }

6

7

8

9

10 }

使用细节:cat只能浏览文件,而不能修改文件(所以cat安全),为了浏览方便,一般会带上管道命令 | more,作用是把查询到的结果交给more处理,等全部显示完就会退出more

cat -n  /etc/profile |more(交互指令)

如按下空格显示更多

more指令


more指令是一个基于vi编辑器的文本过滤器,他以全屏幕的方式按页显示文本文件的内容,more指令中内置了若干个快捷键(交互指令)

基本语法:more 要查看的文件

操作说明如图:

less查看指令


less指令用来分屏查看文件内容,它的功能与more指令类似,但是比more指令更加强大,支持各种显示终端。less指令在显示文件内容时,并不是一次将整个文件加载之后才显示,而是根据显示需要加载的内容,对于显示大型文件具有较高的效率。

基本语法**:less   要查看的文件**

echo输出指令


echo输出内容到控制台

基本语法:echo  [选项]   [输出内容]

示例:用echo指令输出环境变量和指定内容

[root@kongchao02 ~]# echo $HOSTNAME

kongchao02

[root@kongchao02 ~]# echo “hello kongchao”

hello kongchao

[root@kongchao02 ~]#

head显示头部指令


head指令用于显示文件开头部分内容,默认情况下head指令显示文件的前10行内容

基本语法:head  文件  (查看文件头10行内容)

head  -n  15 文件 (查看文件头15行内容,可以是任意行数)

示例:查看/etc/profile下前6行

[root@kongchao02 ~]# head -n 6 /etc/profile

/etc/profile

System wide environment and startup programs, for login setup

Functions and aliases go in /etc/bashrc

It’s NOT a good idea to change this file unless you know what you

[root@kongchao02 ~]#

tail显示尾部指令


tail用于输出文件中尾部的内容,  默认情况下tail显示文件的前10行内容。

基本语法:

tail  文件(查看文件尾部10行内容)

tail  -n  5  文件     (查看文件尾部5行内容)

tail  -f  文件   (实时追踪该文档的所有更新,该文件变化会反馈出来)

[root@kongchao02 ~]# tail /etc/profile

if [ “KaTeX parse error: Expected '}', got '#' at position 3: {-#̲*i}" != "-” ]; then

. “$i”

else

. “$i” >/dev/null

fi

fi

done

unset i

unset -f pathmunge

[root@kongchao02 ~]# tail -n 5 /etc/profile

fi

done

unset i

unset -f pathmunge

[root@kongchao02 ~]#

覆盖指令和>>追加指令


>是覆盖原先的内容,>>是追加到原来的内容之后

基本语法:

ls -l  > 文件   (列表的内容写入到文件中覆盖原先的)

ls  -al  >> 文件  (列表的内容追加到文件的末尾)

cat  文件1  >  文件2 (将文件1内容覆盖到文件2中)

echo  “内容”  >>  文件 (将内容追加到文件中)

示例1:将/home目录下的文件列表写入到/home/text.txt中,覆盖写入(ls -l  /home  > /text.txt)如果text.txt不存在则会自动创建

[root@kongchao02 home]# ls -l /home

总用量 24

-rw-r–r–. 1 root root 107 3月 4 22:22 hello.java

drwx------. 15 kongchao kongchao 4096 3月 1 20:37 kongchao

drwx------. 5 kongchao1 kongchao1 4096 2月 28 22:08 kongchao1

drwx------. 3 kongchao2 kongchao2 4096 2月 28 22:11 kongchao2

drwxr-xr-x. 2 root root 4096 3月 3 21:44 text3

drwxr-xr-x. 3 root root 4096 3月 3 21:27 text4

[root@kongchao02 home]# ls -l /home > text.txt

[root@kongchao02 home]# ls /home

hello.java kongchao kongchao1 kongchao2 text3 text4 text.txt

[root@kongchao02 home]# cat /home/text.txt

总用量 24

-rw-r–r–. 1 root root 107 3月 4 22:22 hello.java

drwx------. 15 kongchao kongchao 4096 3月 1 20:37 kongchao

drwx------. 5 kongchao1 kongchao1 4096 2月 28 22:08 kongchao1

drwx------. 3 kongchao2 kongchao2 4096 2月 28 22:11 kongchao2

drwxr-xr-x. 2 root root 4096 3月 3 21:44 text3

drwxr-xr-x. 3 root root 4096 3月 3 21:27 text4

-rw-r–r–. 1 root root 0 3月 4 22:29 text.txt

[root@kongchao02 home]#

示例2:将I am kc追加到hello.java中

[root@kongchao02 home]# cat /home/hello.java

public class Hello{

public static void main (String[] args){

System.out.println(“hello java”);

}

}

[root@kongchao02 home]# echo “I am kc” >> /home/hello.java

[root@kongchao02 home]# cat /home/hello.java

public class Hello{

public static void main (String[] args){

System.out.println(“hello java”);

}

}

I am kc

[root@kongchao02 home]#

示例3:将文件覆盖

[root@kongchao02 home]# cd /home/

[root@kongchao02 home]# cat text.txt

总用量 24

-rw-r–r–. 1 root root 107 3月 4 22:22 hello.java

drwx------. 15 kongchao kongchao 4096 3月 1 20:37 kongchao

drwx------. 5 kongchao1 kongchao1 4096 2月 28 22:08 kongchao1

drwx------. 3 kongchao2 kongchao2 4096 2月 28 22:11 kongchao2

drwxr-xr-x. 2 root root 4096 3月 3 21:44 text3

drwxr-xr-x. 3 root root 4096 3月 3 21:27 text4

-rw-r–r–. 1 root root 0 3月 4 22:29 text.txt

[root@kongchao02 home]# cat hello.java > text.txt

[root@kongchao02 home]# cat text.txt

public class Hello{

public static void main (String[] args){

System.out.println(“hello java”);

}

}

I am kc

[root@kongchao02 home]#

当前日历显示 cal


[root@kongchao02 ~]# cal

三月 2022

日 一 二 三 四 五 六

1 2 3 4 5

6 7 8 9 10 11 12

13 14 15 16 17 18 19

20 21 22 23 24 25 26

27 28 29 30 31

[root@kongchao02 ~]#

ln符号连接指令


In软连接也称符号连接,类似于windows里的快捷方式,主要存放了链接其他文件的路径

基本语法:ln -s  [原文件或目录]   [软链接名]   (给原文件创建一个软链接)

**示例:**在/home目录下创建一个软链接myroot,链接到/root目录

[root@kongchao02 ~]# ln -s /root /home/myroot

[root@kongchao02 ~]# ls /home

hello.txt kongchao kongchao1 kongchao2 myroot

[root@kongchao02 ~]# cd /home/myroot/

[root@kongchao02 myroot]# ls

anaconda-ks.cfg 公共 视频 文档 音乐

initial-setup-ks.cfg 模板 图片 下载 桌面

[root@kongchao02 myroot]# pwd

/home/myroot

[root@kongchao02 myroot]#

细节说明:当我们使用pwd指令查看目录是,仍然看到的是软链接所在的目录,而不是指向的目录

删除软链接rm


rm  软链接路径

[root@kongchao02 myroot]# rm /home/myroot

rm:是否删除符号链接 “/home/myroot”?y

[root@kongchao02 myroot]# ls /home

hello.txt kongchao kongchao1 kongchao2

[root@kongchao02 myroot]#

history查看历史命令指令


history查看已经执行过历史命令,也可以执行历史命令

基本语法:history  [数字]  (查看已经执行过的多少条命令)

查看所有历史命令:history

查看10条历史命令:history  10

执行历史编号的指令:!编号

示例1:查看历史指令过的指令

[root@kongchao02 myroot]# history

1 gcc -v

2 ifconfig

3 reboot

4 ifconfig

5 cat /etc/passwd

6 useradd kongchao1

7 passwd kongchao1

8 su kongchao1

9 clear

10 ls

11 vim hello.v

12 vim /etc/passwd/

13 useradd kongchao2

14 passwd kongchao2

15 clear

16 cat /etc/passwd

17 clear

18 vim /etc/shadow

19 cat /etc/shadow

20 clear

21 cat /etc/group

22 clear

23 init 5

24 init 3

25 init 5

26 gcc- v

27 gcc -v

28 tree

29 ls /home/

30 ls

31 su kongchao

32 logout

33 ifconfig

34 vim clear

35 man ls

36 q

37 help cd

38 clear

39 ls /

40 cd /

41 ls

42 cd home

43 s

44 clear

45 cd /home

46 ls

47 cd kongchao

48 pwd

49 clear

50 ls -a

51 ls -al

52 ls a

53 man lc

54 manls

55 man ls

56 clear

57 ls -al

58 cd /home

59 ls

60 cd kongchao

61 cd/

62 cd /

63 clear

64 cd /home/kongchao

65 cd ~

66 pwd

67 ls -s /root /home/myroot

68 clear

69 ln -s /root /home/myroot

70 ls /home

71 cd /home/myroot/

72 ls

73 pwd

74 clear

75 ls /home/myroot/

76 clear

77 ls /home

78 rm /home/myroot/

79 clear

80 rm /home/myroot

81 ls /home

82 clear

83 history

示例2:查看指令过的10条指令

[root@kongchao02 myroot]# history 10

75 ls /home/myroot/

76 clear

77 ls /home

78 rm /home/myroot/

79 clear

80 rm /home/myroot

81 ls /home

82 clear

83 history

84 history 10

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注运维)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
cd /home/kongchao

65 cd ~

66 pwd

67 ls -s /root /home/myroot

68 clear

69 ln -s /root /home/myroot

70 ls /home

71 cd /home/myroot/

72 ls

73 pwd

74 clear

75 ls /home/myroot/

76 clear

77 ls /home

78 rm /home/myroot/

79 clear

80 rm /home/myroot

81 ls /home

82 clear

83 history

示例2:查看指令过的10条指令

[root@kongchao02 myroot]# history 10

75 ls /home/myroot/

76 clear

77 ls /home

78 rm /home/myroot/

79 clear

80 rm /home/myroot

81 ls /home

82 clear

83 history

84 history 10

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注运维)
[外链图片转存中…(img-qUUudi91-1713197543463)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值