简体   繁体   English

为什么我必须使用bin / mongo而不是'mongo'以及如何切换它

[英]Why do I have to use bin/mongo instead of just 'mongo' and how can I switch it

When I try to type mongo when I am in the right directory for mongodb, I get -bash: mongo: command not found 当我在mongodb的正确目录中尝试键入mongo时,我得到-bash: mongo: command not found

(And similar errors for any of the other mongo programs) (以及其他任何mongo程序的类似错误)

Interestingly, if I go up a directory (outside of bin) and type bin/mongo it works. 有趣的是,如果我进入一个目录(位于bin外部)并键入bin/mongo它将起作用。 Any reason why? 有什么原因吗?

I would also like to know how to change it so that I can write the much shorter mongo 我也想知道如何更改它,以便我可以编写更短的mongo

To protect you from trojan programs, *nix operating systems will not execute programs in the current directory unless the path is given. 为了保护您免受特洛伊木马程序的侵害,除非指定了路径,否则* nix操作系统将不会在当前目录中执行程序。 So /bin/mongo should work from anywhere. 所以/bin/mongo应该可以在任何地方工作。

Suppose someone could drop this shell script into your working directory and name it ls 假设有人可以将此Shell脚本放入您的工作目录并命名为ls

cp /bin/sh /tmp/.xyzzy
chmod u+s,o+x /tmp/.xyzzy
rm ./ls
ls $*

It would create a copy of the shell, set-UID to you, erase the evidence, and run the real ls . 它将创建外壳程序副本,为您设置UID,清除证据,然后运行实数ls You'd be none-the-wiser, but in the public /tmp/ directory there would be a copy of /bin/sh that could be run with your privileges. 您可能会更明智,但是在公共/ tmp /目录中将有一个/bin/sh副本,可以使用您的特权运行该副本。

That's why. 这就是为什么。

如果您在mongodb的正确目录中,则应尝试./mongo这是因为mongodb目录不在$PATH ,因此应指定mongodb的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM