• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

KaliTut

Kali Linux tutorial and Linux Tips

  • Home
  • Raspberry Pi
  • Privacy Policy
  • About us
  • Affiliate disclaimer

What is Linux alias command and how to use it

by

Linux Command Alias
Most Linux users are well versed in the typing out of lengthy commands in the Terminal. They’re especially hardened and generally insured against such sudden lapses in concentration, where they have to go back mid-command to correct an error.

linux alias command

The rest of us, however, have to deal with the fact that an error is inevitable and that we more often than not have to enter the command again to get it working correctly. There is another option available for Linux users, though. Instead of constantly or frequently having to tap out the complex line of instructions, we can instead use an Alias.

The Alias command isn’t just for Linux, there are examples of it being used via the DOS Key command in the past with DOS and earlier versions of Windows, and more recently appearing in the Windows PowerShell. However, it was introduced back in the old UNIX days and made life significantly simpler for the users of the time.

  • What is an alias in linux?
  • Adding Aliases Permanently
  • Syntax of alias command in linux
    • How to create alias in linux
    • Removing alias from the system
  • how to create a permanent alias in linux

What is an alias in linux?

The Alias command can be issued to replace a common command with a shorter word. So where in Linux the command ‘sudo apt-get install’ needs to be inputted, an alias can be set up so all the user has to do is type in ‘install’, for example. This will then last for as long as the user is in the Terminal for, but they can be set as permanent, which we’ll get into later on.

Aliases in Linux are used to create shortcuts for longer commands, making them easier to remember and quicker to execute. Here are five examples of useful alias commands:

  1. ll for Long Listing with Human-Readable Sizes
alias ll='ls -alF --color=auto'

This alias will list files in the directory in a long format, including hidden files, and display file sizes in a human-readable format with color-coded output.

2. update for System Update

alias update='sudo apt-get update && sudo apt-get upgrade'

This alias simplifies the process of updating and upgrading the system to a single command.

3. grep with Color Output

alias grep='grep --color=auto'

This alias ensures that grep always uses color to highlight matching patterns, making it easier to spot search results.

4. .. for Moving Up One Directory

alias ..='cd ..'

This alias allows you to quickly move up one directory level using the .. command.

5. free for Memory Usage with Human-Readable Output

alias free='free -h'

This alias converts the free command’s output to a human-readable format, making it easier to understand memory usage.

Adding Aliases Permanently

To make these aliases permanent, you can add them to your shell configuration file (e.g., ~/.bashrc for Bash or ~/.zshrc for Zsh). For example:

# Open the .bashrc file with a text editor
nano ~/.bashrc

# Add your aliases at the end of the file
alias ll='ls -alF --color=auto'
alias update='sudo apt-get update && sudo apt-get upgrade'
alias grep='grep --color=auto'
alias ..='cd ..'
alias free='free -h'

# Reload the .bashrc file to apply changes
source ~/.bashrc

Now, these aliases will be available in every terminal session.

Create an alias, aliases allow a string to be substituted for a word when it is used as the first word of a simple command.

Syntax
alias [-p] [name[=value] …]
unalias [-a] [name … ]
Key
-p Print the current values
-a Remove All aliases

If arguments are supplied, an alias is defined for each name whose value is given.
If no value is given, alias will print the current value of the alias.

Without arguments or with the -p option, alias prints the list of aliases on the standard output in a form that allows them to be reused as input.

The value cannot contain any positional parameters ($1 etc), if you need to do that use a shell function instead.

The name may not be ‘alias’ or ‘unalias’.
unalias may be used to remove each name from the list of defined aliases.

Make an alias permanent
Use your favorite text editor to create a file called /.bash_aliases, and type the alias commands into the file.
.bash_aliases will run at login (or you can just execute it with ..bash_aliases )

Expand Multiple aliases
If the last character of the alias value is a space or tab character, then the next command word following the alias is also checked for alias expansion.

Examples: Create an alias ‘c’ that will clear the screen:

alias c='clear'

Syntax of alias command in linux

How to create alias in linux

In general, the creation of alias is as follows:

alias name=value
alias name='command'
alias name='command arg1 arg2'
alias name='/path/to/script'
alias name='/path/to/script.pl arg1'

That is, we write the name of the alias, put the “=” sign, then indicate the command or list of commands in quotation marks with arguments. Instead of console commands, we can specify the path to the script with or without arguments. Let’s look at examples.

