您现在的位置是:首页 >其他 >centos的cd与pwd指令网站首页其他

centos的cd与pwd指令

YT20233 2023-06-04 12:00:02
简介centos的cd与pwd指令

一 切换目录cd:(change directory)

1. cd…

cd…的主要作用是切换回上一级

[root@localhost /]# cd bin
[root@localhost bin]# pwd
/bin
[root@localhost bin]# cd ..
[root@localhost /]# ll
总用量 20
lrwxrwxrwx.   1 root root    7 415 20:34 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 415 20:39 boot
drwxr-xr-x.  20 root root 3200 422 18:58 dev
drwxr-xr-x.  74 root root 8192 422 18:58 etc
drwxr-xr-x.   2 root root    6 411 2018 home
lrwxrwxrwx.   1 root root    7 415 20:34 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 415 20:34 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 411 2018 media
drwxr-xr-x.   2 root root    6 411 2018 mnt
drwxr-xr-x.   2 root root 4096 420 18:57 opt
dr-xr-xr-x. 105 root root    0 422 18:58 proc
dr-xr-x---.   3 root root  184 421 00:58 root
drwxr-xr-x.  24 root root  660 422 18:58 run
lrwxrwxrwx.   1 root root    8 415 20:34 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 411 2018 srv
dr-xr-xr-x.  13 root root    0 422 18:58 sys
drwxrwxrwt.   9 root root  232 422 18:59 tmp
drwxr-xr-x.  18 root root  233 420 05:54 usr
drwxr-xr-x.  20 root root  278 420 03:03 var

2. cd /

cd/的主要功能是切换回根目录

[root@localhost ~]# cd /
[root@localhost /]# ll
总用量 20
lrwxrwxrwx.   1 root root    7 415 20:34 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 415 20:39 boot
drwxr-xr-x.  20 root root 3200 422 18:58 dev
drwxr-xr-x.  74 root root 8192 422 18:58 etc
drwxr-xr-x.   2 root root    6 411 2018 home
lrwxrwxrwx.   1 root root    7 415 20:34 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 415 20:34 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 411 2018 media
drwxr-xr-x.   2 root root    6 411 2018 mnt
drwxr-xr-x.   2 root root 4096 420 18:57 opt
dr-xr-xr-x. 108 root root    0 422 18:58 proc
dr-xr-x---.   3 root root  184 421 00:58 root
drwxr-xr-x.  24 root root  660 422 18:58 run
lrwxrwxrwx.   1 root root    8 415 20:34 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 411 2018 srv
dr-xr-xr-x.  13 root root    0 422 18:58 sys
drwxrwxrwt.   9 root root  232 422 18:59 tmp
drwxr-xr-x.  18 root root  233 420 05:54 usr
drwxr-xr-x.  20 root root  278 420 03:03 var

3. cd -

cd - 后退到上一次所在的目录

[root@localhost /]# cd -
/bin
[root@localhost bin]# ll
总用量 428608
-rwxr-xr-x. 1 root root      41488 820 2019 [
-rwxr-xr-x. 1 root root     107848 23 2021 a2p
-rwxr-xr-x. 1 root root      52640 46 01:19 ab
-rwxr-xr-x. 1 root root      29104 102 2020 addr2line
-rwxr-xr-x. 1 root root         29 41 2020 alias
lrwxrwxrwx. 1 root root          6 415 20:34 apropos -> whatis
-rwxr-xr-x. 1 root root      62680 102 2020 ar
-rwxr-xr-x. 1 root root      33080 820 2019 arch
-rwxr-xr-x. 1 root root     386424 102 2020 as
-rwxr-xr-x. 1 root root      28888 88 2019 aserver
-rwxr-xr-x. 1 root root      15856 88 2019 aulast
-rwxr-xr-x. 1 root root      11624 88 2019 aulastlog
-rwxr-xr-x. 1 root root      11448 88 2019 ausyscall
-rwxr-xr-x. 1 root root      32696 88 2019 auvirt
lrwxrwxrwx. 1 root root          4 415 20:34 awk -> gawk
-rwxr-xr-x. 1 root root      37360 820 2019 base64
-rwxr-xr-x. 1 root root      29032 820 2019 basename
-rwxr-xr-x. 1 root root     964536 41 2020 bash
lrwxrwxrwx. 1 root root         10 415 20:34 bashbug -> bashbug-64
-rwxr-xr-x. 1 root root       6964 41 2020 bashbug-64
-rwxr-xr-x. 1 root root      83424 610 2014 bc
-rwxr-xr-x. 1 root root         26 41 2020 bg

4.绝对路径

/开始的目录,从根目录开始

5.相对路径

直接从当前目录开始吗,以当前目录为参照

二 显示当前目录 pwd(print work directory)

[root@localhost bin]# pwd
/bin

三 练习

1 查看当前所在目录

[root@localhost bin]# pwd
/bin

2 切换到 /usr/local(绝对路径)

[root@localhost bin]# cd /usr/local
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 2 root root  6 411 2018 bin
drwxr-xr-x. 2 root root  6 411 2018 etc
drwxr-xr-x. 2 root root  6 411 2018 games
drwxr-xr-x. 2 root root  6 411 2018 include
drwxr-xr-x. 2 root root  6 411 2018 lib
drwxr-xr-x. 2 root root  6 411 2018 lib64
drwxr-xr-x. 2 root root  6 411 2018 libexec
drwxr-xr-x. 2 root root  6 411 2018 sbin
drwxr-xr-x. 5 root root 49 415 20:34 share
drwxr-xr-x. 2 root root  6 411 2018 src

3 切换到 上一级 /usr

[root@localhost local]# cd ..
[root@localhost usr]# 

4 切换到 /usr/tmp (相对路径)

cd tmp

5 切换回 /usr/local

[root@localhost usr]# cd /usr/local
[root@localhost local]# 

6 后退到上一次所在目录

cd -
风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。