相对路径、绝对路径、cd、mkdir、rm命令举例

简介:

一、相对和绝对路径

相对路径

相对当前目录位置的路径
[root@VM_46_188_centos /]# cd /usr/
[root@VM_46_188_centos usr]# ls
bin  etc  games  include  lib  lib64  libexec  local  sbin  share  src  tmp
[root@VM_46_188_centos usr]#
[root@VM_46_188_centos php]# ls
bin  etc  include  lib  php

绝对路径

从根开始的路径
[root@VM_46_188_centos fxq]# 
[root@VM_46_188_centos network-scripts]# ls
ifcfg-eth0   ifdown-TeamPort  ifdown-ippp  ifdown-ppp     ifup           ifup-bnep  ifup-ipv6   ifup-post    ifup-tunnel        network-functions-ipv6
ifcfg-lo     ifdown-bnep      ifdown-ipv6  ifdown-routes  ifup-Team      ifup-eth   ifup-isdn   ifup-ppp     ifup-wireless
ifdown       ifdown-eth       ifdown-isdn  ifdown-sit     ifup-TeamPort  ifup-ib    ifup-plip   ifup-routes  init.ipv6-globalifdown-Team  ifdown-ib        ifdown-post  ifdown-tunnel  ifup-aliases   ifup-ippp  ifup-plusb  ifup-sit     network-functions
[root@VM_46_188_centos network-scripts]#

二、 cd命令

cd 进入目录

cd - 进入上一次所在的目录

[root@VM_46_188_centos usr]# cd local/php/
[root@VM_46_188_centos php]# ls
bin  etc  include  lib  php
[root@VM_46_188_centos php]#
/usr
[root@VM_46_188_centos usr]# pwd
/usr
[root@VM_46_188_centos usr]# cd -
/usr/local/php

cd ~ 进入用户家目录

[root@VM_46_188_centos ~]# 
[root@VM_46_188_centos ~]# pwd
/root
[root@VM_46_188_centos ~]# 
[root@VM_46_188_centos ~]# pwd
/root
[root@VM_46_188_centos ~]#

cd .. 进入到上一级目录

[root@VM_46_188_centos ~]# pwd
/root
[root@VM_46_188_centos ~]# 
[root@VM_46_188_centos /]# pwd/
[root@VM_46_188_centos /]#

三、创建和删除目录mkdir/rmdir

mkdir 创建目录

mkdir -p /tmp/fxq/1/2 一次创建一系列目录
[root@VM_46_188_centos /]# 
[root@VM_46_188_centos /]# cd /tmp/fxq
[root@VM_46_188_centos fxq]# ls
1 
[root@VM_46_188_centos fxq]# cd 1/
[root@VM_46_188_centos 1]# ls
2
[root@VM_46_188_centos 1]# tree /tmp/fxq/tmp/fxq
`-- 1
    `-- 2
2 directories, 0 files

rmdir 删除空目录

rmdir -p /tmp/fxq/1/2 级联删除目录

四、 rm命令

rm 删除文件

[root@VM_46_188_centos 1]# ls
1.txt  2  test1
[root@VM_46_188_centos 1]# 
rm: remove regular empty file '1.txt'?    
[root@VM_46_188_centos 1]# ls
2  test1
[root@VM_46_188_centos 1]#

rm -r 删除目录

[root@VM_46_188_centos 1]# ls
2  test1
[root@VM_46_188_centos 1]#
rm: remove directory '/tmp/fxq/1/2/'? 
[root@VM_46_188_centos 1]# ls
test1
[root@VM_46_188_centos 1]#

rm -rf 强制删除文件或目录

[root@VM_46_188_centos fxq]# tree.
|-- 1|   |-- 1.txt
|   `-- test1`-- 2
3 directories, 1 file
[root@VM_46_188_centos fxq]# 
removed directory: '/tmp/fxq/1/test1'
removed '/tmp/fxq/1/1.txt'
removed directory: '/tmp/fxq/1/'
[root@VM_46_188_centos fxq]#

-f 加上-f选项删除不存在的文件或目录时不提示信息。

1
2
3
[root@VM_46_188_centos ~] # cd /tmp/fxq
[root@VM_46_188_centos fxq] # rm -rfv /tmp/fxq/1
[root@VM_46_188_centos fxq] #



本文转自 枫叶云  51CTO博客,原文链接:http://blog.51cto.com/fengyunshan911/1954349

相关文章
|
3月前
mkdir、rm、cp、mv命令
mkdir、rm、cp、mv命令
42 0
|
1月前
ls 列出目录的内容
ls 列出目录的内容。
10 2
|
9月前
脚本中mkdir 与 mkdir -p 的区别
脚本中mkdir 与 mkdir -p 的区别
69 1
|
Ubuntu Linux Shell
linux第三课:目录文档操作命令(内含绝对/相对路径+1.pwd+2.cd+3.mkdir(创建目录)+4. rmdir(删除目录)+5. ls+6. cp+7.rm+8cat+9touch命令)
linux第三课:目录文档操作命令(内含绝对/相对路径+1.pwd+2.cd+3.mkdir(创建目录)+4. rmdir(删除目录)+5. ls+6. cp+7.rm+8cat+9touch命令)
161 0
linux第三课:目录文档操作命令(内含绝对/相对路径+1.pwd+2.cd+3.mkdir(创建目录)+4. rmdir(删除目录)+5. ls+6. cp+7.rm+8cat+9touch命令)
|
数据可视化
相对和绝对路径/cd命令/创建和删除目录mkdir/rmdir/rm命令
 2.6 相对和绝对路径 2.7 cd命令 2.8 创建和删除目录mkdir/rmdir 2.9 rm命令   绝对路径:从根开始的路径;文件所在的路径; 相对路径:相对于当前目录而言的路径;上一级或者下一级的路径。
1222 0