目录
Linux系统文件与目录管理
一、Linux系统目录结构
1、查看目录结构命令
二、文件与目录操作命令
1、打印工作目录命令
2、目录切换命令
3、目录内容查看命令
4、文件查看命令
cat命令
重定向符号
在根目录下输入 ls ,即可查看根目录下的子目录
[root@wezzer /]# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys
bin 存储所有可操作二进制指令文件目录 (usr/bin)
[root@wezzer /]# tree bin
sbin 存储管理员可操作的二进制指令文件目录 (usr/sbin)
[root@wezzer /]# tree sbin
boot 存储内核和启动文件目录
[root@wezzer /]# tree boot
dev 储存设备文件目录
[root@wezzer /]# tree dev
etc 存储当前系统配置文件目录 /etc/selinux linux安全设置的相关文件存储目录
[root@wezzer /]# tree etc
home 普通用户家目录
[root@wezzer /]# tree home
lib 32位应用程序依赖库 (usr/bin)
[root@wezzer /]# tree lib
lib64 64位应用程序依赖库(可能也有32位应用程序 向下兼容) (usr/bin64)
[root@wezzer /]# tree lib64
media 媒体 cd/DVD
[root@wezzer /]# tree media
mnt
[root@wezzer /]# tree mnt
opt
[root@wezzer /]# tree opt
proc 映射目录,储存进程文件信息目录(cpu内存信息),(不占用磁盘空间)
[root@wezzer /]# tree proc
root 超级管理员的家目录
[root@wezzer /]# tree root
run 所有进程运行后的ID文件目录
[root@wezzer /]# tree run
srv
[root@wezzer /]# tree srv
sys 系统性能、内核、相关配置文件目录
[root@wezzer /]# tree sys
tmp 临时存储文件目录(所有用户)
[root@wezzer /]# tree tmp
usr用户目录 usr/local 第三方应用安装
[root@wezzer /]# tree usr
var 邮件、日志相关,缓存文件,数据目录 var/log 系统日志目录;var/spool/mail 邮件文件
[root@wezzer /]# tree var
CentOS系统中,加入 tree 命令
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache fast
yum install -y tree
pwd 查看当前目录的完全路径
[root@wezzer opt]# pwd
/opt/opt/opt/opt
cd 返回当前登录的家目录
cd .. 返回上级目录
cd ~ 返回当前登录用户的家目录
cd - 返回上次跳转到当前目录的目录
cd/path 切换到指定目录
[root@wezzer ~]# cd ..
[root@wezzer /]# cd ~
[root@wezzer ~]# cd -
/
[root@wezzer /]# cd
[root@wezzer ~]#
ls 命令可查看linux文件夹包含的文件,还可查看文件权限,查看目录信息
[root@wezzer ~]# ls
anaconda-ks.cfg 公共 视频 文档 音乐
initial-setup-ks.cfg 模板 图片 下载 桌面
ls -a(-all) 显示所有文件(隐藏文件)
[root@wezzer ~]# ls -a
. .bash_profile .dbus .tcshrc 图片
.. .bashrc .esd_auth .viminfo 文档
anaconda-ks.cfg .cache .ICEauthority 公共 下载
.bash_history .config initial-setup-ks.cfg 模板 音乐
.bash_logout .cshrc .local 视频 桌面
ls -l 使用详细列表格式显示文件或目录的详细信息
[root@wezzer ~]# ls -l
总用量 8
-rw-------. 1 root root 1714 5月 8 00:24 anaconda-ks.cfg
-rw-r--r--. 1 root root 1762 5月 8 00:28 initial-setup-ks.cfg
drwxr-xr-x. 2 root root 6 5月 8 00:33 公共
drwxr-xr-x. 2 root root 6 5月 8 00:33 模板
drwxr-xr-x. 2 root root 6 5月 8 00:33 视频
drwxr-xr-x. 2 root root 6 5月 8 00:33 图片
drwxr-xr-x. 2 root root 6 5月 8 00:33 文档
drwxr-xr-x. 2 root root 6 5月 8 00:33 下载
drwxr-xr-x. 2 root root 6 5月 8 00:33 音乐
drwxr-xr-x. 2 root root 6 5月 8 00:33 桌面
ls -h(--human-readable) 改变格式显示文件大小格式1k1M等、常与其他选项搭配
[root@wezzer ~]# ls -lh
总用量 8.0K
-rw-------. 1 root root 1.7K 5月 8 00:24 anaconda-ks.cfg
-rw-r--r--. 1 root root 1.8K 5月 8 00:28 initial-setup-ks.cfg
drwxr-xr-x. 2 root root 6 5月 8 00:33 公共
drwxr-xr-x. 2 root root 6 5月 8 00:33 模板
drwxr-xr-x. 2 root root 6 5月 8 00:33 视频
drwxr-xr-x. 2 root root 6 5月 8 00:33 图片
drwxr-xr-x. 2 root root 6 5月 8 00:33 文档
drwxr-xr-x. 2 root root 6 5月 8 00:33 下载
drwxr-xr-x. 2 root root 6 5月 8 00:33 音乐
drwxr-xr-x. 2 root root 6 5月 8 00:33 桌面
ls -r(--reverse) 使用反序排列文件
[root@wezzer ~]# ls -r
桌面 下载 图片 模板 initial-setup-ks.cfg
音乐 文档 视频 公共 anaconda-ks.cfg
ls -R(--recursive) 递归列出目录及其子目录的文件
[root@wezzer ~]# ls -R
.:
anaconda-ks.cfg 公共 视频 文档 音乐
initial-setup-ks.cfg 模板 图片 下载 桌面
./公共:
./模板:
./视频:
./图片:
./文档:
./下载:
./音乐:
./桌面:
ls -t 按修改时间排序(新修改的在前)
[root@wezzer ~]# ls -t
公共 视频 文档 音乐 initial-setup-ks.cfg
模板 图片 下载 桌面 anaconda-ks.cfg
ls -S 按照文件大小排序
[root@wezzer ~]# ls -S
initial-setup-ks.cfg 公共 视频 文档 音乐
anaconda-ks.cfg 模板 图片 下载 桌面
ls -d 显示目录本身
[root@wezzer ~]# ls -d
.
ls -i 显示每个文件的inode号
[root@wezzer ~]# ls -i
100663362 anaconda-ks.cfg 3486 模板 68802906 文档 68802905 桌面
100663364 initial-setup-ks.cfg 34733400 视频 100663417 下载
34733399 公共
ls --color=auto 自动根据文件类型显示不同的颜色
[root@wezzer ~]# ls --color=auto
anaconda-ks.cfg 公共 视频 文档 音乐
initial-setup-ks.cfg 模板 图片 下载 桌面
cat 用于连接文件或标准输入并打印,或将几个文件连起来显示,可带配重定向符号使用(可查看具体内容)
[root@wezzer ~]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
cat -n 显示行号
[root@wezzer ~]# cat -n /etc/centos-release
1 CentOS Linux release 7.9.2009 (Core)
cat -e 在输出的行尾添加制表符和换行符$
[root@wezzer ~]# cat -e /etc/centos-release
CentOS Linux release 7.9.2009 (Core)$
正确重定向 (在当前目录,创建一个1.txt的文件内容为:以e开始到e结束中的内容)
[root@wezzer ~]# cat <> 1.txt
> 1
> 2
> 3
> e
将1.txt 和 2.txt 内容整合覆盖到 4.txt
[root@wezzer ~]# cat 1.txt 2.txt > 4.txt
将1.txt 和 3.txt 内容整合到 4.txt (在4.txt内容的基础再加上1.txt和3.txt)
[root@wezzer ~]# cat 1.txt 3.txt >> 4.txt
都看到这了,制作不易,能点个赞再走嘛