• About Us
  • Contact Us
  • Privacy Policy
  • Terms Of Services
  • DMCA Policy
  • Our Sitemap
UpCutter
  • Home
  • Applications
  • Computers & Electronics
  • Gaming
  • Internet
  • Web Development
No Result
View All Result
  • Home
  • Applications
  • Computers & Electronics
  • Gaming
  • Internet
  • Web Development
No Result
View All Result
UpCutter
No Result
View All Result

Home » General » How to customize the Linux terminal with bash aliases

How to customize the Linux terminal with bash aliases

William Platt by William Platt
January 12, 2022
in General
0
312
SHARES
2.4k
VIEWS
Share on FacebookShare on Twitter

An alias is effectively a “shortcut” command in Bash. For example, if you use the terminal in Ubuntu a lot, and get sick of typing sudo apt update;sudo apt upgrade -y all the time, you can create an alias called “update” that will execute those same commands without needing to type out so much.

Bash aliases are defined in every user’s home directory in the .bashrc file. For more information on aliases, run the man command below. It will show you all there is to know about aliases, how they work, and what you can do with them.

man bash | grep alias

You can also take a look at the complete Bash manual by running:

man bash

Setting commands as aliases

The most common use for alias in Bash is using it to execute multiple, long commands at once to save time. In this example, we will go over how to turn Ubuntu’s long update commands into a simple alias.

To start the process, open up a terminal window on your Linux desktop by pressing Ctrl + Alt + T or Ctrl + Shift + T on the keyboard. Then, open up your .bashrc file in the Nano text editor with the command below.

nano -w ~/.bashrc

Inside of the .bashrc file, you will notice a lot of code already there. The developers of your Linux distribution define this text. If you do not understand what any of it is, it is best to ignore it and leave it be, and move to the bottom of the file.

At the bottom of the .bashrc file, press the Enter key to create a new line. It is critical to create a new line in your .bashrc file before adding to it, as you could mess up the code already there.

After creating a new line in the .bashrc file, write out alias on the new line. Each new alias you create must start with alias , otherwise .bashrc and your terminal emulator will not read it correctly.

alias

Following alias= on the new line, you must give your new alias a name. In this example, we are covering Ubuntu’s long update commands, so, we will use ubuntu-update as the new alias name. However, feel free to name your alias whatever you like.

alias ubuntu-update

Once you’ve named your alias, it is time to add in the = sign.

alias ubuntu-update=

Next, after the = sign, add in the first " (quotation mark). This quotation mark will contain all of your commands within the alias.

alias ubuntu-update="

So far we have alias ubuntu-update=". Now it is time to add in the commands that we want the alias to call when ubuntu-update is used.

Note: use ; to write multiple commands in one line. Such as command1;command2;command3, and so on.

alias ubuntu-update="sudo apt update;sudo apt upgrade -y

When you’ve finished writing out the commands in the alias, close it off with the second " (quotation mark). With both quotation marks, it should look like the example below.

alias ubuntu-update="sudo apt update;sudo apt upgrade -y"

Save your new alias by pressing Ctrl + O on the keyboard. Exit Nano with Ctrl + X. Then, close the terminal window and re-open it.

When you’ve re-opened the terminal, run ubuntu-update to try out the new alias.

Setting bash scripts as aliases

Did you know that it is also possible to run bash scripts as an alias? Here’s how it works.

First, open up your .bashrc file. Then, go to the bottom of the file and press the Enter key on the keyboard to create a new line in the file.

sudo nano -w ~/.bashrc

On the new line, write alias followed by the name of the script. In this example, the script name is mybashscript. It should look like alias mybashscript.

alias mybashscript

Next, add in the = sign, and the first " (quotation mark). After adding in the = and ", it will look like the example below.

alias mybashscript="

Following the first " (quotation mark), add in the command to launch your code. Please remember that this is an example, so you will need to replace ~/path/to/bash/script/script.sh with the actual script file, you want to execute within the .bashrc alias.

alias mybashscript="bash ~/path/to/bash/script/script.sh

After writing in the command to execute the script file, close off the alias with the second quotation mark ". When the entire alias is written out, it should look something like the example below.

alias mybashscript="bash ~/path/to/bash/script/script.sh"

Save the edits to the .bashrc file by pressing Ctrl + O, and exit with Ctrl + X. Then, close your terminal window and re-open it to execute your new bash script via an alias.

To launch the alias, run mybashscript (or whatever you’ve named your alias) and press Enter.

Previous Post

Flameshot is a brilliant screenshot tool for Linux

Next Post

VPN Market Report 2022 – Which VPN Has The Biggest Market Share?

Related Posts

General

How to install display color profiles on Windows 10

February 17, 2023
General

Effective SEO copywriting hints to increase your traffic

February 15, 2023
General

What Microsoft’s new Xbox Series X says about the future of gaming

February 10, 2023
General

How to Check if an iPhone is Unlocked, or Locked to a Network

January 28, 2023
General

How to delete online accounts and reduce your security risks

January 22, 2023
General

How to install the Chromium based version of Brave browser on Linux

January 18, 2023

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

RECOMMENDEDREADS

General

How to Check if an iPhone is Unlocked, or Locked to a Network

by William Platt
January 28, 2023
General

How to delete online accounts and reduce your security risks

by William Platt
January 22, 2023
General

How to install the Chromium based version of Brave browser on Linux

by William Platt
January 18, 2023

Popular Post

  • The Blender 2.8 Keyboard Shortcuts Cheat Sheet for Windows

    341 shares
    Share 136 Tweet 85
  • Funny Things To Ask Siri At Christmas And All Year Round

    340 shares
    Share 136 Tweet 85
  • How to Jailbreak FireStick 4K [Free & Safest Method for February 2020]

    337 shares
    Share 135 Tweet 84
  • Stay Strong Quotes to Text Someone Who Needs Inspiration

    326 shares
    Share 130 Tweet 82
  • Top 15 Marketing Automation Software for 2020

    326 shares
    Share 130 Tweet 82

Browse by Categories

  • General (139)
  • Internet Marketing (1)
  • Technology (20)
  • Web Development (1)
UpCutter

UpCutter is a community of technology enthusiasts who believe that technology should be available to all and an effort should be made to help everyone understand it.

Contact us at mail@upcutter.com.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms Of Services
  • DMCA Policy
  • Our Sitemap

© 2022 UpCutter. All Rights Reserved. Reproduction Of Contents Is Strictly Prohibited.

No Result
View All Result
  • Home
  • Applications
  • Computers & Electronics
  • Gaming
  • Internet
  • Web Development

© 2022 UpCutter. All Rights Reserved. Reproduction Of Contents Is Strictly Prohibited.