You are here: Home » How to Create a Custom Bash Command in Ubuntu 24.04 or 22.04

How to Create a Custom Bash Command in Ubuntu 24.04 or 22.04

by Jonathan Dough

Ever find yourself typing the same long command over and over in your Ubuntu terminal? Why not save some time and create your own custom Bash command? It’s fun, easy, and makes you feel like a Linux wizard!

In this guide, we’ll walk through how to do it on Ubuntu 24.04 or 22.04. You’ll learn how to create, save, and use your custom command like a pro.

🔧 What Is a Custom Bash Command?

It’s like a shortcut. Instead of typing a long command or series of commands, you type one simple word. Bash will run the full command for you in the background. Magic, right?

Let’s say you often run:

ls -alh --color=auto

Why not create a custom command like ll instead?

🚀 Step-by-Step: Making Your Own Bash Command

Here’s how to do it in just a few steps.

  1. Open your terminal
    You can use Ctrl + Alt + T to open it quickly.
  2. Edit your Bash config file
    Depending on which shell you use, run:

    nano ~/.bashrc

    This file runs every time you open a terminal.

  3. Add your custom command
    Scroll to the bottom and type something like:

    alias ll='ls -alh --color=auto'

    This sets ll as a new command that runs ls -alh –color=auto.

  4. Save and exit
    Hit Ctrl + O to save, then Ctrl + X to exit Nano.
  5. Apply the changes
    Type:

    source ~/.bashrc

    Now Bash knows about your new command.

💡 Cool Tip:

You can create more advanced custom commands too! Like combining several commands into one.

alias backup='tar -czvf backup.tar.gz ~/Documents'

This would compress your Documents folder into a nice backup file. Handy!

📂 Want to Create a Script Instead?

Aliases are cool, but maybe you want a custom command that does more than one thing. That’s where scripts come in.

  1. Create a script file
    Make a new file:

    nano myscript.sh
  2. Add some shell code
    For example:

    #!/bin/bash
    echo "Backing up..."
    tar -czvf backup.tar.gz ~/Documents
    echo "Done!"
  3. Make it executable
    Do this:

    chmod +x myscript.sh
  4. Add it to your PATH
    Move the file to a folder in your PATH so you can run it from anywhere:

    mv myscript.sh ~/.local/bin/mybackup

    Then you can run it by simply typing:

    mybackup

📋 Bonus: Check Existing Aliases

Wondering what aliases already exist on your system? Just type:

alias

You’ll see a list of all available shortcuts. Pretty neat!

🧹 Want to Remove a Custom Command?

If you change your mind, you can delete the line from .bashrc and run:

source ~/.bashrc

Or temporarily remove an alias like this:

unalias ll

✅ Wrap-Up

Creating custom Bash commands in Ubuntu 22.04 or 24.04 is super simple. Whether it’s a quick alias or a full script, you’re in control.

  • Save time
  • Avoid typing mistakes
  • Impress your friends (or cat!)

So go ahead—make your terminal smarter, one line at a time!

Techsive
Decisive Tech Advice.