Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

Linux IntroductionChapter 6. Commands for Command Management

alias (Create Command Shortcuts)

alias (Create Command Shortcuts)

Creating Command Shortcuts with alias

The alias command is used to create command shortcuts. You can use the command to shorten your typing for frequently used commands or long complex commands. You can even combine multiple commands into one alias command.

Display registered alias

By running the alias command without any argument, you can display a registered alias. For example, when you run the alias command on Ubuntu OS on AWS Lightsail, you can see preregistered aliases.

Command Line - INPUT
alias
Command Line - RESPONSE
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

One of the most commonly used commands, alias ll, has already been registered. When you run the ll alias command, you can see the same result as when you run the ls -l command.

Command Line - INPUT
ll
Command Line - RESPONSE
total 72
drwxr-xr-x  19 root root  4096 Jan  8 08:29 ./
drwxr-xr-x  19 root root  4096 Jan  8 08:29 ../
lrwxrwxrwx   1 root root     7 Jul 16  2020 bin -> usr/bin/
drwxr-xr-x   3 root root  4096 Jan  8 09:11 boot/
drwxr-xr-x  15 root root  3180 Jan  5 13:52 dev/
:

Create a new alias

To create a new alias, you need to define an alias name and a command to be assigned to it. Use quotation marks to create an alias for a command with arguments separated by one or more spaces. For example, to create a new alias named md1 that executes "mkdir dir_1", run the command below.

Command Line - INPUT
alias md1="mkdir dir_1"

Run the alias and check the result with the ls command.

Command Line - INPUT
md1
ls
Command Line - RESPONSE
dir_1

Create a new alias with multiple commands

To create a new alias with multiple commands, use ; (semicolon) to combine commands. The example below shows how to create a new alias named mdfa to execute two commands – mkdir and touch.

Command Line - INPUT
alias mdfa="mkdir dir_a;touch dir_a/file_a"

Run the command and check the results with the ls command.

Command Line - INPUT
mdfa
ls
Command Line - RESPONSE
dir_1  dir_a
Command Line - INPUT
ls dir_a
Command Line - RESPONSE
file_a

You can also check how the commands are registered by running the alias command.

Command Line - INPUT
alias
Command Line - RESPONSE
:
alias ls='ls --color=auto'
alias md1='mkdir dir_1'
alias mdfa='mkdir dir_a;touch dir_a/file_a'

Delete an existing alias

To delete an existing alias, you can use the unalias command.
Delete alias md1.

Command Line - INPUT
unalias md1

Check if it was deleted by running the alias command.

Command Line - INPUT
alias
Command Line - RESPONSE
:
alias ls='ls --color=auto'
alias mdfa='mkdir dir_a;touch dir_a/file_a'

You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Building User Management Functions: Django Approaches

Approaches to Building User Management Functions in Django

Copying Files and Directories with cp Command

cp (Copy File and Directory)

Execute Shell Scripts with source

source (Execute Shell Script and Refresh Environmental Variables)

Why Use Visual Studio Code for Django Coding

Install Visual Studio Code

Understanding Redirection, Pipe, and Shell Scripting

Chapter 5. Redirection, Pipe and Shell Script

Building User Management Functions: Django Approaches

Approaches to Building User Management Functions in Django

Copying Files and Directories with cp Command

cp (Copy File and Directory)

Execute Shell Scripts with source

source (Execute Shell Script and Refresh Environmental Variables)

Why Use Visual Studio Code for Django Coding

Install Visual Studio Code

Understanding Redirection, Pipe, and Shell Scripting

Chapter 5. Redirection, Pipe and Shell Script

Tags:

Linux Command

Linux Introduction
Course Content

Chapter 1. Linux Basics

What Is OS?

CUI and GUI

Linux Distributions

Package Manager

Kernel and Shell

Current Working Directory

Linux Directory Structure

Absolute Path and Relative Path (Linux OS)

Linux Command Syntax

Special Characters and Escape Character

Chapter 2. Linux Key Commands

Setting Up Linux Environment on AWS

pwd (Print Working Directory)

cd (Change Directory)

ls (List Contents of Directory)

mkdir (Make Directory)

rmdir (Remove Directory)

touch (Create File)

rm (Remove File)

mv (Move File and Directory)

cp (Copy File and Directory)

cat (Display File Content)

sort (Sort File Contents)

grep (Global Regular Expression Print)

Regular Expression

find (Find File and Directory)

Wildcard

ln (Create Link to File and Directory)

Chapter 3. Vim Editor

What Is Vim and How to Launch It?

Normal, Insert and Visual Mode

Normal Mode (1) – Move Cursor

Normal Mode (2) – Delete

Normal Mode (3) – Copy and Paste

Normal Mode (4) – Undo and Redo

Normal Mode (5) – Search Phrase

Normal Mode (6) – Replace Phrase

Normal Mode (7) – Save and Exit

Insert Mode

Visual Mode

Chapter 4. User, Group and Permission

What Are User, Group And Permission in Linux?

Permission (Access Mode) by Owner Status

Superuser (Root User) vs. Normal User

sudo (Run Command with Superuser Privileges)

su (Switch User)

useradd (Add User)

passwd (Set Password)

userdel (Delete User)

Group – Primary Group and Secondary Group

groupadd (Add Group)

usermod (Modify User Account Information)

