您的位置:首页 > 其它

相对与绝对路径,创建删除目录文件,CD与RM命令

2017-12-18 19:54 477 查看

相对和绝对路径

1.所有的文件都有自己的路径,例如:

[root@weix-01 ~]# ls /etc/sysconfig/network-scripts/ifcfg-ens33
/etc/sysconfig/network-scripts/ifcfg-ens33

2.绝对路径:从根开始路径

[root@weix-01 ~]# ls /root/anaconda-ks.cfg
/root/anaconda-ks.cfg

3.相对路径:相对当前你所在位置的一个路径

[root@weix-01 ~]# ls anaconda-ks.cfg
anaconda-ks.cfg

CD命令

1.cd:change directory 切换目录
2.cd - :在当前目录与上一次所在目录之前切换:

[root@weix-01 ~]# cd /etc/sysconfig
[root@weix-01 sysconfig]# cd -
/root
[root@weix-01 ~]# pwd
/root
[root@weix-01 ~]# cd -
/etc/sysconfig
[root@weix-01 sysconfig]# pwd
/etc/sysconfig

3.cd命令不加后缀:回到你登录用户的家目录下面

[root@weix-01 sysconfig]# cd
[root@weix-01 ~]# pwd
/root

4.cd ~:和cd /root 一样

[root@weix-01 sysconfig]# cd /root
[root@weix-01 ~]# cd -
/etc/sysconfig
[root@weix-01 sysconfig]# cd ~
[root@weix-01 ~]#

5.cd..:切换到上一级目录

[root@weix-01 /]# cd /etc/sysconfig/network-scripts
[root@weix-01 network-scripts]# cd ..
[root@weix-01 sysconfig]# cd ..
[root@weix-01 etc]# cd ..

创建和删除目录

1.mkdir : make directory缩写,创建目录

[root@weix-01 /]# mkdir /tmp/weix01
[root@weix-01 /]# ls -ld !$
ls -ld /tmp/weix01
drwxr-xr-x. 2 root root 6 12月 18 16:07 /tmp/weix01
[root@weix-01 /]# date
2017年 12月 18日 星期一 16:08:22 CST

2.mkdir -p 可以级联创建

[root@weix-01 /]# mkdir -p /tmp/weix01/1/2/3
[root@weix-01 /]# ls -l /tmp/weix01
总用量 0
drwxr-xr-x. 3 root root 15 12月 18 17:01 1
[root@weix-01 /]# ls -l /tmp/weix01/1
总用量 0
drwxr-xr-x. 3 root root 15 12月 18 17:01 2
[root@weix-01 /]# ls -l /tmp/weix01/1/2
总用量 0
drwxr-xr-x. 2 root root 6 12月 18 17:01 3

3.mkdir -v:可视化创建

[root@weix-01 /]# mkdir -pv /tmp/weix01/2/3/4
mkdir: 已创建目录 "/tmp/weix01/2"
mkdir: 已创建目录 "/tmp/weix01/2/3"
mkdir: 已创建目录 "/tmp/weix01/2/3/4"

4.rmdir :remove directory 删除目录(非空目录)

[root@weix-01 /]# rmdir /tmp/weix01/1/2//3/4
[root@weix-01 /]# ls -lh /tmp/weix01/1/2/3
总用量 0

5.rmdir -p :可以级联删除一串空目录(基本不用,容易误删)

[root@weix-01 /]# tree /tmp/weix01
/tmp/weix01
├── 1
│   └── 2
│       └── 3
└── 2
└── 3
└── 4

6 directories, 0 files
[root@weix-01 /]# rmdir -p /tmp/weix01/1/2/3
rmdir: 删除目录 "/tmp/weix01" 失败: 目录非空
[root@weix-01 /]# tree /tmp/weix01
/tmp/weix01
└── 2
└── 3
└── 4

RM命令

1.rm :remove 删除文件或目录

[root@weix-01 /]# touch /tmp/weix01/2/3/4/1.txt
[root@weix-01 /]# ls !$
ls /tmp/weix01/2/3/4/1.txt
/tmp/weix01/2/3/4/1.txt
[root@weix-01 /]# rm !$
rm /tmp/weix01/2/3/4/1.txt
rm:是否删除普通空文件 "/tmp/weix01/2/3/4/1.txt"?y

2.rm -f : 强制删除,不用询问

[root@weix-01 /]# rm -f /tmp/weix01/2/3/4/1.txt
[root@weix-01 /]# !tree
tree /tmp/weix01
/tmp/weix01
└── 2
└── 3
└── 4

3.history命令:将历史命令列出

139  ls -lh /tmp/weix01/1/2/3
140  ls -lh /tmp/weix01/1/2/3/4
141  ls -lh /tmp/weix01
142  tree /tmp/weix01
143  yum install -y tree
144  tree /tmp/weix01
145  rmdir -p /tmp/weix01/1/2/3
146  tree /tmp/weix01
147  touch /tmp/weix01/2/3/4/1.txt
148  ls /tmp/weix01/2/3/4/1.txt
149  rm /tmp/weix01/2/3/4/1.txt
150  ls /tmp/weix01/2/3/4
151  touch /tmp/weix01/2/3/4/1.txt
152  rm -f /tmp/weix01/2/3/4/1.txt
153  tree /tmp/weix01
154  history

4.!tree: 执行历史命令里面最近的一次tree命令

[root@weix-01 /]# !tree
tree /tmp/weix01
/tmp/weix01
└── 2
└── 3
└── 4
3 directories, 0 files

5.rm -r :删除目录

[root@weix01 ~]# rm -r /tmp/weix01/2/3
rm:是否进入目录"/tmp/weix01/2/3"? y
rm:是否删除目录 "/tmp/weix01/2/3/4"?y
rm:是否删除目录 "/tmp/weix01/2/3"?y
[root@weix01 ~]# !tree
tree /tmp/weix01
/tmp/weix01
└── 2

1 directory, 0 files

6.rm -rf: 强制删除目录

[root@weix01 ~]# rm -rf /tmp/weix01/2

[root@weix01 ~]# rm -rfv /tmp/weix01/2/3
已删除"/tmp/weix01/2/3/1.txt"
已删除目录:"/tmp/weix01/2/3"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  创建删除 目录 cd
相关文章推荐