bash make命令别名_使用Bash别名优化您的命令行工作流程

bash make命令别名

Whether you’re a novice developer or a seasoned veteran, it’s always a good idea to consider optimizations in your workflow to maximize your productivity in solving the problems that matter.

无论您是新手开发人员还是经验丰富的老手,在工作流程中考虑优化以最大化解决问题时的生产率始终是一个好主意。

The command line, or terminal, is a very common touchpoint for programmers. Given that it’s a text-based interface, a lot of its capabilities are slowed down by the need for memorization of commands, which can often be long and sometimes can be complicated.

命令行或终端对于程序员来说是非常常见的接触点。 鉴于它是基于文本的界面,由于需要记忆命令,因此其许多功能会变慢,而记忆通常会很长,有时会很复杂。

That’s where Bash aliases come in.

这就是Bash别名的来源。

什么是Bash别名? (What’s a Bash alias?)

A Bash alias is basically a shortcut you can set for a command. If you have to type some long command out often, you can shorten it or make it more memorable with a Bash alias.

Bash别名基本上是您可以为命令设置的快捷方式。 如果您必须经常键入一些长命令,可以使用Bash别名将其缩短或使其更令人难忘。

Bash别名的例子是什么? (What’s an example of a Bash alias?)

Let’s say you run the following command often:

假设您经常运行以下命令:

Basically, you often have to ssh into an IP of 10.82.16.435 with a port of 8080, but it’s a pain to type that out every time. In fact, you often have to refer to some notes you have in order to copy and paste that command in every single time.

基本上,你经常要ssh到的IP 10.82.16.435用的端口8080 ,但它是键入每一次疼痛。 实际上,为了每次都复制和粘贴该命令,通常必须参考一些注释。

With Bash aliases, you can run that command with something as simple as the following:

使用Bash别名,您可以使用以下简单命令来运行该命令:

Isn’t that much nicer and easier to remember?

难道不是更好,更容易记住吗?

如何制作Bash别名? (How do I make a Bash alias?)

First, go to your command line or Terminal.

首先,转到您的命令行或终端。

在您当前的Shell会话中 (In your current shell session)

Then, type whatever you want to alias in the following format. I’ll use the above example here:

然后,以以下格式键入要作为别名的任何内容。 我将在此处使用以上示例:

It’s honestly really that simple. Now, you can just use the command enter_ip whenever you want.

老实说,就是这么简单。 现在,您可以随时使用命令enter_ip

However, there’s a catch: this is only in your current shell session. Close your window, and this alias is gone.

但是,有一个陷阱:这仅在您当前的shell会话中。 关闭您的窗口,该别名消失了。

在以后的所有Shell会话中 (In all future shell sessions)

If you plan on keeping that alias for the future, you will have to open up either your ~/.bash_profile or ~/.bashrc files with a text editor and save the aliases directly there. Here are some examples of text editor commands you can use; just choose your favorite one:

如果打算将来保留该别名,则必须使用文本编辑器打开~/.bash_profile~/.bashrc文件,然后直接在其中保存别名。 这是您可以使用的文本编辑器命令的一些示例。 只需选择您最喜欢的一个即可:

Then, save your alias:

然后,保存您的别名:

The alias will now be available in all your future shell sessions. If you really want it in your current shell session, you can run the following command (make sure you replace ~/.bash_profile with ~/.bashrc if you saved it there instead):

现在,该别名将在以后的所有Shell会话中可用。 如果您确实希望在当前的shell会话中使用它,则可以运行以下命令(确保将〜/ .bash_profile替换为〜/ .bashrc(如果将其保存在该位置),请执行以下命令:

如何摆脱Bash别名? (How do I get rid of the Bash alias?)

在您当前的Shell会话中 (In your current shell session)

Just as you saved the alias, you can un-save it with the following command format:

就像保存别名一样,您可以使用以下命令格式取消保存它:

Now, enter_ip will no longer work as you expected.

现在, enter_ip将不再按预期工作。

Alternatively, you can simply exit your current shell session; this could simply mean just exiting out of your terminal window.

另外,您可以简单地退出当前的Shell会话。 这可能只是意味着退出您的终端窗口。

在以后的所有Shell会话中 (In all future shell sessions)

As you can probably deduce, you can navigate to your ~/.bash_profile or ~/.bashrc files with your text editor of choice and then delete the alias lines. Remember to use the source command afterward if you want the changes to take effect immediately in your current session.

可以推断出,可以使用所选的文本编辑器导航至~/.bash_profile~/.bashrc文件,然后删除别名行。 如果您希望更改在当前会话中立即生效,请记住以后使用source命令。

翻译自: https://medium.com/swlh/optimize-your-command-line-workflow-with-bash-aliases-7647e5601439

bash make命令别名

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值