Linux unalias Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the unalias command in Linux to temporarily disable aliases that you have previously created. You will also learn how to create and manage aliases in the terminal, which can make your workflow more efficient by allowing you to use shorter commands instead of the full commands. The lab covers the purpose of the unalias command, how to create and manage aliases, and how to temporarily disable aliases using the unalias command. The content is presented in a clear and concise manner, without any additional information or sub-headings.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux/BasicSystemCommandsGroup -.-> linux/source("`Script Executing`") linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`") linux/BasicFileOperationsGroup -.-> linux/ls("`Content Listing`") subgraph Lab Skills linux/source -.-> lab-422972{{"`Linux unalias Command with Practical Examples`"}} linux/echo -.-> lab-422972{{"`Linux unalias Command with Practical Examples`"}} linux/ls -.-> lab-422972{{"`Linux unalias Command with Practical Examples`"}} end

Understand the Purpose of the unalias Command

In this step, you will learn about the purpose of the unalias command in Linux. The unalias command is used to temporarily disable an alias that has been previously created.

Aliases are shortcuts or nicknames for commands in the Linux terminal. They can make your workflow more efficient by allowing you to type a shorter command instead of the full command. However, there may be times when you need to temporarily disable an alias and use the original command instead.

Let's start by creating an alias for the ls command:

alias ls='ls -l'

Now, when you run the ls command, it will execute the ls -l command, which lists files in long format.

Example output:

total 12
drwxr-xr-x 2 labex labex 4096 May 11 10:00 bin
drwxr-xr-x 3 labex labex 4096 May 11 10:00 project
-rw-r--r-- 1 labex labex   24 May 11 10:00 README.md

To temporarily disable the alias and use the original ls command, you can use the unalias command:

unalias ls
ls

Example output:

bin  project  README.md

As you can see, the unalias ls command temporarily disables the alias, and the ls command now executes the original ls command instead of the aliased version.

The unalias command is useful when you need to run the original command instead of the aliased version, without having to permanently remove the alias.

Create and Manage Aliases in the Terminal

In this step, you will learn how to create and manage aliases in the Linux terminal.

Aliases are shortcuts or nicknames for commands that you use frequently. They can save you time and make your workflow more efficient.

Let's start by creating an alias for the git status command:

alias gs='git status'

Now, whenever you type gs in the terminal, it will execute the git status command.

Example output:

On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

You can also create aliases for more complex commands. For example, let's create an alias for the git commit -m command:

alias gcm='git commit -m'

Now, you can use the gcm alias to commit changes with a message:

gcm "Update README.md"

Example output:

[main 1234567] Update README.md
 1 file changed, 1 insertion(+)

To view all the aliases you have created, you can use the alias command:

alias

Example output:

alias gs='git status'
alias gcm='git commit -m'

Aliases are stored in your shell configuration file, such as .bashrc or .zshrc, depending on the shell you are using. If you want the aliases to persist across sessions, you can add them to your shell configuration file.

Temporarily Disable Aliases Using the unalias Command

In this step, you will learn how to temporarily disable aliases using the unalias command.

First, let's create some aliases:

alias ll='ls -l'
alias rm='rm -i'

Now, when you run the ll command, it will execute the ls -l command, and when you run the rm command, it will execute the rm -i command.

Example output:

total 12
drwxr-xr-x 2 labex labex 4096 May 11 10:00 bin
drwxr-xr-x 3 labex labex 4096 May 11 10:00 project
-rw-r--r-- 1 labex labex   24 May 11 10:00 README.md

To temporarily disable the ll alias, you can use the unalias command:

unalias ll
ll

Example output:

bin  project  README.md

As you can see, the unalias ll command temporarily disables the ll alias, and the ll command now executes the original ls -l command.

You can also disable multiple aliases at once:

unalias ll rm
ll
rm README.md

Example output:

bin  project  README.md
rm: remove regular file 'README.md'?

In this example, both the ll and rm aliases are temporarily disabled.

The unalias command is useful when you need to run the original command instead of the aliased version, without having to permanently remove the alias.

Summary

In this lab, you learned about the purpose of the unalias command in Linux, which is used to temporarily disable an alias that has been previously created. You also learned how to create and manage aliases in the terminal, which can save you time and make your workflow more efficient. The lab covered creating aliases for frequently used commands, such as ls and git status, and using the unalias command to temporarily disable an alias and use the original command instead.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like