Cybersecurity Updates & Tools

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.