CommandsLinux

How to Create and Use Alias Command in Linux

Introduction:

Alias command is a powerful tool in Linux that allows you to create short and simple alternatives for complex or frequently used commands. Aliases make it easier for you to work with the system by providing shortcuts and simplifying command execution.

Here are 20 examples of creating and using alias commands in Linux:


Create an alias to list all files in the current directory:

alias l="ls -al"

Create an alias to update the system packages:

alias update="sudo apt-get update && sudo apt-get upgrade"

Create an alias to go to the home directory:

alias home="cd ~"

Create an alias to display the IP address:

alias ip="ifconfig | grep 'inet ' | awk '{print $2}'"

Create an alias to check disk usage:

alias du="df -h"

Create an alias to clear the terminal screen:

alias cls="clear"

Create an alias to open the .bashrc file:

alias bashrc="vi ~/.bashrc"

Create an alias to show running processes:

alias ps="ps aux"


Create an alias to restart the network interface:

alias restartnet="sudo systemctl restart network"

Create an alias to search for a specific file:

alias findfile="find / -name"

Create an alias to list listening ports:

alias ports="netstat -tuln"

Create an alias to check system uptime:

alias uptime="uptime"

Create an alias to compress a directory into a tar.gz file:

alias tarcompress="tar -czvf"

Create an alias to change directory to the previous directory:

alias prev="cd -"

Create an alias to display calendar:

alias calendar="cal"

Create an alias to show the current date and time:

alias datetime="date +'%Y-%m-%d %H:%M:%S'"

Create an alias to recursively delete all .log files:

alias dellogs="find . -name '*.log' -type f -delete"

Create an alias to display system information:

alias sysinfo="uname -a"

Create an alias to open the manual page for a command:

alias manpage="man"

Create an alias to show the current user’s home directory:

alias myhome="echo $HOME"

Create an alias to show the contents of a file with line numbers:

alias catn="cat -n"

Feel free to customize and create aliases that suit your needs. These examples demonstrate the flexibility and convenience of using alias commands in Linux.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button