一、相对路径与绝对路径

1.绝对路径:从根目录写起,想去哪个目录下,要写全所有要经过的路径。

[root@localhost ~]# cd /etc/init.d/
[root@localhost init.d]# cd /usr/local/mysql/

2.相对路径:从当前目录进入到另一个目录,不从根目录写起。例如从当前目录进入 data目录。

[root@localhost mysql]# cd data/
[root@localhost data]# ls
auto.cnf ibdata1 ibtmp1 mysql
db1 ib_logfile0 localhost.localdomain.err performance_schema
ib_buffer_pool ib_logfile1 localhost.localdomain.pid sys

二、cd 命令

1.cd 命令用来改变目录,使用户进入自己想要去的目录下。cd 目录路径 ,例如要去 home下。

[root@localhost ~]# cd /home/mysql/
[root@localhost mysql]# pwd
/home/mysql

2.cd 后只能跟目录,跟文件会报错。

[root@localhost ~]# cd my.cnf
-bash: cd: my.cnf: 不是目录

3. cd .  和cd ..

cd . 表示当前路径,

[root@localhost tmp]# cd .
[root@localhost tmp]# pwd
/tmp

cd .. 表示上一级目录

[root@localhost tmp]# cd ..
[root@localhost /]# pwd
/

三、mkdir  命令

1. mkdir 用来创建目录。 mkdir  目录名

 

[root@localhost ~]# mkdir dir
[root@localhost ~]# ls

dir newdir rsync test1 模板 文档

2.mkdir 不能直接创建子目录,加 -p 选项才能创建子目录。

[root@localhost ~]# mkdir dir/12/13
mkdir: 无法创建目录"dir/12/13": 没有那个文件或目录

root@localhost ~]# mkdir -p dir/12/13
[root@localhost ~]# cd dir/12/13/
[root@localhost 13]# pwd
/root/dir/12/13

四、rmdir 命令

1.删除命令,只能删除空目录,文件也无法删除

[root@localhost dir]# ls
11 1.txt
[root@localhost dir]# cd ..
[root@localhost ~]# rmdir dir
rmdir: 删除 "dir" 失败: 目录非空

[root@localhost dir]# rmdir 1.txt
rmdir: 删除 "1.txt" 失败: 不是目录

[root@localhost ~]# mkdir dir1
[root@localhost ~]# rmdir dir1

五、rm 命令

1.也是删除命令,功能较强大。 rm  -r 目录  -r 删除目录或文件,可删除非空目录,也可一次性删除多级目录。

 

[root@localhost dir]# ls
1.txt dir2
[root@localhost dir]# cd dir2
[root@localhost dir2]# mkdir dir3
[root@localhost dir2]# ls
dir3
[root@localhost dir2]# cd ..
[root@localhost dir]# rm -r dir2
[root@localhost dir]# ls
1.txt

2.-f  强制删除,删除一个不存在的目录或文件时,不会报错,如果存在,则会报错,需要加 -r 选项。

[root@localhost dir]# mkdir dir1
[root@localhost dir]# ls
1.txt dir1
[root@localhost dir]# rm -f dir2
[root@localhost dir]# rm -f dir1
rm: 无法删除"dir1": 是一个目录
[root@localhost dir]# rm -rf dir1
[root@localhost dir]# ls
1.txt

3.- i  询问命令,一般 rm 命令在别名中已经携带 -i 选项,会确认是否删除,输 y删除,输入其他无法删除

[root@localhost dir]# ls
1.txt
[root@localhost dir]# rm -i 1.txt
rm:是否删除普通空文件 "1.txt"?y

[root@localhost dir]# touch 1.txt
[root@localhost dir]# rm -i 1.txt
rm:是否删除普通空文件 "1.txt"?n
[root@localhost dir]# rm -i 1.txt
rm:是否删除普通空文件 "1.txt"?l
[root@localhost dir]# ls
1.txt

 

 

 

 



 

posted on 2017-12-18 23:35  天梭  阅读(143)  评论(0编辑  收藏  举报