自动将别名添加到 .bashrc
我知道可能没有简单的方法可以做到这一点,但我想我可以把它放在那里。我有一个目录,其中包含我所处理的每个客户的子目录。我希望能够在计算机上的任何位置键入该客户目录名称,然后切换到该目录。换句话说:
/dir/customers/
/dir/customers/customer1/
/dir/customers/customer2/
/dir/customers/customer3/
我希望将 customer1、customer2 和 customer3 全部添加到我的 ~/.bashrc 文件中,并且每当我创建新客户时,它也会更新以添加该文件。
有接受者吗?
I know there is probably no simple way to do this, but I thought I might put this out there. I have a directory that contains a subdirectory for each customer I deal with. I'd like to be able to type that customers directory name in, anywhere on the computer, and switch to that directory. In other words:
/dir/customers/
/dir/customers/customer1/
/dir/customers/customer2/
/dir/customers/customer3/
I'd like customer1, customer2, and customer3 to all be added to my ~/.bashrc file, and whenever I create a new customer, it would update to add that as well.
Any takers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在 ~/.bashrc 中添加此代码:
它将为 customer1、customer2、customer3(/dir/customers/ 的所有子目录)设置别名,并且每次添加新客户(例如:customerN)时,它的别名为 customerN将在您登录时自动添加。
例如:别名 customer1 是 cd /dir/customers/customer1 ,别名 customer2 是 cd /dir/customers/customer2 等等...
If you add this code in your ~/.bashrc:
It will setup aliases for customer1, customer2, customer3 (all the sub directories of /dir/customers/) and every time you add a new customer (eg: customerN) it's alias customerN will be added automatically you log in.
eg: alias customer1 is cd /dir/customers/customer1 and alias customer2 is cd /dir/customers/customer2 so on...
值得一提的替代方案:您可以
export CDPATH=/dir/customers
,然后如果您在任何地方输入
cd David_Johnson
,您将被带到/dir/ customers/David_Johnson
(如果存在这样的目录)。这里的好处是,您可以只添加
David_Johnson
并且不需要为您的.bashrc
提供资源来使其工作(我知道它不是别名,但似乎提供有点灵活性)An alternative worth mentioning: you can
export CDPATH=/dir/customers
and then if you are anywhere and you type
cd David_Johnson
you would be taken to/dir/customers/David_Johnson
if such a directory existed.The benefit here is that you could have just Added
David_Johnson
and did not need to resource your.bashrc
for this to work (I know it's not an alias, but seems to offer a bit flexibility)