linux文件与目录管理

xiaoxiao2021-02-28  123

目录与路径

相对路径与绝对路径

        相对路径:路径的写法从根目录“/”写起,例如:/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中

转载请注明原文地址: https://www.6miu.com/read-20650.html

最新回复(0)