How to Add Alias in Linux Permanently
If you want to know how to add alias in linux permanently, the usual answer is to put the alias in your shell startup file, such as .bashrc for Bash or .zshrc for Zsh, then reload the file or open a new terminal. That makes the alias available every time you start an interactive shell, instead of only for the current session.
What a permanent Linux alias means
An alias is a shortcut for a longer command. For example, you might create ll as a shortcut for ls -alF. A permanent alias is one that loads automatically each time your shell starts, so you do not have to type it again after closing the terminal or rebooting.
In Linux, aliases are usually defined in shell configuration files, not in a system-wide program setting. The exact file depends on the shell you use.
How to add an alias for the current session
Before making anything permanent, it helps to test the alias in your current terminal.
- Open a terminal.
- Run the alias command in the format
alias name='command'.
Example:
alias ll='ls -alF'This works right away, but only for the current terminal session. Once you close that terminal, the alias disappears unless you save it in a startup file.
Make the alias permanent in Bash
If you use Bash, the most common place to store personal aliases is ~/.bashrc. On some systems, aliases may also be placed in ~/.bash_aliases if that file is loaded from .bashrc.
Option 1: Add the alias directly to .bashrc
- Open the file in a text editor.
nano ~/.bashrc- Add your alias near the end of the file.
alias ll='ls -alF'
alias gs='git status'- Save the file and close the editor.
- Reload the file in the current terminal.
source ~/.bashrcAfter that, the alias should be available in new Bash terminals too.
Option 2: Use .bash_aliases
Some users prefer to keep aliases separate from other shell settings. If your .bashrc already includes .bash_aliases, you can put aliases there instead.
Typical setup:
nano ~/.bash_aliasesAdd your aliases:
alias ll='ls -alF'
alias update='sudo apt update && sudo apt upgrade'If your system does not already load .bash_aliases, you may need to add this to ~/.bashrc:
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fiThat way, Bash reads your alias file automatically when a new interactive shell starts.
Make the alias permanent in Zsh
If you use Zsh, place aliases in ~/.zshrc.
- Open the file.
nano ~/.zshrc- Add the alias.
alias ll='ls -alF'
alias cls='clear'- Save the file.
- Reload it.
source ~/.zshrcNew Zsh terminals should now recognize the alias automatically.
Reload your shell config without restarting
You do not need to log out or reboot to test a permanent alias. After editing the file, reload it in the same shell with the source command.
source ~/.bashrcor
source ~/.zshrcYou can also open a new terminal window, which forces the shell to read its startup file again.
Verify that the alias works
It is a good idea to confirm that the shell sees the alias before assuming the setup is correct.
Check with alias
alias llThis prints the alias definition if it exists.
Check with type
type llThis tells you whether the shell recognizes ll as an alias, function, built-in, or external command.
Try the command directly
llIf the alias is loaded correctly, the shortcut should run the command you defined.
Where to put aliases in Linux
The right file depends on the shell and how your terminal session starts. Here is a quick reference.
| Shell | Common file | Typical use |
|---|---|---|
| Bash | ~/.bashrc | Interactive terminal sessions |
| Bash, optional | ~/.bash_aliases | Alias-only file, usually loaded from .bashrc |
| Zsh | ~/.zshrc | Interactive Zsh sessions |
If you are unsure which shell you are using, run:
echo $SHELLKeep in mind that the shell shown there is your login shell, not always the shell currently running in a given terminal. If needed, check with:
echo $0Common problems and fixes
Most alias problems come down to one of a few simple issues.
The alias works only in one terminal
That usually means you defined it in the current session but did not add it to a startup file. Put the alias in .bashrc, .bash_aliases, or .zshrc, depending on your shell.
The alias is not available in new terminals
Your shell may not be reading the file where you saved it. Make sure you edited the correct startup file, and check that the file contains the line that loads your alias file if you used .bash_aliases.
The alias is inside a script
Aliases are mainly for interactive shells. They are often not expanded in scripts or non-interactive commands unless special shell options are used. If you need reusable logic in a script, a shell function or a script file is usually a better choice.
The alias contains spaces or special characters
Use single quotes around the command part when possible:
alias gs='git status'If you need nested quotes, be careful with escaping so the shell reads the line correctly.
sudo seems to ignore the alias
That is normal. sudo runs a command with elevated privileges and does not rely on your shell alias in the usual way. If you need a shortcut for an admin command, define the alias for the exact command you run, but do not assume it will rewrite how sudo behaves.
Alias vs function vs script
An alias is best for short substitutions. If your command needs arguments, logic, or multiple lines, a shell function is often better. If the task is more complex or should be reusable across systems, a script is usually the cleanest option.
| Tool | Best for | Limitations |
|---|---|---|
| Alias | Short command shortcuts | Poor for complex logic or parameters |
| Function | Commands with arguments or simple logic | More verbose than an alias |
| Script | Reusable automation or longer workflows | Requires a file, permissions, and sometimes PATH setup |
A practical rule is simple: use an alias for convenience, a function for flexibility, and a script for real automation.
Quick example for everyday use
If you want a common productivity setup, you might add these lines to your shell config file:
alias ll='ls -alF'
alias la='ls -A'
alias cls='clear'
alias ..='cd ..'After saving the file and running source ~/.bashrc or source ~/.zshrc, the shortcuts will stay available each time you open a terminal.
Frequently Asked Questions About how to add alias in linux permanently
How do I make an alias permanent in Linux?
Add the alias to your shell startup file, such as ~/.bashrc for Bash or ~/.zshrc for Zsh, then reload the file or open a new terminal.
Where do I put aliases in Linux?
For Bash, use ~/.bashrc or ~/.bash_aliases if your system loads it. For Zsh, use ~/.zshrc.
Why is my Linux alias not working after reboot?
Usually the alias was not saved in the correct startup file, or the file is not being loaded when the shell starts. Check the shell you are actually using and confirm the alias line is present.
Should I put aliases in .bashrc or .bash_aliases?
Either works for Bash. .bashrc is the simplest choice, while .bash_aliases can be useful if you want to keep aliases separate from other shell settings.
How do I reload aliases without restarting the terminal?
Run source ~/.bashrc or source ~/.zshrc, depending on your shell. That loads the updated alias definitions into the current session.
Do aliases work in scripts?
Usually not in the same way they do in interactive terminals. For scripts, use functions or full command names instead of relying on aliases.
Conclusion
The most reliable way to set up a permanent Linux alias is to add it to the right shell startup file, then reload that file to test it immediately. Use .bashrc or .bash_aliases for Bash, and .zshrc for Zsh. If an alias does not persist, the issue is usually the wrong file, the wrong shell, or a case where a function or script would be a better fit.
