How To

How To Create Bash Aliases In Linux

Introduction

Bash aliases are shortcuts for long or frequently used Linux commands. Instead of typing the same command again and again, you can create a short alias and run it quickly from the terminal. If you are learning Bash scripting or Linux command-line basics, aliases can save time and improve your workflow.

Bash aliases are useful for system administrators, Linux users, developers, and cybersecurity learners. You can create aliases for listing files, updating the system, checking logs, connecting to servers, running scans, or navigating directories faster.

What Is A Bash Alias?

A Bash alias is a custom shortcut for a command.

Basic syntax:

alias shortcut='command'

Example:

alias ll='ls -la'

Now, instead of typing:

ls -la

You can simply type:

ll

This will show all files, including hidden files, in long listing format.

Create A Temporary Bash Alias

You can create an alias directly in the terminal.

alias cls='clear'

Now run:

cls

This will clear the terminal screen.

However, this alias is temporary. It will work only in the current terminal session. If you close the terminal, the alias will be removed.

View Existing Bash Aliases

To view all aliases currently available in your shell, run:

alias

This will display all active aliases.

To check a specific alias, use:

alias ll

Create Permanent Bash Aliases

To make aliases permanent, add them to the .bashrc file.

Open .bashrc using nano:

nano ~/.bashrc

Scroll to the bottom and add your aliases:

alias ll='ls -la'alias cls='clear'alias ports='ss -tuln'alias update='sudo apt update && sudo apt upgrade'

Save the file and reload it:

source ~/.bashrc

Now your aliases will work even after closing and reopening the terminal.

Useful Bash Alias Examples

Here are some useful aliases for Linux users:

alias home='cd ~'alias ..='cd ..'alias grep='grep --color=auto'alias mkdir='mkdir -p'alias myip='ip addr show'alias disk='df -h'alias mem='free -h'

These aliases help you move faster in the terminal and reduce typing mistakes.

Cybersecurity Alias Examples

For cybersecurity learners, aliases can make common commands easier.

alias openports='ss -tuln'alias authlog='sudo tail -f /var/log/auth.log'alias nmapquick='nmap -T4 -F'alias webheaders='curl -I'

Example usage:

nmapquick 192.168.1.1webheaders https://example.com

These shortcuts are useful for quick checks, but always use security tools only on systems you own or have permission to test.

Remove A Bash Alias

To remove an alias temporarily, use:

unalias ll

To remove a permanent alias, delete it from .bashrc and reload the file:

source ~/.bashrc

Conclusion

Bash aliases are simple shortcuts that make Linux command-line work faster and easier. You can create temporary aliases in the terminal or permanent aliases inside the .bashrc file.

For beginners, learning aliases is a useful step in Bash and Linux productivity. They help reduce repeated typing, improve speed, and create a more comfortable command-line workflow for automation, administration, and cybersecurity tasks.

Cyber Defence

Recent Posts

Install Pip on Ubuntu 18.04: Python 3 and Python 2 Setup Guide

Pip is the official package manager for Python and the standard way to install libraries from…

2 days ago

Install R on Ubuntu 18.04 from CRAN: Statistical Computing Setup

R is an open-source programming language and environment built for statistical computing and data visualization. It…

2 days ago

Install Jenkins on Ubuntu 18.04: CI/CD Server Setup Guide

Jenkins is an open-source automation server that makes it easy to build CI/CD pipelines. Continuous integration…

2 days ago

Install Android Studio on Ubuntu 18.04 with Snap and OpenJDK 8

Android Studio is the official IDE for Android development, built on JetBrains' IntelliJ IDEA platform. It…

2 days ago

Install and Configure GitLab on Ubuntu 18.04 with Omnibus

GitLab is a web-based, open-source Git repository manager written in Ruby. It includes built-in tools for…

2 days ago

Install Anaconda on Ubuntu 18.04: Python Data Science Setup Guide

Anaconda is the most widely used Python distribution for data science and machine learning. It bundles…

3 days ago