Setting Up Aliases - How to Shorten Linux Commands
What Is an Alias?
ls -la --color=auto every single time. Is there a faster way?alias ll='ls -la --color=auto' and from then on, ll does the job.An alias is a way to give a short custom name to a longer command. It reduces typing, prevents typos, and is a standard productivity technique on Linux.
One-liner summary
alias shortname='long command'
That's the whole thing. Try it right now.
1. Basic Usage
1-1. Create an alias
$ alias ll='ls -la'
Once set, you can use it immediately.
$ ll total 48 drwxr-xr-x 5 user user 4096 May 31 19:00 . drwxr-xr-x 3 root root 4096 May 20 10:00 .. -rw-r--r-- 1 user user 220 May 20 10:00 .bash_logout -rw-r--r-- 1 user user 3526 May 20 10:00 .bashrc
Aliases created with the alias command are only active in the current terminal session. They disappear when you close the terminal. See Section 4 for how to make them permanent.
1-2. List all current aliases
$ alias
Running alias without arguments shows all currently active aliases.
alias ll='ls -la' alias grep='grep --color=auto' alias ls='ls --color=auto'
On Ubuntu, aliases for grep and ls are often pre-configured. You can see them with the alias command.
1-3. Check a specific alias
$ alias ll alias ll='ls -la'
2. Useful Alias Examples
2-1. ls shortcuts
alias ll='ls -la' alias la='ls -A' alias l='ls -CF'
la and ll?ls -la shows all files including hidden ones with full details. ls -A also shows hidden files, but skips the . and .. entries. Use whichever fits your need.2-2. Directory navigation
alias ..='cd ..' alias ...='cd ../..' alias ~='cd ~'
Just type .. to go up one directory level.
2-3. Safer file operations
alias cp='cp -i' alias mv='mv -i' alias rm='rm -i'
The -i flag prompts for confirmation before overwriting or deleting.
Watch out in shell scripts
If these aliases are active inside a script, they can cause unexpected interactive prompts. Use \rm or /bin/rm in scripts to bypass aliases and call the command directly.
2-4. Git shortcuts
alias gs='git status' alias ga='git add' alias gc='git commit' alias gp='git push' alias gl='git log --oneline'
gs for git status? That's a huge time-saver since I use it constantly.alias to check the full list.3. Checking and Verifying Aliases
3-1. Check if an alias is defined
$ type ll ll is aliased to `ls -la'
type shows whether a name is a command, alias, function, or built-in. If ll is not defined, you'll see:
$ type ll bash: type: ll: not found
3-2. Run the original command, bypassing an alias
If you have alias rm='rm -i' but want to run rm without confirmation for once:
$ \rm file.txt
Prepending \ tells the shell to use the actual command, not the alias.
4. Making Aliases Permanent
To keep aliases across terminal sessions, add them to ~/.bashrc.
4-1. Edit .bashrc
$ nano ~/.bashrc
Add your aliases at the end of the file:
# My aliases alias ll='ls -la' alias ..='cd ..' alias gs='git status' alias cp='cp -i' alias mv='mv -i' alias rm='rm -i'
4-2. Apply the changes immediately
Editing .bashrc alone does not affect the current terminal. Run:
$ source ~/.bashrc
Or use the shorthand (same effect):
$ . ~/.bashrc
What does source do?
It re-reads .bashrc in the current shell session. New terminals automatically load .bashrc on startup, but source applies changes right away without opening a new terminal.
5. Removing Aliases
5-1. Remove a specific alias
$ unalias ll
5-2. Remove all aliases
$ unalias -a
unalias only removes the alias for the current session. If the alias is in ~/.bashrc, it will come back when you open a new terminal. To permanently remove an alias, delete the line from ~/.bashrc as well.
6. Troubleshooting
ll still isn't working. What's wrong?type ll first and see what it says.$ type ll ll is aliased to `ls -la'
If it's not defined, check the following:
Troubleshooting checklist:
- Did you save
.bashrc? (In nano:Ctrl+O→Enter→Ctrl+X) - Did you run
source ~/.bashrcafter saving? - Is there a syntax error in your alias definition?
Common mistake: spaces around =
# Wrong: spaces around = cause an error alias ll = 'ls -la' # Correct alias ll='ls -la'
The = sign must have no spaces on either side.
Summary
| Task | Command |
|---|---|
| Create an alias | alias ll='ls -la' |
| List all aliases | alias |
| Check a specific alias | alias ll |
| Remove a specific alias | unalias ll |
| Remove all aliases | unalias -a |
| Make aliases permanent | Add to ~/.bashrc, then run source ~/.bashrc |
3 steps to try right now
- Run
alias ll='ls -la'to create an alias - Type
lland confirm it works - Add it to
~/.bashrcand runsource ~/.bashrcto make it permanent