Fundamentals 3 min read

Master Bash Aliases: How to View, Define, and Persist Command Shortcuts

Learn how to use the Linux bash alias command to create, list, and manage command shortcuts, understand its temporary nature, and make aliases permanent by editing the appropriate initialization files such as /etc/bashrc or ~/.bashrc, with practical examples included.

Open Source Linux
Open Source Linux
Open Source Linux
Master Bash Aliases: How to View, Define, and Persist Command Shortcuts

alias: View and Define Aliases

Function Description

The alias command is used to set shortcuts for other commands. When defining an alias, enclose the original command in single quotes to prevent special characters from causing errors.

Aliases created with alias only last for the current login session. To make them available at every login, place the alias definitions in Bash initialization files such as /etc/bashrc or ~/.bashrc .

Command Syntax

alias [alias_name]=[command_to_alias]

Common Options

-p: Print the currently defined command aliases

Parameter Examples

(1) View system-defined aliases:

# alias -p
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

(2) Set an alias for a command:

# alias ok='ls -l /bin'
# ok
lrwxrwxrwx. 1 root root 7 Aug 29 00:49 /bin -> usr/bin

Key Points

Aliases set directly in the shell disappear when the terminal is closed or the system is rebooted. To make them permanent, edit ~/.bashrc (for the current user) or /etc/bashrc (for all users) and add the alias definitions, then run source ~/.bashrc or restart the shell.
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

SysadminBashcommand-lineAlias
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.