南宁网站建设地方,软件工程师工资高吗,百度发帖推广,画廊网站模板第3章 文件类型和目录结构
在这这章之前我们先学习一个前面使用过的命令 ls
查看文件ls
命令格式#xff1a; [rootbogon redhat]# ls --helpUsage: ls [OPTION]... [FILE]...List information about the FILEs (the current directory by default).Sort entries alphabeti…第3章 文件类型和目录结构
在这这章之前我们先学习一个前面使用过的命令 ls
查看文件ls
命令格式 [rootbogon redhat]# ls --helpUsage: ls [OPTION]... [FILE]...List information about the FILEs (the current directory by default).Sort entries alphabetically if none of -cftuvSUX nor --sort is specified. ls 命令是 List 的简写它的作用是显示指定路径下的所有的文件信息。它常用的选项有如下 -a 用于显示所有文件包括隐藏文件及目录-d 显示目录本身而不是目录下的内容-l 以长列表的方式来显示内容-h 以人的读取习惯显示内容-r 递归显示 使用命令
1显示根下所有内容 [rootbogon redhat]# ls // 它是 linux 系统的根目录所有的文件或目录都是挂载到它之下的afsboot 它是系统启动时所需要的文件etc 它是系统中所有的配置文件所在目录它是非常重要的一个目录这个目录大家一定要记住后续学到高级课程时就需要修改它里面的文件lib 库文件在系统运行过程中所需要的一个库文件media 媒体它是用户挂载的一般我们光盘就可以挂载到它下面opt 它是第三方软件安装目录root 它是 root 用户有家目录sbin 超级用户可以执行的命令所在目录sys 这是用户存储虚拟的文件路径usr unix software resource 它是软件资源所在目录bin 普通用户可以执行的命令所在目录dev 设备文件所在目录home 它是普通用户所在的家目录lib64 它也是库文件所在目录mnt 它是挂载目录proc 进程所在目录run 程序运行时相关的文件所在路径srv 网络服务数据tmp 运行程序时产生的临时文件在这个目录中不要存储重要信息因为它可能会被系统删除var 用于存放一些变化的数据例如日志 -a 选项 [rootbogon redhat]# ls -a /
. afs bin dev home lib64 mnt proc run srv tmp var
.. .bash_history boot etc lib media opt root sbin sys usr当指定了 -a 选项时发现多了一些内容 . 它表示当前目录
.. 它表示上一级目录
.bash_history 表示它是一个隐藏文件或目录 注意 在 linux 中以点开头的文件或目录是隐藏文件或目录 任何一个目录当执行了 ls 命令后都可以看到 . 和 .. -d 选择
只显示目录本身而不会显示目录内容 [rootbogon redhat]# ls /usr
bin games include lib lib64 libexec local sbin share src tmp
[rootbogon redhat]# ls -d /usr
/usr-l 选项
它是以长列表的方式来显示内容 [rootbogon redhat]# ls /usr
bin games include lib lib64 libexec local sbin share src tmp
# 下面是带了 -l 选项的
[rootbogon redhat]# ls -l /usr
total 240
dr-xr-xr-x. 2 root root 45056 Oct 15 19:40 bin
drwxr-xr-x. 2 root root 6 Aug 10 2021 games
drwxr-xr-x. 3 root root 23 Oct 15 19:38 include
dr-xr-xr-x. 38 root root 4096 Oct 15 19:42 lib
dr-xr-xr-x. 123 root root 73728 Oct 15 19:42 lib64
drwxr-xr-x. 46 root root 12288 Oct 15 19:40 libexec
drwxr-xr-x. 12 root root 131 Oct 15 19:36 local
dr-xr-xr-x. 2 root root 20480 Oct 15 19:40 sbin
drwxr-xr-x. 213 root root 8192 Oct 15 19:40 share
drwxr-xr-x. 4 root root 34 Oct 15 19:36 src
lrwxrwxrwx. 1 root root 10 Aug 10 2021 tmp - ../var/tmp
[rootbogon redhat]# 内容格式说明 d r-xr-xr-x. 2 root root 45056 Oct 15 19:40 bin
1 2 3 4 5 6 7 81. 文件的类型
2. 文件的操作权限
3. 硬连接数
4. 文件所有者创建文件的人
5. 文件所发属组名称
6. 文件大小单位为字节
7. 文件最后一次修改时间
8. 文件名称 在 Linux 中一切皆文件。 -h 选项 [rootbogon redhat]# ls -l -h /usr
total 240K
dr-xr-xr-x. 2 root root 44K Oct 15 19:40 bin
drwxr-xr-x. 2 root root 6 Aug 10 2021 games
drwxr-xr-x. 3 root root 23 Oct 15 19:38 include
dr-xr-xr-x. 38 root root 4.0K Oct 15 19:42 lib
dr-xr-xr-x. 123 root root 72K Oct 15 19:42 lib64
drwxr-xr-x. 46 root root 12K Oct 15 19:40 libexec
drwxr-xr-x. 12 root root 131 Oct 15 19:36 local
dr-xr-xr-x. 2 root root 20K Oct 15 19:40 sbin
drwxr-xr-x. 213 root root 8.0K Oct 15 19:40 share
drwxr-xr-x. 4 root root 34 Oct 15 19:36 src
lrwxrwxrwx. 1 root root 10 Aug 10 2021 tmp - ../var/tmp# 我们可以在命令后面跟多个选项多个选项之间用空格分隔当然也可以把选项进行组全例如
[rootbogon redhat]# ls -lh /usr
total 240K
dr-xr-xr-x. 2 root root 44K Oct 15 19:40 bin
drwxr-xr-x. 2 root root 6 Aug 10 2021 games
drwxr-xr-x. 3 root root 23 Oct 15 19:38 include
dr-xr-xr-x. 38 root root 4.0K Oct 15 19:42 lib
dr-xr-xr-x. 123 root root 72K Oct 15 19:42 lib64
drwxr-xr-x. 46 root root 12K Oct 15 19:40 libexec
drwxr-xr-x. 12 root root 131 Oct 15 19:36 local
dr-xr-xr-x. 2 root root 20K Oct 15 19:40 sbin
drwxr-xr-x. 213 root root 8.0K Oct 15 19:40 share
drwxr-xr-x. 4 root root 34 Oct 15 19:36 src
lrwxrwxrwx. 1 root root 10 Aug 10 2021 tmp - ../var/tmp文件类型
在 linux 中一共有 七 种文件类分别是如下 - 表示普通文件
d 表示目录
l 链接文件分为软链接和硬链接
c 表示字符设备文件
b 块设备文件
p 管道文件
s 套接字文件 [rootbogon ~]# ll /usr/bin/ls
-rwxr-xr-x. 1 root root 140760 Jan 6 2023 /usr/bin/ls
[rootbogon ~]# ll -d /root
dr-xr-x---. 14 root root 4096 Oct 29 16:29 /root
[rootbogon ~]# ll /dev/tty
crw-rw-rw-. 1 root tty 5, 0 Oct 29 16:29 /dev/tty
[rootbogon ~]# ll /dev/sr0
brw-rw---- 1 root cdrom 11, 0 Oct 29 16:29 /dev/sr0
[rootbogon ~]# ll /usr/bin/yum
lrwxrwxrwx. 1 root root 5 Mar 15 2023 /usr/bin/yum - dnf-3 路径切换cd
这个命令的作用是用来切换用户的工作路径。cd 是 change directory 的简写。
它的语法格式 [rootbogon ~]# cd --help
cd: cd [-L|[-P [-e]] [-]] [dir]Change the shell working directory.Change the current directory to DIR. The default DIR is the value of theHOME shell variable.命令使用 [rootbogon ~]# pwd
/root
[rootbogon ~]# cd /var/log
[rootbogon log]# pwd
/var/log
[rootbogon log]# cd .. # 切换到上级目录
[rootbogon var]# pwd
/var
[rootbogon var]# cd /usr/local/etc
[rootbogon etc]# ls
[rootbogon etc]# pwd
/usr/local/etc
# 希望切换到 /usr 目录下
[rootbogon etc]# cd ../../
[rootbogon usr]# pwd
/usr
[rootbogon usr]# cd /usr# cd - 会在最近两目录之间来回切换
[rootbogon home]# cd -
/root
[rootbogon ~]# cd -
/home
[rootbogon home]# cd -
/root
[rootbogon ~]# cd -
/home# 如果只写 cd 不带参数表示切换到 root 用户的家目录
[rootbogon home]# cd
[rootbogon ~]# # cd ~ 也会切换到当前用户所在的家目录
[rootbogon home]# cd ~
[rootbogon ~]#