alias Command in Linux
Overview
In the Linux ecosystem, an indispensable feature that aids in enhancing productivity is the alias command. The alias command in Linux is a method of reducing typing time by substituting a longer command sequence with a shorter one. This utility not only saves time but also reduces the risk of typing errors.
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Syntax of alias Command in Linux
The basic syntax of the alias command in Linux is as follows:
Where:
- alias: This is the command keyword which signals the interpreter to perform an alias operation.
- name='command': Here, 'name' is the alias name and 'command' is the Linux command string it should represent. The command string must be in quotes.
Options in alias Command in Linux
-
-p: This option prints the list of currently defined aliases.
For example -
Output:
This command will list all the defined aliases in the current shell.
Example Usages
-
Setting an alias for a simple command:
Explanation: This will set the alias 'll' to perform the command 'ls -la'. So, when you type 'll', it will list all the files and directories including hidden ones in long format.
-
Removing an alias:
Explanation: This command will remove the alias 'll' that was previously set.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Tips
-
Aliases are shell-specific and non-permanent. If you want to make them permanent across sessions, you can add them to shell configuration files such as .bashrc, .bash_profile, or .zshrc.
-
Complex commands can also be aliased by enclosing them within single quotes in the alias command.
Advanced Use Cases of alias Command in Linux
-
Create an alias to navigate to a specific directory:
Explanation: This command creates an alias 'project' that changes the current directory to '/home/user/MyProject/' when invoked.
-
Create an alias to show the usage of disk space by each directory:
Explanation: This command sets an alias 'du' that when invoked, shows the disk usage by each directory in the current directory in human-readable format.
-
Create an alias with a pipe and multiple commands:
Explanation: This command creates an alias 'lf' that lists all text files in long format in the current directory.
Conclusion
-
The alias command in Linux is a handy tool to create shortcuts for lengthy or complex command sequences.
-
While the alias command greatly enhances productivity, it is vital to ensure that the alias names don't collide with existing command names.
-
Aliases defined in a session are temporary. To make them permanent, add them to shell configuration files.