0

CentOS 文件管理(2)

 2 years ago
source link: https://blog.51cto.com/baicia/5141036
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

CentOS 文件管理(2)

原创

白菜素三鲜丶 2022-03-23 17:08:10 ©著作权

文章标签 bash 创建目录 目标路径 文章分类 虚拟化 云计算 阅读数490

文件管理命令

目录创建命令

mkdir # make directory
## 语法
mkdir   [OPTION]...        DIRECTORY...
创建目录 [选项,可以有多个]  目录名字,也可以有多个
## 选项
-p:递归创建目录,如果目录已存在,则不创建,并且不报错
-v:打印,显示,目录的创建过程
## 例子
## 在当前目录下,创建一个名字为acer的目录
[root@localhost ~]# mkdir acer
## 在指定的路径下,创建名字叫lenovo的目录
[root@localhost ~]# mkdir /opt/lenovo
## 创建多个目录
[root@localhost ~]# mkdir 1 2 3 4
[root@localhost ~]# mkdir /opt/acer /tmp/acer

## 报错的提示
如:[root@localhost ~]# mkdir /opt/dell/acer
mkdir: cannot create directory ‘/opt/dell/acer’: No such file or directory
#不能创建 '/opt/dell/acer'目录,原因,没有这样的文件或目录
使用mkdir创建目录,它的上一级目录必须存在,才能创建

如:[root@localhost ~]# mkdir acer
目录不能创建,'acer'文件已存在
mkdir: cannot create directory ‘acer’: File exists
## 序列用法
[root@localhost ~]# mkdir {1..10}
[root@localhost ~]# mkdir {a..z}
[root@localhost ~]# mkdir test{1,2} = mkdir {test1,test2}

##注意 在linux中,区分字母大小写
## 例子
[root@localhost ~]# mkdir abc
[root@localhost ~]# mkdir ABC
[root@localhost ~]# ls
abc  ABC  anaconda-ks.cfg  test

普通文件创建

touch # 只能创建出,可编辑的普通文件
## 语法
# 语法
touch     [OPTION]...    FILE...
touch命令   [选项]      普通文件的文件名,可以写多个
# touch创建文件,如果文件已存在,不报错,也不覆盖,只会修改文件的创建时间戳
## 例子
[root@localhost ~]# touch a b c
[root@localhost ~]# ll a b c
-rw-r--r--. 1 root root 0 Mar 21 21:54 a
-rw-r--r--. 1 root root 0 Mar 21 21:54 b
-rw-r--r--. 1 root root 0 Mar 21 21:54 c
[root@localhost ~]# touch a b c
[root@localhost ~]# ll a b c
-rw-r--r--. 1 root root 0 Mar 21 21:55 a
-rw-r--r--. 1 root root 0 Mar 21 21:55 b
-rw-r--r--. 1 root root 0 Mar 21 21:55 c
## 序列
[root@localhost ~]# touch {1..10}
[root@localhost ~]# touch /opt/acer /opt/dell /usr/src/acer
## 报错
[root@localhost ~]# touch /wsh/acer.txt
touch: cannot touch ‘/wsh/acer.txt’: No such file or directory
#touch想要创建文件,必须该文件的上级目录要存在

树状显示目录结构

tree
## 安装
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum -y install tree

## 语法
tree [option]... 路径
## 选项
-L:后面接数字,查看指定层级的目录
-d:只看所有的目录,不看普通文件
## 报错
[root@localhost ~]# tree
-bash: tree: command not found
## 以前没有安装过tree命令,tree 命令没有找到

-bash: /usr/bin/tree: No such file or directory
## 以前安装过tree命令,/usr/bin/tree 没有这样的文件或目录

移动(剪切)命令

mv # move
## 语法
mv [option]... source dest
mv [选项] 源文件... 目标路径
## 例子
root@localhost ~]# ls
acer  anaconda-ks.cfg  test
[root@localhost ~]# mv acer /opt/
[root@localhost ~]# ll /opt/
total 0
drwxr-xr-x. 2 root root 6 Mar 21 21:46 acer
[root@localhost ~]# ls
anaconda-ks.cfg  test

## 注意,目标路径,必须是一个目录,如果目标路径不存在,则是改名
##例子
[root@localhost opt]# ls
acer
[root@localhost opt]# mv acer  wsh
[root@localhost opt]# ls
wsh

 51CTO

  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK