SSH aliases allow you to define custom shortcuts (keywords) that execute longer or more complex commands in the SSH terminal. This helps speed up repetitive tasks and reduces typing errors.
For example, instead of typing:
ls -la You can create an alias:
alias lista="ls -la" After this, typing lista will execute ls -la.
Note: Aliases created this way only work for the current SSH session.
Table of Contents
Saving Permanent Aliases
To make aliases persistent, you need to add them to the ~/.bashrc file.
Editing the file
Run:
mcedit ~/.bashrc Then add your aliases, for example:
My aliases
Format: alias name=”command”
Detailed listing
alias ll="ls -la" To save changes:
- Press F2 to save
- Press F10 to exit editor
Apply changes immediately:
source ~/.bashrc Advanced Commands (Functions)
Aliases can also execute multiple commands using functions.
Basic structure:
function_name () {
commands
} Example: create and enter a directory
nkat ()
{
mkdir -p -- "$1" && cd -P -- "$1"
} Usage:
nkat new_folder This will:
- Create a folder
- Immediately move into it
Explanation:
nkat→ function namemkdir→ creates directory$1→ first argument passed to the function&&→ runs next command only if previous succeeds
Example: Running PHP Commands via Alias
You can also wrap application commands:
runapp ()
{
php "$1" path_to_application "$2"
} Example usage:
runapp 7.3 update
This can be used to:
- Select PHP version
- Run a tool (like Composer)
- Pass arguments automatically