Linux软连接来摆脱长长长的运行目录【学习笔记】

Linux很方便,很多东西可以一个命令解决。Wordpress作为为Linux量身优化的博客系统,自然也支持命令行的管理。在根目录下有个wp-cli.phar,就是那个命令行的程序文件。但是每次运行都要带上长长的目录,怎么简化?

我们知道Linux有软连接的机制,这样我们运行python等程序时不用输入/usr/local/…..这样长长的目录而只需要一个python就可以了。我们这里也是用的这个原理。一个命令,很简单。

ln -s /dir/to/wordpress/wp-cli.phar /usr/bin/wp
# 其中/usr/bin这个位置应该是不能变的,后面的你可以自己定制,例如wp,wordpress,怎么好记怎么来。

然后我们试一下:

root@localhost# wp
Error: YIKES! It looks like you're running this as root. You probably meant to run this as the user that your WordPress installation exists under.

If you REALLY mean to run this as root, we won't stop you, but just bear in mind that any code on this site will then have full control of your server, making it quite DANGEROUS.

If you'd like to continue as root, please run this again, adding this flag:  --allow-root

If you'd like to run it as the user that this site is under, you can run the following to become the respective user:

    sudo -u USER -i -- wp <command>

这样就可以了。

是的,细心的你可能注意到了,为了安全起见wordpress不希望用户以root用户来运行命令行。当然,你可以用--allow-root来忽略这个。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*

code