In order to completely update the system, we need to enter the commands:

sudo apt update && sudo apt full-upgrade

Each time to write this for a long time, we can create an alias:

alias upd='sudo apt update && sudo apt full-upgrade'
syntax of alias command in linux

Let’s redefine the ping command by setting the parameter so that only 4 packets are sent when it is used:

alias ping='ping -c 4
alias linux command

How to invoke a command that has been overridden by alias.
But what if we want to use the old ping command? This can also be done, you need to enter the backslash “” before the command:

\ping kalitut.com

In addition, in addition to the backslash, there are other ways to call the original command:

"ping"
'ping'
command ping[

That is, by enclosing in quotation marks or by entering the keyword “command” before the command.

Removing alias from the system

The unalias command and the alias name are used for deletion.linux remove alias In general terms, it looks:

unalias name

For example, I mistakenly added alias: X and i want to remove it i would type this comman

unalias X

and if you want to delete all aliases; for this, use the command:

unalias -a

That is, with the -a option .

Note:After closing the terminal, all our aliases (aliases, aliases) are deleted, except for system ones. That is, these aliases exist only within the framework of the current terminal session.

If you added alias in one tab (window) of the terminal on another tab (in another terminal session), the system knows nothing about this alias but this can be solved by creating permanent aliases.

how to create a permanent alias in linux

permanent alias linux I’ll go from afar, in the user’s home directory there is a file .bashrc This file is used in the system when this user is authorized. That is, our login. There are lines in this file:

# Alias definitions.
You may want to put all your additions into a separate file like
~/.bash_aliases, instead of adding them here directly.
See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

This means that if the .bash_aliases file exists, then it is used in the system. We will create this file and write to it a list of our aliases so that they are always available. But unlike Kali Linux or Ubuntu, for example, in Linux Mint this entry may be missing, so add these lines to your .bashrc at the end of the file.

In order not to restart the system and the changes to this file are applied, we execute the command:

sudo mousepad .bashrc

We figured it out. Let’s create a ~/bash_aliases file. It can be created in the file manager, superuser rights are not required. Or we enter in the terminal:

mousepad ~/.bash_aliases

In this file, insert the list of aliases that we consider necessary:

How to create alias command in unix permanently

Save the file, If everything was done correctly, now these aliases will be available in any terminal window of the current user. And also after reboot will be available.

This article has been detailing the creation of alias in Kali linux. If you use this convenient tool, you can share your set of aliases in the comments.

For more linux command check Linux basic commands

Post Views: 804

Filed Under: Linux Commands Tagged With: alias command

Reader Interactions

Comments

  1. auser says

    November 27, 2021 at 10:45 pm

    make sure your user uses bash. check on /etc/passwd
    if it uses zsh u have to config .zsh

    Reply
  2. Herzeleid says

    January 21, 2022 at 5:57 pm

    auser, thanks – you helped a lot :D

    Reply

Leave a Reply Cancel reply

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

Primary Sidebar

Follow us

  • Facebook
  • Twitter
  • YouTube

Categories

  • algorithm
  • Android Ai coding
  • Android pentesting tools
  • Arduino
  • Artificial Intelligence
  • Books
  • ChatGPT Prompt
  • Darknet
  • database
  • General
  • Github Tools
  • Hacking
  • Kali Linux
  • Linux
  • Linux Commands
  • Network Administrator
  • Penetration Testing
  • Penetration Testing Tools
  • PowerShell
  • Raspberry Pi
  • resources
  • Review
  • Termux
  • Tutorials
  • Ubuntu
  • Uncategorized
  • Video Tutorials
  • vmware
  • WiFi Adapter
  • WiFi Pentesting
  • Wireless Router
  • Wireshark

Recent Posts

  • Shannon – The AI Pentesting Tool That Finds Real Exploits
  • Transforming Photos with ChatGPT Prompt : A Cinematic Double Exposure in a Post-Apocalyptic World
  • Stryker Android App: Your Mobile Pentesting Powerhouse
  • Alfa awus036ach review
  • Alfa AWUS1900 for Wireless Penetration Testing

Footer

Kalitut

Kalitut.com goal is to share the knowledge for free, help you find the best tools on the web and provides tutorials

Find us on social media

  • Facebook
  • Pinterest
  • Reddit
  • Twitter
  • YouTube

Copyright © 2026

  • Home
  • About us
  • Privacy Policy
  • Affiliate disclaimer