<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          不可錯過的cd命令,你知道cd -、cd ~和切換空格目錄等內(nèi)容嗎?

          共 3844字,需瀏覽 8分鐘

           ·

          2021-11-04 03:27

          cd 命令詳細(xì)介紹

          cd (change directory)改變目錄,即,切換目錄。用于從當(dāng)前目錄切換到另一個指定的目錄。

          cd 后面的目錄路徑,可以是相對目錄,也可以是絕對目錄。

          ./ 相對路徑,表示當(dāng)前目錄;../ 相對路徑,表示上一級目錄。/xxx 反斜杠開頭的表示絕對路徑。

          / 表示根目錄,所有的內(nèi)容都從根目錄開始;/root 表示root用戶的家目錄。

          對于家目錄(Home Directory),除了root用戶之外,所有用戶的家目錄都位于 /home/ 下(/home/)。

          • Absolute Path(絕對路徑):從根目錄開始的路徑。

          • Relative Path(相對路徑):相對于當(dāng)前位置開始的路徑,如 ./../

          cd切換命令演示

          Linux中涉及到目錄的所有命令,都可以通過 tab 鍵對路徑補(bǔ)全。即輸入路徑名的一部分,按 tab 鍵補(bǔ)全其余名稱。

          cd ../cd ../ 切換到相對當(dāng)前的上一級目錄

          [root_test@VM_0_15_centos test]$ cd ../
          [root_test@VM_0_15_centos ~]$
          復(fù)制代碼

          ./開頭,或直接以目錄名(文件名)開頭,表示當(dāng)前目錄。

          如下切換到當(dāng)前目錄下的test目錄中。

          [root_test@VM_0_15_centos ~]$ cd test/
          [root_test@VM_0_15_centos test]$ cd ../
          [root_test@VM_0_15_centos ~]$ cd ./test/
          [root_test@VM_0_15_centos test]$
          復(fù)制代碼

          切換到絕對目錄 /etc/my.cnf.d

          [root_test@VM_0_15_centos test]$ cd /etc/my.cnf.d
          [root_test@VM_0_15_centos my.cnf.d]$
          復(fù)制代碼

          help 查看 cd 命令的幫助

          cd命令是shell的內(nèi)置命令,使用 man 查看時會顯示 shell 的幫助信息,而不是 cd 的。

          $ man cd
          BASH_BUILTINS(1) General Commands Manual BASH_BUILTINS(1)

          NAME
          bash, :, ., [, alias, bg, bind, break, builtin, caller, cd, command,
          compgen, complete, compopt, continue, declare, dirs, disown, echo,
          enable, eval, exec, exit, export, false, fc, fg, getopts, hash, help,
          history, jobs, kill, let, local, logout, mapfile, popd, printf, pushd,
          pwd, read, readonly, return, set, shift, shopt, source, suspend, test,
          times, trap, true, type, typeset, ulimit, umask, unalias, unset, wait -
          bash built-in commands, see bash(1)

          BASH BUILTIN COMMANDS
          ......
          復(fù)制代碼

          help cd 查看幫助命令:

          $ help cd
          cd: cd [-L|[-P [-e]]] [dir]
          Change the shell working directory.

          Change the current directory to DIR. The default DIR is the value of the
          HOME shell variable.
          ......
          復(fù)制代碼

          cd - 切換到上一次的目錄

          cd - 命令用于直接切換到上一次的目錄,即兩個目錄之前來回切換,非常方便。

          [root_test@VM_0_15_centos ~]$ cd /etc/sysconfig/network-scripts/
          [root_test@VM_0_15_centos network-scripts]$ pwd
          /etc/sysconfig/network-scripts
          [root_test@VM_0_15_centos network-scripts]$ cd -
          /home/root_test
          [root_test@VM_0_15_centos ~]$ cd -
          /etc/sysconfig/network-scripts
          [root_test@VM_0_15_centos network-scripts]$
          復(fù)制代碼

          cd ~cd $home 返回家目錄

          cd ~ 命令用于快速回到用戶家目錄(Home Directory)。對于 root 用戶為/root;對于其他用戶為/home/user_name

          [root_test@VM_0_15_centos tmp]$ pwd
          /var/tmp
          [root_test@VM_0_15_centos tmp]$ cd ~
          [root_test@VM_0_15_centos ~]$ pwd
          /home/root_test
          復(fù)制代碼

          $# 前面的 ~ 即表示當(dāng)前是家目錄。

          ~(波浪號——tilde)是家目錄的縮寫。

          cd $home 同樣用于回到家目錄。

          root 用戶使用 cd ~username 切換到指定用戶的家目錄

          cd ~usernamecd ~username/ 用于切換到指定用戶的家目錄,但是,只能root用戶執(zhí)行,具有管理員權(quán)限的用戶,使用 sudo 執(zhí)行也無效。

          比如,root_test用戶,嘗試切換到 root_test1 和 root_test2 用戶,均失敗!

          [root_test@VM_0_15_centos ~]$ cd ~root_test2
          -bash: cd: /home/root_test2: Permission denied
          [root_test@VM_0_15_centos ~]$ sudo cd ~root_test1
          [root_test@VM_0_15_centos ~]$ pwd
          /home/root_test
          [root_test@VM_0_15_centos ~]$ sudo cd ~root_test2
          [root_test@VM_0_15_centos ~]$ pwd
          /home/root_test
          復(fù)制代碼

          root用戶可以正常切換。

          [root@VM_0_15_centos ~]# pwd
          /root
          [root@VM_0_15_centos ~]# cd ~root_test2
          [root@VM_0_15_centos root_test2]# pwd
          /home/root_test2
          復(fù)制代碼

          三種方法切換到有空格的目錄名中

          如下,存在一個有空格的目錄 my space dir

          $ ls -l
          total 12
          -rw-rw-r-- 1 root_test root_test 2 Oct 29 08:52 123
          drwxrwxr-x 2 root_test root_test 4096 Oct 29 08:52 my
          drwxrwxr-x 2 root_test root_test 4096 Oct 30 10:28 my space dir
          -rw-rw-r-- 1 root_test root_test 0 Oct 26 21:52 my.txt
          復(fù)制代碼

          一下三種方式均可使用 tab 鍵補(bǔ)全。

          使用 \ 轉(zhuǎn)義字符

          [root_test@VM_0_15_centos test]$ cd my\ space\ dir/
          [root_test@VM_0_15_centos my space dir]$ pwd
          /home/root_test/test/my space dir
          復(fù)制代碼

          使用雙引號包含目錄名

          [root_test@VM_0_15_centos test]$ cd "my space dir"/
          [root_test@VM_0_15_centos my space dir]$
          復(fù)制代碼

          使用單引號

          [root_test@VM_0_15_centos test]$ cd 'my space dir'/
          [root_test@VM_0_15_centos my space dir]$
          復(fù)制代碼

          另,cd !$,表示把上個命令的參數(shù)作為 cd 參數(shù)使用


          作者:代碼迷途
          鏈接:https://juejin.cn/post/7024685258851221511
          來源:稀土掘金
          著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請注明出處。


          瀏覽 100
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  女人裸体一级片久久久 | 青青草男人天堂 | 中文字幕国产乱伦 | 国产 无码 精品 | 久久不卡视频精典视频 |