命令行管理文件
文件系统层次结构

Linux遵循开源协议,所以任何人都可以根据Linux的核心代码制作和发行版本。如果每个人都按自己的喜好,在/目录下创建目录、存放文件,将导致其他人无法快速使用他人的linux系统。为避免这样的情况,FHS就应运而生,对linux文件系统目录结构进行规范化。
FHS(Filesystem Hierarchy Standard)采用树形结构组织文件,定义了系统中每个区域的用途、所需要的最小构成的文件和目录,同时还给出了例外处理与矛盾处理。
FHS定义了两层规范:
- **定义了 / 下面的各个目录应该要放什么文件数据。**例如/etc应该要放置设置文件,/bin与/sbin则应该要放置可执行文件等等。
- **针对/usr及/var这两个目录的子目录来定义。**例如/var/log放置系统登录文件、/usr/share放置共享数据等等。
USR,Unix System Resource
| /usr | 系统安装的软件、共享的库。重要的子目录有:/usr/bin: 用户命令。/usr/sbin: 系统管理命令。 /usr/lib、/usr/lib64:应用程序可调用的通用库文件。 /usr/local: 本地自定义软件。 |
| /etc | 系统配置文件。 |
| /var | variable,系统可变数据,在系统启动之间保持永久性,如数据库、 缓存目录、日志文件、打印机后台处理文档和网站内容。 |
| /run | 自本次系统启动以来运行中的进程的运行数据,包括进程ID文件和锁定文件,等等。此目录中的内容在重启时重新创建。此目录合并了早期版本的Linux 中的/var/run和/var/lock。 |
| /home | 主目录是普通用户存储其个人数据和配置文件的位置。 每个用户有自己的位置,例如 /home/laoma。 |
| /root | 管理员root的主目录。 |
| /tmp | 供临时文件使用的全局可写空间。 10天内未访问、未更改或未修改的文件将自动从该目录中删除。 还有一个临时目录/var/tmp,该目录中的文件如果在30天内未曾访问、更改或修改过, 将被自动删除。 |
| /boot | 开机启动过程所需的文件。 |
| /dev | device,包含特殊的设备文件,供系统用于访问硬件。 |
文件路径导航
导航路径 cd 和 pwd
常见路径说明:
- 绝对路径:以根(/)开头的路径,用于指定文件的确切位置。
- 当前工作路径:当前所处的位置。
- 相对路径:不是以根(/)开头的路径,相对当前工作目录的路径。
#显示当前工作目录
[liulele@centos7 ~ 10:26:31]$ pwd
/home/liulele
#切换路径
[liulele@centos7 ~ 10:29:40]$ cd /usr/bin/
[liulele@centos7 bin 10:30:06]$ pwd
/usr/bin
#切换到其他目录
[liulele@centos7 bin 10:30:27]$ cd /usr/share/doc/
[liulele@centos7 doc 10:31:11]$ pwd
/usr/share/doc
#切换上一次所在的目录
[liulele@centos7 doc 13:26:20]$ cd –
[liulele@centos7 share 13:26:23]$ pwd
/usr/share
# 切换到家目录
[liulele@centos7 share 13:26:32]$ cd
#或者
[liulele@centos7 doc 13:27:16]$ cd ~
[liulele@centos7 ~ 13:27:21]$ pwd
/home/liulele
# 上一级目录(父目录),用..表示
[liulele@centos7 ~ 13:27:26]$ cd ..
[liulele@centos7 home 13:28:30]$ pwd
/home
# 当前目录用.表示,通常不写.
[liulele@centos7 ~ 13:29:48]$ file ./.bash_history
./.bash_history: UTF-8 Unicode text
[liulele@centos7 ~ 13:30:05]$ file .bash_history
.bash_history: UTF-8 Unicode text
ls命令
#可以ls –help 查看ls的用法
# -1(数字1)选项以单列格式展示
# 图形化界面,并且用户登录系统后才会有这些文件。
[liulele@centos7 ~ 17:51:39]$ ls -1
公共
模板
视频
图片
文档
下载
音乐
桌面
# -R 选项递归查看子目录中文件
[liulele@centos7 ~ 17:51:43]$ ls /etc/yum
fssnap.d pluginconf.d protected.d vars version-groups.conf
[liulele@centos7 ~ 17:52:05]$ ls -R /etc/yum
/etc/yum:
fssnap.d pluginconf.d protected.d vars version-groups.conf
/etc/yum/fssnap.d:
/etc/yum/pluginconf.d:
fastestmirror.conf langpacks.conf
/etc/yum/protected.d:
systemd.conf
/etc/yum/vars:
contentdir infra
# -l选项 长列表格式查看文件详细信息
[liulele@centos7 ~ 17:52:14]$ ls /etc/hosts
/etc/hosts
[liulele@centos7 ~ 17:52:51]$ ls -l /etc/hosts
-rw-r–r–. 1 root root 158 6月 7 2013 /etc/hosts
# 使用 -r 选项反向排序,按字母
#head查看目录的前10文件,默认
#|表示将前的命令执行的结果作为后边的条件
[liulele@centos7 ~ 17:54:06]$ ls -lr /tmp|head
总用量 12
-rw——-. 1 root root 0 7月 14 10:26 yum.log
drwx——. 2 root root 6 7月 14 10:38 vmware-root_805-4257200540
drwx——. 2 root root 6 7月 14 11:38 vmware-root_796-2991202916
drwx——. 2 root root 6 7月 15 08:51 vmware-root_779-4290232237
drwx——. 2 root root 6 7月 14 19:57 vmware-root_771-4256545187
drwx——. 2 root root 6 7月 15 08:58 vmware-root_733-4248680474
drwx——. 2 root root 6 7月 14 13:50 vmware-root_732-2999591876
drwx——. 2 liulele liulele 6 7月 14 16:45 tracker-extract-files.1000
drwx——. 2 root root 6 7月 14 14:56 tracker-extract-files.0
# 使用 -t 选项按时间排序(从新到旧)
#tail查看目录最后10个文件
[liulele@centos7 ~ 17:55:53]$ ls -lt /tmp|tail
-rw-r–r–. 1 root root 1148 7月 14 10:39 anaconda.log
-rw-r–r–. 1 root root 415 7月 14 10:39 ifcfg.log
-rw-r–r–. 1 root root 0 7月 14 10:38 sensitive-info.log
-rw-r–r–. 1 root root 0 7月 14 10:38 packaging.log
-rw-r–r–. 1 root root 0 7月 14 10:38 program.log
-rw-r–r–. 1 root root 0 7月 14 10:38 storage.log
drwx——. 2 root root 6 7月 14 10:38 vmware-root_805-4257200540
-rwx——. 1 root root 836 7月 14 10:38 ks-script-I0dl02
drwxr-xr-x. 2 root root 18 7月 14 10:29 hsperfdata_root
-rw——-. 1 root root 0 7月 14 10:26 yum.log
tree 命令
以树形格式查看目录结构
# 配置仓库
[liulele@centos7 ~ 17:57:06]$ curl -s -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[liulele@centos7 ~ 17:57:06]$ curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# 安装tree工具
[liulele@centos7 ~ 17:58:06]$ yum install -y tree
[liulele@centos7 ~ 17:59:15]$
[liulele@centos7 ~ 17:59:15]$ tree /etc/yum
/etc/yum
├── fssnap.d
├── pluginconf.d
│ ├── fastestmirror.conf
│ └── langpacks.conf
├── protected.d
│ └── systemd.conf
├── vars
│ ├── contentdir
│ └── infra
└── version-groups.conf
4 directories, 6 files
stat 命令
查看文件的元数据属性。
[liulele@centos7 ~ 18:02:55]$ ls /etc/yum
fssnap.d pluginconf.d protected.d vars version-groups.conf
[liulele@centos7 ~ 18:03:09]$ stat /etc/fstab
文件:"/etc/fstab"
大小:541 块:8 IO 块:4096 普通文件
设备:fd00h/64768dInode:67160130 硬链接:1
权限:(0644/-rw-r–r–) Uid:( 0/ root) Gid:( 0/ root)
环境:system_u:object_r:etc_t:s0
最近访问:2026-07-15 10:39:39.084791402 +0800
最近更改:2026-07-14 10:25:59.838010352 +0800
最近改动:2026-07-14 10:38:19.999574086 +0800
创建时间:-
touch 命令
[liulele@centos7 ~ 18:03:19]$ touch –help
用法:touch [选项]... 文件...
Update the access and modification times of each FILE to the current time.
A FILE argument that does not exist is created empty, unless -c or -h
is supplied.
A FILE argument string of – is handled specially and causes touch to
change the times of the file associated with standard output.
Mandatory arguments to long options are mandatory for short options too.
-a只更改访问时间
-c, –no-create不创建任何文件
-d, –date=字符串使用指定字符串表示时间而非当前时间
-f(忽略)
-h, –no-dereference会影响符号链接本身,而非符号链接所指示的目的地
(当系统支持更改符号链接的所有者时,此选项才有用)
-m只更改修改时间
-r, –reference=FILE use this file's times instead of current time
-t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time
–time=WORD change the specified time:
WORD is access, atime, or use: equivalent to -a
WORD is modify or mtime: equivalent to -m
–help显示此帮助信息并退出
–version显示版本信息并退出
请注意,-d 和-t 选项可接受不同的时间/日期格式。
# 更新现有文件时间戳:包括访问时间,更改时间和修改时间。
[liulele@centos7 ~ 18:17:21]$ ls -l test.txt
-rw-rw-r–. 1 liulele liulele 0 7月 15 18:17 test.txt
[liulele@centos7 ~ 18:17:34]$ touch test.txt
[liulele@centos7 ~ 18:17:41]$ ls -l test.txt
-rw-rw-r–. 1 liulele liulele 0 7月 15 18:17 test.txt
[liulele@centos7 ~ 18:17:43]$ date
2026年 07月 15日 星期三 18:18:15 CST
[liulele@centos7 ~ 18:18:15]$ stat test.txt
文件:"test.txt"
大小:0 块:0 IO 块:4096 普通空文件
设备:fd02h/64770dInode:75 硬链接:1
权限:(0664/-rw-rw-r–) Uid:( 1000/ liulele) Gid:( 1000/ liulele)
环境:unconfined_u:object_r:user_home_t:s0
最近访问:2026-07-15 18:17:41.789086101 +0800
最近更改:2026-07-15 18:17:41.789086101 +0800
最近改动:2026-07-15 18:17:41.789086101 +0800
创建时间:-
# 如果文件不存在,则创建文件
[liulele@centos7 ~ 18:18:28]$ ls test1.txt
ls: 无法访问test1.txt: 没有那个文件或目录
[liulele@centos7 ~ 18:20:19]$ touch test1.txt
[liulele@centos7 ~ 18:20:31]$ ls -l test1.txt
-rw-rw-r–. 1 liulele liulele 0 7月 15 18:20 test1.txt
# 使用-c选项时候,如果文件不存在,则不会创建文件。
[liulele@centos7 ~ 18:20:41]$ ls test2.txt
ls: 无法访问test2.txt: 没有那个文件或目录
[liulele@centos7 ~ 18:21:24]$ touch -c test2.txt
[liulele@centos7 ~ 18:21:37]$ ls test2.txt
ls: 无法访问test2.txt: 没有那个文件或目录
命令行管理文件
| 复制文件 | cp file1 file2 | cp file1 file2 file3 dir |
| 移动文件 | mv file1 file2 | mv file1 file2 file3 dir |
| 删除文件 | rm file1 | rm file1 file2 file3 |
| 创建目录 | mkdir dir | mkdir -p dir1/dir2/dir3 |
| 复制目录 | cp -r dir1 dir2 | cp -r dir1 dir2 dir3 dir4 |
| 移动目录 | mv dir1 dir2 | mv dir1 dir2 dir3 dir4 |
| 删除目录 | rm -r dir1 或 rmdir dir1 | rm -rf dir1 dir2 dir3 |
mkdir 命令
#创建目录
[liulele@centos7 ~ 18:23:01]$ mkdir lab
[liulele@centos7 ~ 18:23:07]$ ls
lab 公共 模板 视频 图片 文档 下载 音乐 桌面
# 多个目录创建
[liulele@centos7 ~ 18:23:12]$ mkdir lab1 lab2 lab3
[liulele@centos7 ~ 18:23:21]$ ls
lab lab1 lab2 lab3 公共 模板 视频 图片 文档 下载 音乐 桌面
# -p 选项级联创建目录
[liulele@centos7 ~ 18:23:22]$ mkdir d1/d2/d3
mkdir: 无法创建目录"d1/d2/d3": 没有那个文件或目录
[liulele@centos7 ~ 18:23:41]$ mkdir -p d1/d2/d3
[liulele@centos7 ~ 18:23:50]$ tree d1
d1
└── d2
└── d3
2 directories, 0 files
cp命令
复制文件
# 复制单个文件到目标位置
#/etc/hosts是绝对路径,.是表示当前目录下
[liulele@centos7 ~ 18:26:04]$ cd lab
[liulele@centos7 lab 18:26:12]$ ls
[liulele@centos7 lab 18:26:13]$ cp /etc/hosts .
[liulele@centos7 lab 18:26:31]$ ls
hosts
# 复制过来并且重命名
[liulele@centos7 lab 18:26:33]$ cp /etc/hosts hosts-1
[liulele@centos7 lab 18:27:33]$ ls
hosts hosts-1
# 当前目录下有同名称文件,不会提示直接覆盖
[liulele@centos7 lab 18:27:34]$ cp /etc/hosts ./hosts-1
# 通过 -i 选项,提示是否覆盖
[liulele@centos7 lab 18:28:15]$ cp -i /etc/hosts ./hosts-1
cp:是否覆盖"./hosts-1"? yes
# 复制多个文件,目标只能是目录
[liulele@centos7 lab 18:28:49]$ cp /etc/passwd /etc/hosts.allow ./hosts-all
cp: 目标"./hosts-all" 不是目录
[liulele@centos7 lab 18:31:00]$ cp /etc/passwd /etc/hosts.allow .
[liulele@centos7 lab 18:31:10]$ ls
hosts hosts-1 hosts.allow passwd
复制目录
# 使用 -r 选项复制目录
[liulele@centos7 lab 18:32:57]$ cp /etc/yum .
cp: 略过目录"/etc/yum"
[liulele@centos7 lab 18:33:02]$ cp -r /etc/yum .
[liulele@centos7 lab 18:33:12]$ ls
hosts hosts-1 hosts.allow passwd yum
# 复制过来,并使用新的名称
[liulele@centos7 lab 18:34:06]$ cp -r /etc/yum ./yum-1
[liulele@centos7 lab 18:34:28]$ ls
hosts hosts-1 hosts.allow passwd yum yum-1
# 当前目录下有同名称目录,则将源目录放到相同目录下面,而不是覆盖当前目录
[liulele@centos7 lab 18:35:53]$ ls yum
fssnap.d pluginconf.d protected.d vars version-groups.conf
[liulele@centos7 lab 18:35:56]$ cp -r /etc/yum ./yum
[liulele@centos7 lab 18:36:05]$ ls
hosts hosts-1 hosts.allow passwd yum yum-1
[liulele@centos7 lab 18:36:08]$ ls yum
fssnap.d pluginconf.d protected.d vars version-groups.conf yum
#用tree查看下结构
[liulele@centos7 lab 18:40:05]$ tree yum
yum
├── fssnap.d
├── pluginconf.d
│ ├── fastestmirror.conf
│ └── langpacks.conf
├── protected.d
│ └── systemd.conf
├── vars
│ ├── contentdir
│ └── infra
├── version-groups.conf
└── yum
├── fssnap.d
├── pluginconf.d
│ ├── fastestmirror.conf
│ └── langpacks.conf
├── protected.d
│ └── systemd.conf
├── vars
│ ├── contentdir
│ └── infra
└── version-groups.conf
9 directories, 12 files
# 复制多个目录,目标必须是已经存在的目录
[liulele@centos7 lab 18:44:28]$ cp -r /etc /home ./test
cp: 目标"./test" 不是目录
#因为我使用的是普通用户,没有这个权限
[liulele@centos7 lab 18:44:51]$ cp -r /etc /home .
cp: 无法打开"/etc/crypttab" 读取数据: 权限不够
cp: 无法访问"/etc/grub.d": 权限不够
cp: 无法访问"/etc/pki/CA/private": 权限不够
cp: 无法访问"/etc/pki/rsyslog": 权限不够
cp: 无法打开"/etc/ppp/peers/wvdial" 读取数据: 权限不够
#虽然有些文件需要有权限,但是还是复制过来了,只是目录下的内容不全
[liulele@centos7 lab 18:45:34]$ ls
etc home hosts hosts-1 hosts.allow passwd yum yum-1
[liulele@centos7 lab 18:47:29]$ ls etc home
mv命令
# 我们使用前面创建的lab1目录
#../是代表上一级目录的
[liulele@centos7 ~ 18:50:37]$ cd lab
[liulele@centos7 lab 18:50:39]$ mkdir ../lab1
[liulele@centos7 lab 18:51:04]$ ls -dl ../lab1
drwxrwxr-x. 2 liulele liulele 6 7月 15 18:50 ../lab1
# 移动单个文件
[liulele@centos7 lab 18:51:16]$ ls
etc home hosts hosts-1 hosts.allow passwd yum yum-1
[liulele@centos7 lab 18:53:04]$ mv hosts-1 ../lab1
[liulele@centos7 lab 18:53:22]$ ls
etc home hosts hosts.allow passwd yum yum-1
[liulele@centos7 lab 18:53:24]$ ls ../lab1
hosts-1
# 移动多个文件,目标位置只能是目录
[liulele@centos7 lab 18:54:13]$ mv hosts passwd ../lab1
[liulele@centos7 lab 18:54:53]$ ls ../lab1
hosts hosts-1 passwd
# 重命名文件
[liulele@centos7 lab 18:54:57]$ ls
etc home hosts.allow yum yum-1
[liulele@centos7 lab 18:55:30]$ mv hosts.allow hosts.allow-new
[liulele@centos7 lab 18:55:42]$ ls
etc home hosts.allow-new yum yum-1
# 移动单个目录
[liulele@centos7 lab 18:55:43]$ ls
etc home hosts.allow-new yum yum-1
[liulele@centos7 lab 18:56:09]$ mv home/ yum/ yum-1/ ../lab1
[liulele@centos7 lab 18:56:49]$ ls ../lab1
home hosts hosts-1 passwd yum yum-1
rmdir命令
#删除空文件
[liulele@centos7 lab 18:58:33]$ ls ../lab2
[liulele@centos7 lab 18:58:42]$ rmdir ../lab2
#要是删除有内容的文件会显示失败
[liulele@centos7 lab 19:00:12]$ ll
总用量 16
drwxr-xr-x. 139 liulele liulele 8192 7月 15 18:45 etc
-rw-r–r–. 1 liulele liulele 370 7月 15 18:31 hosts.allow-new
[liulele@centos7 lab 19:00:22]$ rmdir etc
rmdir: 删除 "etc" 失败: 目录非空
rm命令
[liulele@centos7 lab 19:00:40]$ cd ../lab1
[liulele@centos7 lab1 19:01:27]$ ls
home hosts hosts-1 passwd yum yum-1
# 删除文件
[liulele@centos7 lab1 19:01:29]$ ls
home hosts hosts-1 passwd yum yum-1
[liulele@centos7 lab1 19:02:32]$ rm hosts
[liulele@centos7 lab1 19:02:35]$ ls
home hosts-1 passwd yum yum-1
[liulele@centos7 lab1 19:02:38]$ rm hosts-1 passwd
[liulele@centos7 lab1 19:02:52]$ ls
home yum yum-1
# 强制删除具有写保护的文件,如果想要删除回答yes则会被删掉
[liulele@centos7 lab1 19:02:54]$ cp /etc/pki/ca-trust/extracted/java/cacerts .
[liulele@centos7 lab1 19:03:44]$ rm cacerts
rm:是否删除有写保护的普通文件 "cacerts"?yes
[liulele@centos7 lab1 19:03:53]$ ls cacerts
ls: 无法访问cacerts: 没有那个文件或目录
# 使用-f选项表示强制删除,直接删除
[liulele@centos7 lab1 19:02:54]$ cp /etc/pki/ca-trust/extracted/java/cacerts .
[liulele@centos7 lab1 19:03:44]$ rm -f cacerts
# -r选项递归删除目录
[liulele@centos7 lab1 19:04:00]$ rm -r yum
[liulele@centos7 lab1 19:05:41]$ ls
home yum-1
# 递归强制删除目录 -fr选项
[liulele@centos7 lab1 19:05:44]$ rm -rf home/
[liulele@centos7 lab1 19:06:25]$ ls
yum-1
# 清理实验环境
[liulele@centos7 lab1 19:06:56]$ cd ..
[liulele@centos7 ~ 19:06:58]$ ls
d1 lab lab1 lab3 公共 模板 视频 图片 文档 下载 音乐 桌面
[liulele@centos7 ~ 19:06:59]$ rm -rf d1/ lab lab1 lab3
[liulele@centos7 ~ 19:07:41]$ ls
公共 模板 视频 图片 文档 下载 音乐 桌面
软连接
soft link,也成为 symbolic link(符号链接)。
示例:window中快捷方式

