linux文件与目录管理

目录与路径

相对路径与绝对路径

        相对路径:路径的写法从根目录“/”写起,例如:/usr/bin/

绝对路径:路径的写法不从根目录“/”写起,例如:从/usr/bin/到/usr/local可以写cd../local/

目录的相关操作

 cd(Change Directory):切换目录                             

cd .. /cd -:回到当前文件的上层目录
cd ~/cd :回到自己的主文件夹,及/root目录

 pwd(Print WorkingDirectory):显示当前目录                         

[root@localhost mail]# pwd
/var/mail
[root@localhost mail]# pwd –P  大写的P
/var/spool/mail
-P:显示当前路径,不是使用链接的路径

 mkdir:新建一个新的目录(文件)

[root@localhost tmp]# mkdir -p test1/test2/test3/test4 
==》加了-p参数就可以创建多层目录了
[root@localhost tmp]# mkdir -m 711 test2
==》新建权限为:rwx—x—x的目录
[root@localhost tmp]# ls -l
总用量 20
drwxr-xr-x. 2 root root 4096 5月   5 11:21 711
-rw-rw-r--. 1 root root    0 5月   3 16:54 attrtest
-rw-r--r--. 1 root root  176 5月   3 2015 bashrc
drwxr-xr-x. 2 root root 4096 5月   5 11:20 test
drwxr-xr-x. 3 root root 4096 5月   5 11:21 test1
drwx--x--x. 2 root root 4096 5月   5 11:22 test2
-rw-r--r--. 1 root root    0 5月   3 15:54 testtouch
-rw-------. 1 root root    0 5月   3 12:49 yum.log

 rmdir:删除一个空的目录(文件)            

[root@localhost tmp]# rmdir test
[root@localhost tmp]# rmdir test1
rmdir: 删除 "test1" 失败: 目录非空
[root@localhost tmp]# rmdir -p test1/test2/test3/test4/
[root@localhost tmp]# ls
711  attrtest  bashrc  test2  testtouch  yum.log

$PATH:执行文件路径的变量:

[root@localhost tmp]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.7.0_71/bin:/root/bin


1、不同的身份用户默认你的path是不同的,默认能随意执行的命令你也是不同的
2、path是能够修改的,所以一般用户也可以通过修改来改变path来执行某位于/sbin或/usr/bin的命令来查询
3、使用绝对路径或相对路径直接指定某个命令的文件名来执行会更加方便,会比PATH来的正确
4、命令应该放在正确的目录下,执行起来才会更方便
5、本目录(.)最好不要放在PATH中

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值