gpasswd (Add and Delete Users to Group)

groupdel (Delete Group)

chown (Change Owner of File and Directory)

chgrp (Change Group of File and Directory)

chmod (Change Access Mode)

chmod Command with Numbers

w and who (Check Current User Login Status)

id and groups (Check User ID and Group)

getent (Display User and Group Data)

Chapter 5. Redirection, Pipe and Shell Script

Standard Input Output and Redirection

Pipe (Combine Commands)

less (Display Content with Pager)

tr (Replace Characters)

cut (Extract Data Sections)

uniq (Extract Unique Data Lines)

Shell Script

echo (Echo input)

read (Read and Store Input)

Shell Variable and Environmental Variable

source (Execute Shell Script and Refresh Environmental Variables)

Chapter 6. Linux Commands for Command Management

history (Check Command History)

alias (Create Command Shortcuts)

man (Display Manual)

type, which and whereis (Display Command Information)

Package Manager Command

tree (Display Directory Tree)

Chapter 7. SSH Remote Connection

SSH (Secure Shell)

Locate .ssh Directory

SSH Remote Login (1) – Use Key Pair Generated by Server

SSH Remote Login (2) – Use Key Pair Generated by Client

SSH Config File

SSH Remote Login with Visual Studio Code

SCP (Secure Copy Protocol)

SCP with SSH Config File

SFTP (Secure File Transfer Protocol)

Other File Transfer Commands

Chapter 8. Linux Process Management

Process and Job

Foreground and Background Jobs

jobs and ps (Display Jobs and Processes)

Signals

Create, Stop and Terminate Jobs

Daemon Processes

What Is Service on Linux?

Systemd

Unit File

Systemctl Sub-Commands

Create Custom Unit and Start at Boot

Firewall

UFW (Uncomplicated Firewall)

Web Server

Launch Apache Web Server

Chapter 1. Linux Basics

What Is OS?

CUI and GUI

Linux Distributions

Package Manager

Kernel and Shell

Current Working Directory

Linux Directory Structure

Absolute Path and Relative Path (Linux OS)

Linux Command Syntax

Special Characters and Escape Character

Chapter 2. Linux Key Commands

Setting Up Linux Environment on AWS

pwd (Print Working Directory)

cd (Change Directory)

ls (List Contents of Directory)

mkdir (Make Directory)

rmdir (Remove Directory)

touch (Create File)

rm (Remove File)

mv (Move File and Directory)

cp (Copy File and Directory)

cat (Display File Content)

sort (Sort File Contents)

grep (Global Regular Expression Print)

Regular Expression

find (Find File and Directory)

Wildcard

ln (Create Link to File and Directory)

Chapter 3. Vim Editor

What Is Vim and How to Launch It?

Normal, Insert and Visual Mode

Normal Mode (1) – Move Cursor

Normal Mode (2) – Delete

Normal Mode (3) – Copy and Paste

Normal Mode (4) – Undo and Redo

Normal Mode (5) – Search Phrase

Normal Mode (6) – Replace Phrase

Normal Mode (7) – Save and Exit

Insert Mode

Visual Mode

Chapter 4. User, Group and Permission

What Are User, Group And Permission in Linux?

Permission (Access Mode) by Owner Status

Superuser (Root User) vs. Normal User

sudo (Run Command with Superuser Privileges)

su (Switch User)

useradd (Add User)

passwd (Set Password)

userdel (Delete User)

Group – Primary Group and Secondary Group

groupadd (Add Group)

usermod (Modify User Account Information)

gpasswd (Add and Delete Users to Group)

groupdel (Delete Group)

chown (Change Owner of File and Directory)

chgrp (Change Group of File and Directory)

chmod (Change Access Mode)

chmod Command with Numbers

w and who (Check Current User Login Status)

id and groups (Check User ID and Group)

getent (Display User and Group Data)

Chapter 5. Redirection, Pipe and Shell Script

Standard Input Output and Redirection

Pipe (Combine Commands)

less (Display Content with Pager)

tr (Replace Characters)

cut (Extract Data Sections)

uniq (Extract Unique Data Lines)

Shell Script

echo (Echo input)

read (Read and Store Input)

Shell Variable and Environmental Variable

source (Execute Shell Script and Refresh Environmental Variables)

Chapter 6. Linux Commands for Command Management

history (Check Command History)

alias (Create Command Shortcuts)

man (Display Manual)

type, which and whereis (Display Command Information)

Package Manager Command

tree (Display Directory Tree)

Chapter 7. SSH Remote Connection

SSH (Secure Shell)

Locate .ssh Directory

SSH Remote Login (1) – Use Key Pair Generated by Server

SSH Remote Login (2) – Use Key Pair Generated by Client

SSH Config File

SSH Remote Login with Visual Studio Code

SCP (Secure Copy Protocol)

SCP with SSH Config File

SFTP (Secure File Transfer Protocol)

Other File Transfer Commands

Chapter 8. Linux Process Management

Process and Job

Foreground and Background Jobs

jobs and ps (Display Jobs and Processes)

Signals

Create, Stop and Terminate Jobs

Daemon Processes

What Is Service on Linux?

Systemd

Unit File

Systemctl Sub-Commands

Create Custom Unit and Start at Boot

Firewall

UFW (Uncomplicated Firewall)

Web Server

Launch Apache Web Server