alw*_*slz 2 linux bash shell cd
我刚刚学习了Linux,并阅读了"Linux命令行"一书.它说:
cd是bash中的内置命令.
所以我们找不到任何东西which cd; 但不知怎的,它在我的电脑上运行良好:
$ which cd
/usr/bin/cd
Run Code Online (Sandbox Code Playgroud)
是因为我使用CentOS?
对于shell内置使用help而不是man.help cd会告诉你使用信息.which是误导,因为它只找到二进制文件.使用type.
$ type cd
cd is a shell builtin
$ help cd
cd: cd [-L|[-P [-e]] [-@]] [dir]
Change the shell working directory.
...
Run Code Online (Sandbox Code Playgroud)
现在碰巧,你的系统上有一个无用的二进制* /usr/bin/cd.它既没有用,也因为内置的shell取代了它,因为二进制文件不可能改变父shell的目录.尝试使用它,你会发现它什么都不做.
/dir1$ /usr/bin/cd /dir2
/dir1$
Run Code Online (Sandbox Code Playgroud)