[liulele@centos7 ~ 19:20:56]$ ls -dl /bin
lrwxrwxrwx. 1 root root 7 7月 14 10:26 /bin –> usr/bin
# 创建软连接
[liulele@centos7 ~ 19:24:33]$ ln -s /var/tmp mytmp
[liulele@centos7 ~ 19:24:45]$ ls -l mytmp
lrwxrwxrwx. 1 liulele liulele 8 7月 15 19:24 mytmp –> /var/tmp
[liulele@centos7 ~ 19:24:58]$ ls mytmp/
abrt
myfile
systemd-private-1d32be89f0a54fb4b4c3f41415d5376c-bolt.service-Y3ven2
systemd-private-1d32be89f0a54fb4b4c3f41415d5376c-chronyd.service-EEz7Ug
systemd-private-1d32be89f0a54fb4b4c3f41415d5376c-colord.service-wrkJoG
systemd-private-1d32be89f0a54fb4b4c3f41415d5376c-cups.service-LVrseu
systemd-private-1d32be89f0a54fb4b4c3f41415d5376c-fwupd.service-kqbQDF
systemd-private-1d32be89f0a54fb4b4c3f41415d5376c-rtkit-daemon.service-j3am5g
systemd-private-237c7c5504df4ffa9ad11a5dbb37c526-bolt.service-t3XZbd
systemd-private-237c7c5504df4ffa9ad11a5dbb37c526-chronyd.service-1GRri5
systemd-private-237c7c5504df4ffa9ad11a5dbb37c526-colord.service-26okAV
systemd-private-237c7c5504df4ffa9ad11a5dbb37c526-cups.service-IQ3KDm
systemd-private-237c7c5504df4ffa9ad11a5dbb37c526-fwupd.service-4TiJAv
systemd-private-237c7c5504df4ffa9ad11a5dbb37c526-rtkit-daemon.service-T0Wdt4
systemd-private-3d53bcea2f8f470cb79e72ce9da1e174-bolt.service-wydV3a
systemd-private-3d53bcea2f8f470cb79e72ce9da1e174-chronyd.service-Kg8Go5
systemd-private-3d53bcea2f8f470cb79e72ce9da1e174-colord.service-3jeauL
systemd-private-3d53bcea2f8f470cb79e72ce9da1e174-cups.service-Uzgnz5
systemd-private-3d53bcea2f8f470cb79e72ce9da1e174-rtkit-daemon.service-Qr7z3b
yum-liulele-38vTaC
[liulele@centos7 ~ 19:25:39]$ ls /var/tmp
abrt
myfile
systemd-private-1d32be89f0a54fb4b4c3f41415d5376c-bolt.service-Y3ven2
systemd-private-1d32be89f0a54fb4b4c3f41415d5376c-chronyd.service-EEz7Ug
systemd-private-1d32be89f0a54fb4b4c3f41415d5376c-colord.service-wrkJoG
systemd-private-1d32be89f0a54fb4b4c3f41415d5376c-cups.service-LVrseu
systemd-private-1d32be89f0a54fb4b4c3f41415d5376c-fwupd.service-kqbQDF
systemd-private-1d32be89f0a54fb4b4c3f41415d5376c-rtkit-daemon.service-j3am5g
systemd-private-237c7c5504df4ffa9ad11a5dbb37c526-bolt.service-t3XZbd
systemd-private-237c7c5504df4ffa9ad11a5dbb37c526-chronyd.service-1GRri5
systemd-private-237c7c5504df4ffa9ad11a5dbb37c526-colord.service-26okAV
systemd-private-237c7c5504df4ffa9ad11a5dbb37c526-cups.service-IQ3KDm
systemd-private-237c7c5504df4ffa9ad11a5dbb37c526-fwupd.service-4TiJAv
systemd-private-237c7c5504df4ffa9ad11a5dbb37c526-rtkit-daemon.service-T0Wdt4
systemd-private-3d53bcea2f8f470cb79e72ce9da1e174-bolt.service-wydV3a
systemd-private-3d53bcea2f8f470cb79e72ce9da1e174-chronyd.service-Kg8Go5
systemd-private-3d53bcea2f8f470cb79e72ce9da1e174-colord.service-3jeauL
systemd-private-3d53bcea2f8f470cb79e72ce9da1e174-cups.service-Uzgnz5
systemd-private-3d53bcea2f8f470cb79e72ce9da1e174-rtkit-daemon.service-Qr7z3b
yum-liulele-38vTaC
#如果再软连接下创建文件,源文件目录下也会出现文件
[liulele@centos7 ~ 19:25:45]$ touch mytmp/myfile
[liulele@centos7 ~ 19:26:39]$ ls /var/tmp/myfile
/var/tmp/myfile
#删除软连接
#注意:这里一定是mytmp而不是mytmp/,如果试mytmp/将会把源文件/var/tmp目录删除
#-f强制删除
[liulele@centos7 ~ 19:27:43]$ rm -rf mytmp
硬连接
**硬链接就是一个普通文件。**相当于,可以通过多个文件名访问同一个数据块。任何一个文件发生的变化,其他文件也跟着变。
[liulele@centos7 ~ 19:27:56]$ cp /etc/hosts ./hosts-1
#创建硬链接
[liulele@centos7 ~ 19:30:28]$ ln hosts-1 hosts-2
[liulele@centos7 ~ 19:30:38]$ ls -l hosts-1 hosts-2
-rw-r–r–. 2 liulele liulele 158 7月 15 19:30 hosts-1
-rw-r–r–. 2 liulele liulele 158 7月 15 19:30 hosts-2
# 两个文件的inode是相同的
[liulele@centos7 ~ 19:31:56]$ ls -il hosts-1 hosts-2
75 -rw-r–r–. 2 liulele liulele 158 7月 15 19:30 hosts-1
75 -rw-r–r–. 2 liulele liulele 158 7月 15 19:30 hosts-2
# 更新hosts-1时间,hosts-2也跟着一起变动
[liulele@centos7 ~ 19:32:02]$ touch hosts-1
[liulele@centos7 ~ 19:33:28]$ ls -l hosts-1 hosts-2
-rw-r–r–. 2 liulele liulele 158 7月 15 19:33 hosts-1
-rw-r–r–. 2 liulele liulele 158 7月 15 19:33 hosts-2
# 更新hosts-1文件内容,hosts-2也跟着一起变动
#echo 'abc' >> hosts-1 是将abc追加到hosts-1文件内容中
[liulele@centos7 ~ 19:33:40]$ cat hosts-1
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[liulele@centos7 ~ 19:35:10]$ echo 'abc' >> hosts-1
[liulele@centos7 ~ 19:35:26]$ cat hosts-1
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
abc
[liulele@centos7 ~ 19:35:30]$ cat hosts-2
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
abc
练习(第一种做法)
在用户的主目录中,创建三个子目录:music pictures videos。
[liulele@centos7 ~ 14:09:11]$ mkdir music pictures videos
[liulele@centos7 ~ 14:09:11]$ ls -d music pictures videos
music pictures videos
在用户的主目录中:
创建六个文件,并以 songX.mp3 形式取名。
创建六个文件,并以 snapX.jpg 形式取名。
创建六个文件,并以 filmX.avi 形式取名。
在每一组文件中,将 X 替换为数字 1 到 6 。
[liulele@centos7 ~ 14:20:14]$ touch song1.mp3 song2.mp3 song3.mp3 song4.mp3 song5.mp3 song6.mp3
[liulele@centos7 ~ 14:20:43]$ touch snap1.jpg snap2.jpg snap3.jpg snap4.jpg snap5.jpg snap6.jpg
[liulele@centos7 ~ 14:21:35]$ touch fil1.avi fil2.avi fil3.avi fil4.avi fil5.avi fil6.avi
[liulele@centos7 ~ 14:21:55]$ ll
总用量 0
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:21 fil1.avi
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:21 fil2.avi
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:21 fil3.avi
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:21 fil4.avi
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:21 fil5.avi
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:21 fil6.avi
drwxrwxr-x. 2 liulele liulele 6 7月 15 14:09 music
drwxrwxr-x. 2 liulele liulele 6 7月 15 14:09 pictures
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:21 snap1.jpg
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:21 snap2.jpg
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:21 snap3.jpg
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:21 snap4.jpg
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:21 snap5.jpg
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:21 snap6.jpg
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:20 song1.mp3
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:20 song2.mp3
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:20 song3.mp3
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:20 song4.mp3
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:20 song5.mp3
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:20 song6.mp3
drwxrwxr-x. 2 liulele liulele 6 7月 15 14:09 videos
将 songX.mp3 所有文件移动到 Music 目录。
[liulele@centos7 ~ 14:21:59]$ mv song* music
[liulele@centos7 ~ 14:39:51]$ ls music/
song1.mp3 song2.mp3 song3.mp3 song4.mp3 song5.mp3 song6.mp3
将 snapX.jpg 所有文件移动到 Pictures 目录。
[liulele@centos7 ~ 14:22:15]$ mv snap* pictures
[liulele@centos7 ~ 14:40:39]$ ls pictures/
snap1.jpg snap2.jpg snap3.jpg snap4.jpg snap5.jpg snap6.jpg
[liulele@centos7 ~ 14:22:28]$ mv fil* videos
[liulele@centos7 ~ 14:40:57]$ ls videos/
fil1.avi fil2.avi fil3.avi fil4.avi fil5.avi fil6.avi
在用户的主目录中,创建三个子目录:friends、family 和 work。
将所有序号是1和2的文件复制到 friends 目录。
将所有序号是3和4的文件复制到 family 目录。
将所有序号是5和6的文件复制到 work 目录。
[liulele@centos7 ~ 14:22:40]$ mkdir friends family work
[liulele@centos7 ~ 14:41:13]$ ls -d friends family work
family friends work
[liulele@centos7 ~ 14:46:33]$ cp music/song1.mp3 music/song2.mp3 pictures/snap1.jpg pictures/snap2.jpg videos/fil1.avi videos/fil2.avi ./friends
[liulele@centos7 ~ 14:46:45]$ ls friends/
fil1.avi fil2.avi snap1.jpg snap2.jpg song1.mp3 song2.mp3
[liulele@centos7 ~ 14:48:02]$ cp music/song3.mp3 music/song4.mp3 pictures/snap3.jpg pictures/snap4.jpg videos/fil3.avi videos/fil4.avi family/
[liulele@centos7 ~ 14:49:12]$ ls family/
fil3.avi fil4.avi snap3.jpg snap4.jpg song3.mp3 song4.mp3
[liulele@centos7 ~ 14:49:17]$ cp music/song5.mp3 music/song6.mp3 pictures/snap5.jpg pictures/snap6.jpg videos/fil5.avi videos/fil6.avi work/
[liulele@centos7 ~ 14:50:14]$ ls work/
fil5.avi fil6.avi snap5.jpg snap6.jpg song5.mp3 song6.mp3
复制 family 和 friends 目录到/tmp中。
[liulele@centos7 ~ 14:51:44]$ cp -r family/ friends/ /tmp
[liulele@centos7 ~ 14:52:26]$ ls /tmp
anaconda.log
family
friends
删除 family 和 friends 目录。
[liulele@centos7 ~ 14:52:30]$ rm -r /tmp/friends/ /tmp/family/
[liulele@centos7 ~ 14:53:59]$ ls /tmp
anaconda.log
删除 work 目录中所有文件,然后再删除 work 目录。
[liulele@centos7 ~ 14:54:02]$ cd work/
[liulele@centos7 work 14:55:24]$ ll
总用量 0
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:50 fil5.avi
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:50 fil6.avi
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:50 snap5.jpg
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:50 snap6.jpg
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:50 song5.mp3
-rw-rw-r–. 1 liulele liulele 0 7月 15 14:50 song6.mp3
[liulele@centos7 work 14:55:25]$ rm -rf *
[liulele@centos7 work 14:55:51]$ ll
总用量 0
[liulele@centos7 work 14:55:52]$ cd ..
[liulele@centos7 ~ 14:56:37]$ rmdir work/
在家目录下创建mytmp软连接指向/var/tmp,并验证。
[liulele@centos7 ~ 14:57:32]$ ln -s /var/tmp mytmp
#这里一定不要ls -l mytmp/ ,因为加/ 表示显示/var/tmp下的所有的文件
[liulele@centos7 ~ 14:58:57]$ ls -l mytmp
lrwxrwxrwx. 1 liulele liulele 8 7月 15 14:57 mytmp –> /var/tmp
删除以上步骤中创建的所有文件和目录。
#-r 删除目录 -f强制删除
#如果不加-f无法删除mytmp的软连接
#mytmp一定不要加mytmp/,要不然就会将源文件/var/tmp删除
[liulele@centos7 ~ 15:01:16]$ rm -rf family/ friends/ mytmp music/ pictures/ videos/
shell 扩展匹配文件
| * | 由零个或更多字符组成的任何字符串。单独*不匹配隐藏文件。 |
| ? | 任何一个字符。 |
| [abc…] | 位于两个方括号之间中的任何一个字符。 |
| [**^abc…]或[!**abc…] | 不在括起的类中的任何一个字符。 |
| ~ | 当前用户的主目录。 |
| ~username | username用户的主目录。 |
| [[:alpha:]] | 任何字母字符,相当于[a-Z]。 |
| [[:lower:]] | 任何小写字符。 |
| [[:upper:]] | 任何大写字符。 |
| [[:alnum:]] | 任何字母字符或数字,相当于[a-Z0-9]。 |
| [[:punct:]] | 除空格和字母数字以外的任何可打印字符。 |
| [[:digit:]]或[0-9] | 从 0 到 9 的任何单个数字。 |
| [[:space:]] | 任何一个空白字符。这可能包括制表符、 换行符、回车符、 换页符或空格。 |
| {…} | 匹配列表。 |
*示例
匹配由零个或更多字符组成的任何字符串。单独*不匹配隐藏文件。
# 匹配/etc目录下所有ho开头的文件
[liulele@centos7 ~ 15:16:03]$ ls /etc/ho*
/etc/host.conf /etc/hostname /etc/hosts /etc/hosts.allow /etc/hosts.deny
# 将/etc目录下所有ho开头的文件复制到/tmp
[liulele@centos7 ~ 15:29:41]$ cp /etc/ho* /tmp
[liulele@centos7 ~ 15:29:48]$ ls /tmp/ho*
/tmp/host.conf /tmp/hostname /tmp/hosts /tmp/hosts.allow /tmp/hosts.deny
# 删除/tmp目录下所有ho开头的文件
[liulele@centos7 ~ 15:29:55]$ rm /tmp/ho*
[liulele@centos7 ~ 15:30:39]$ ls /tmp/ho*
ls: 无法访问/tmp/ho*: 没有那个文件或目录
# *不匹配隐藏文件
[liulele@centos7 ~ 15:30:39]ls *
ls: 无法访问*: 没有那个文件或目录
# 如果匹配隐藏文件,使用以下命令
[liulele@centos7 ~ 15:31:11]$ ls -d .*
. .bash_history .bash_profile .cache .dbus .ICEauthority .local .Xauthority
.. .bash_logout .bashrc .config .esd_auth .lesshst .mozilla
? 示例
匹配任何一个字符
# 准备文件
[liulele@centos7 ~ 15:31:40]$ touch file-1 file-2 file-a file-a1 file-a2 file-ab file-b
[liulele@centos7 ~ 15:32:32]$ ls file-*
file-1 file-2 file-a file-a1 file-a2 file-ab file-b
# 查看文件名称是 file- 后跟1个字母的文件
[liulele@centos7 ~ 15:32:40]$ ls file-?
file-1 file-2 file-a file-b
# 查看文件名称是 file- 后跟2个字母的文件
[liulele@centos7 ~ 15:32:51]$ ls file-??
file-a1 file-a2 file-ab
# 查看文件名称是 file- 后跟3个字母的文件
[liulele@centos7 ~ 15:33:01]$ ls file-???
ls: 无法访问file-???: 没有那个文件或目录
[] 示例
匹配位于两个方括号之间中的任何一个字符。
[liulele@centos7 ~ 15:33:10]$ ls file-?
file-1 file-2 file-a file-b
[liulele@centos7 ~ 15:33:43]$ ls file-[abc]
file-a file-b
[liulele@centos7 ~ 15:33:54]$ ls file-[12]
file-1 file-2
[liulele@centos7 ~ 15:34:00]$ ls file-[^12]
file-a file-b
集合示例
# 准备文件
[liulele@centos7 ~ 15:34:05]$ touch file-9 file-A file-Z file-z
# 匹配所有数字
[liulele@centos7 ~ 15:34:26]$ ls file-[0-9]
file-1 file-2 file-9
[liulele@centos7 ~ 15:34:35]$ ls file-[[:digit:]]
file-1 file-2 file-9
# 匹配所有大写字母
[liulele@centos7 ~ 15:34:59]$ ls file-[[:upper:]]
file-A file-Z
# 匹配所有小写字母
[liulele@centos7 ~ 15:35:11]$ ls file-[[:lower:]]
file-a file-b file
# 匹配所有字母
[liulele@centos7 ~ 15:35:18]$ ls file-[a-Z]
file-a file-A file-b file-z file-Z
[liulele@centos7 ~ 15:35:45]$ ls file-[[:alpha:]]
file-a file-A file-b file-z file-Z
# 匹配所有字母和数字
[liulele@centos7 ~ 15:35:28]$ ls file-[[:alnum:]]
file-1 file-2 file-9 file-a file-A file-b file-z file-Z
~ 示例
匹配用户家目录。
[liulele@centos7 ~ 15:40:35]$ echo ~
/home/liulele
[liulele@centos7 ~ 15:41:30]$ cd ~
[liulele@centos7 ~ 15:41:38]$ pwd
/home/liulele
[liulele@centos7 ~ 15:41:40]$ echo ~root
/root
[liulele@centos7 ~ 15:41:47]$ cd ~root
-bash: cd: /root: 权限不够
{} 示例
[liulele@centos7 ~ 15:41:53]$ ls file-[abc]
file-a file-b
[liulele@centos7 ~ 15:43:39]$ ls file-{a,b,c}
ls: 无法访问file-c: 没有那个文件或目录
file-a file-b
# 相当于下面命令
[liulele@centos7 ~ 15:43:39]$ ls file-a file-b file-c
ls: 无法访问file-c: 没有那个文件或目录
file-a file-b
# {1..5}表达一个范围
[liulele@centos7 ~ 15:43:55]$ ls file-{1..5}
ls: 无法访问file-3: 没有那个文件或目录
ls: 无法访问file-4: 没有那个文件或目录
ls: 无法访问file-5: 没有那个文件或目录
file-1 file-2
括:[]和{}用法的区别
#touch file-[1-3] file-{1-3}
#目录下显示没有file-[1-3],也就是没有file-1,file-2,file-3文件
[liulele@centos7 ~ 16:34:19]$ ls file-[1-3]
ls: 无法访问file-[1-3]: 没有那个文件或目录
#这里touch创建file-[1-3],会把file-[1-3]看成一个整体
[liulele@centos7 ~ 16:34:31]$ touch file-[1-3]
#结果创建成file-[1-3]
[liulele@centos7 ~ 16:34:40]$ ls
file-[1-3] file-a file-a1 file-ab file-z
file-9 file-A file-a2 file-b file-Z
#删除file-[1-3]文件
[liulele@centos7 ~ 16:34:41]$ rm file-[1-3]
#如果先建立file-1的文件,再touch file-[1-3]
[liulele@centos7 ~ 16:34:57]$ touch file-1
[liulele@centos7 ~ 16:35:08]$ touch file-[1-3]
#只会匹配file-1,文件不会创建file-1.file-3
[liulele@centos7 ~ 16:35:17]$ ls
file-1 file-a file-a1 file-ab file-z
file-9 file-A file-a2 file-b file-Z
#删除file-1,继续实验
[liulele@centos7 ~ 16:35:18]$ rm file-1
#用{}继续创建
[liulele@centos7 ~ 16:35:30]$ touch file-{1..3}
#就会显示file-1,file-2,file-3
[liulele@centos7 ~ 16:35:43]$ ll
file-1 file-3 file-a file-a1 file-ab file-z
file-2 file-9 file-A file-a2 file-b file-Z
#[]不会创建file-4
[liulele@centos7 ~ 16:37:57]$ touch file-[1-4]
[liulele@centos7 ~ 16:37:57]$ll
file-1 file-3 file-a file-a1 file-ab file-z
file-2 file-9 file-A file-a2 file-b file-Z
#{}会创建file-4
[liulele@centos7 ~ 16:38:16]$ touch file-{1..4}
file-1 file-3 file-a file-a1 file-ab file-z
file-2 file-9 file-A file-a2 file-b file-Z
file-4
[liulele@centos7 ~ 16:41:00]$ ls /etc/{hosts,hosts.allow}
/etc/hosts /etc/hosts.allow
[liulele@centos7 ~ 16:41:07]$ #cp file-A file-A.bak
[liulele@centos7 ~ 16:41:34]$ echo cp file-{A,A.bak}
cp file-A file-A.bak
[liulele@centos7 ~ 16:41:54]$ echo cp file-A{,.bak}
cp file-A file-A.bak
练习(第二种做法)
使用shell扩展匹配,完成以下练习。
在用户的主目录中,创建三个子目录:Music、Pictures 和 Videos。
[liulele@centos7 ~ 15:50:53]$ mkdir music pictures videos
[liulele@centos7 ~ 15:51:24]$ ls -d music pictures videos
music pictures videos
在用户的主目录中:
创建六个文件,并以 songX.mp3 形式取名。
创建六个文件,并以 snapX.jpg 形式取名。
创建六个文件,并以 filmX.avi 形式取名。
在每一组文件中,将 X 替换为数字 1 到 6 。
#这里不能使用touch song[1-6],如果使用结果是:song[1-6].mp3文件
[liulele@centos7 ~ 15:52:49]$ touch song{1..6}.mp3
[liulele@centos7 ~ 15:55:21]$ touch snap{1..6}.jpg
[liulele@centos7 ~ 15:55:33]$ touch fil{1..6}.avi
[liulele@centos7 ~ 15:55:42]$ ls
将 songX.mp3 所有文件移动到 Music 目录。
将 snapX.jpg 所有文件移动到 Pictures 目录。
将 filmX.avi 所有文件移动到 Videos 目录。
[liulele@centos7 ~ 15:57:19]$ mv song* music/
[liulele@centos7 ~ 15:59:17]$ mv snap* pictures/
[liulele@centos7 ~ 16:00:50]$ mv fil* videos/
[liulele@centos7 ~ 16:01:12]$ ls music/ pictures/ videos/
music/:
song1.mp3 song2.mp3 song3.mp3 song4.mp3 song5.mp3 song6.mp3
pictures/:
snap1.jpg snap2.jpg snap3.jpg snap4.jpg snap5.jpg snap6.jpg
videos/:
fil1.avi fil2.avi fil3.avi fil4.avi fil5.avi fil6.avi
在用户的主目录中,创建三个子目录:friends、family 和 work。
[liulele@centos7 ~ 15:55:48]$ mkdir friends family work
[liulele@centos7 ~ 15:57:02]$ ls -d friends family work
family friends work
将所有序号是1和2的文件复制到 friends 目录。
将所有序号是3和4的文件复制到 family 目录。
将所有序号是5和6的文件复制到 work 目录。
#第一个*代表music pictures videos目录,/*代表目录下song文件,最后的*表示song1后所有的内容
[liulele@centos7 ~ 16:07:58]$ cp */*[1-2]* friends/
#在song3.mp3最后边有3,如果只是用*/*[3-4]*的话,会显示所有带mp3的文件
#*/*[3-4]?*,这里的加?是表示强制要求 3/4 后面必须还有 1 个字符。这样就可将song3.mp3筛选出来
[liulele@centos7 ~ 16:09:02]$ cp */*[3-4]?* family/
[liulele@centos7 ~ 16:09:43]$ cp */*[5-6]?* work/
[liulele@centos7 ~ 16:10:02]$ ls friends/ family/ work/
family/:
fil3.avi fil4.avi snap3.jpg snap4.jpg song3.mp3 song4.mp3
friends/:
fil1.avi fil2.avi snap1.jpg snap2.jpg song1.mp3 song2.mp3
work/:
fil5.avi fil6.avi snap5.jpg snap6.jpg song5.mp3 song6.mp3
复制 family 和 friends 目录到/tmp中。
[liulele@centos7 ~ 16:01:31]$ cp -r family/ friends/ /tmp
[liulele@centos7 ~ 16:02:16]$ ls /tmp
anaconda.log
family
friends
删除 family 和 friends 目录。
[liulele@centos7 ~ 16:04:05]$ rm -r /tmp/{family,friends}
删除 work 目录中所有文件,然后在删除 work 目录。
[liulele@centos7 ~ 16:11:42]$ cd work/
[liulele@centos7 work 16:11:47]$ rm -r *
[liulele@centos7 work 16:11:53]$ ls
在家目录下创建 mytmp 软连接指向 /var/tmp,并验证。
#这里一定不要ls -l mytmp/ ,因为加/ 表示显示/var/tmp下的所有的文件
[liulele@centos7 ~ 16:12:07]$ ln -s /var/tmp mytmp
[liulele@centos7 ~ 16:12:24]$ ls -dl mytmp
lrwxrwxrwx. 1 liulele liulele 8 7月 15 16:12 mytmp –> /var/tmp
删除以上步骤中创建的所有文件和目录。
#-r 删除目录 -f强制删除
#如果不加-f无法删除mytmp的软连接
#mytmp一定不要加mytmp/,要不然就会将源文件/var/tmp删除
[liulele@centos7 ~ 16:12:50]$rm -rf mytmp
#删除a-Z开头文件
[liulele@centos7 ~ 16:12:50]$ rm -rf [a-Z]*
song1.mp3 song2.mp3
work/:
fil5.avi fil6.avi snap5.jpg snap6.jpg song5.mp3 song6.mp3
1. 复制 family 和 friends 目录到/tmp中。
~~~bash
[liulele@centos7 ~ 16:01:31]$ cp -r family/ friends/ /tmp
[liulele@centos7 ~ 16:02:16]$ ls /tmp
anaconda.log
family
friends
删除 family 和 friends 目录。
[liulele@centos7 ~ 16:04:05]$ rm -r /tmp/{family,friends}
删除 work 目录中所有文件,然后在删除 work 目录。
[liulele@centos7 ~ 16:11:42]$ cd work/
[liulele@centos7 work 16:11:47]$ rm -r *
[liulele@centos7 work 16:11:53]$ ls
在家目录下创建 mytmp 软连接指向 /var/tmp,并验证。
#这里一定不要ls -l mytmp/ ,因为加/ 表示显示/var/tmp下的所有的文件
[liulele@centos7 ~ 16:12:07]$ ln -s /var/tmp mytmp
[liulele@centos7 ~ 16:12:24]$ ls -dl mytmp
lrwxrwxrwx. 1 liulele liulele 8 7月 15 16:12 mytmp –> /var/tmp
删除以上步骤中创建的所有文件和目录。
#-r 删除目录 -f强制删除
#如果不加-f无法删除mytmp的软连接
#mytmp一定不要加mytmp/,要不然就会将源文件/var/tmp删除
[liulele@centos7 ~ 16:12:50]$rm -rf mytmp
#删除a-Z开头文件
[liulele@centos7 ~ 16:12:50]$ rm -rf [a-Z]*



