How to Make Custom Commands for Linux Terminal?
Last Updated :
14 Oct, 2024
With commands, users can communicate with the operating system via the Linux terminal, a handy tool. Although the terminal has several pre-defined commands, you can improve productivity and optimize processes by writing your custom commands. This article explains how to write and use custom commands in the Linux terminal to personalize and enhance your experience.
What Are Custom Commands?
User-defined scripts or shortcuts that carry out particular actions in the terminal are called custom commands. They can automate tedious chores, simplify complicated command sequences, or add functionality to existing commands. Users can increase their overall efficiency and save time when using the terminal by writing custom commands.
Creating Custom Command for Linux Terminal
1. Making Use of Aliases
The easiest method for creating custom commands in Linux is to use aliases. With them, you can create a shortcut for an already-existing combash: cd: Videos: No such file or directory
ubuntu $mand or set of commands. This is how an alias is made:
- Get your terminal open.
- To create an alias, use the syntax as follows:
Command: alias shortcut_name='command_to_run'
For example, if you frequently use ls -la
To list files in detail, you can create an alias like this:
Command: alias ll='ls -la'

Custom Command
Add this alias to your shell configuration file (e.g., ~/.bash_aliases or ~/.bashrc) to make it permanent. Run source ~/.bashrc after making modifications to the file.
2. Creating Programs in Shell
Shell scripts can be used to construct more intricate custom commands. A shell script is a file that the terminal can run that contains a list of commands. This is how to make one:
1. Create a New Script File: To make a new script file, use a text editor. As an illustration:
Command: nano myscript.sh
2. Add Shebang Line: At the top of the file, add the shebang line to specify the script interpreter:
Command: #!/bin/bash
3. Add Commands: Write the commands you want to execute in the script. For example:
Command:
#!/bin/bash
echo "Hello, World!"
date
4. Make the Script Executable: Save the file and exit the editor. Then, make the script executable with the following command:
Command: chmod +x myscript.sh
5. Run the Script: Execute the script by typing:
Command: ./myscript.sh
3. Making Use of Functions
You can also write custom commands inside your shell using functions. They are very handy when generating more complex instructions with parameters. How to build a function is as follows:
1. Open Your Shell Configuration File: Edit your ~/.bashrc
or ~/.bash_profile
.
2. Define the Function: The syntax for creating a function is as follows:
my_function() {
command1
command2
}
For example, to create a function that backs up a directory, you could write:
backup() {
tar -czf "$1_backup.tar.gz" "$1"
}
3. Save and Source the File: Save the changes and run source
~/.bashrc
to apply them.
4. Use the Function: You can now use your custom function like this:
backup my_directory
Customizing Your Terminal Experience
1. Developing Unique Git Commands
If you use Git regularly, you can write custom commands to make repetitive activities easier. For instance, you could write a function that logs in with a single command and checks the status:
Command:
git_status_log() {
git status
git log --oneline
}
2. Combining Multiple Commands
You can combine multiple commands into a single custom command. For instance, if you often navigate to a directory and list its contents, you can create a function:
Command:
go_and_list() {
cd "$1" && ls -la
}
3. Using Custom Commands in Scripts
You can also call your custom commands or scripts within other scripts. This allows you to build complex workflows by combining various commands and scripts.

Custom Commands for Linux Terminal
Conclusion
Developing personalized commands for the Linux terminal can significantly increase your efficiency and improve your enjoyment of using the command line. Shell scripts, functions, and aliases can help you automate repetitive activities and improve processes. As you gain more experience with custom commands, there are a plethora of methods to customize the terminal to meet your unique requirements, which will ultimately increase your task management efficiency.
How to Make Custom Commands for Linux Terminal – FAQs
How do I view my current aliases?
You can view your current aliases by typing alias in the terminal. This will list all defined aliases.
Can I create custom commands for any shell?
Yes, while this article primarily focuses on Bash, you can create custom commands in other shells like Zsh or Fish, but the syntax may vary.
What is the difference between aliases and functions?
Aliases are simpler and typically used for single commands or command sequences, while functions can include multiple commands and accept parameters.
How can I remove an alias?
You can remove an alias by using the unalias command followed by the alias name, for example: unalias ll.
Are custom commands persistent across sessions?
To make custom commands persistent, you must define them in your shell configuration file (like ~/.bashrc or ~/.bash_profile) and then source the file or restart your terminal.
Get 90% Course fee refund on completing 90% course in 90 days! Take the Three 90 Challenge today.
The next 90 Days of focus & determination can unlock your full potential. The Three 90 challenge has started and this is your chance to upskill and get 90% refund. What more motivation do you need? Start the challenge right away!
Similar Reads
How To Create Custom Theme for Windows Terminal?
Every operating system should have some sort of place where users can execute some commands. Commands are a very important element while using any operating system. Every technique of the operating system can't be known by all users. There might be some processes that need to be executed by the commands. For all these reasons, all operating systems
4 min read
Terminal Mail and Linux Security Mail
One great feature, among others, is the ability to manage emails directly from the terminal under Linux. Many users utilize this for effectiveness and control. Therefore, you, being a system administrator or developer, should be in a position to handle terminal mail in Linux, and part of that would be to ensure improved Linux email security. This a
4 min read
How to Unzip .tgz File Using the Linux Terminal?
If you’ve come across a .tgz file and are unsure how to access its contents, you’re not alone. Knowing how to extract or unzip a .tgz file in a Linux environment can be highly useful, especially when handling compressed files for software installations, backups, or data transfers. Here, we will walk you through the steps to easily unzip .tgz files
6 min read
How to Browse From the Linux Terminal Using W3M?
W3M is an open-source text-based terminal web browser for Linux used to browse through the terminal. It is simple to use and do not require any additional interacting interface application though it interacts through the terminal. It renders the web pages in a form as their original layout. How to Install W3M? As W3M is not included by default on m
1 min read
Using Lynx to Browse the Web From the Linux Terminal
Lynx is a terminal-based web browser for all Linux distributions. It shows the result as plain text on the terminal. It is a classic non-graphical text-mode web browser which displays the pages on the terminal. Lynx does not load images and multimedia contents, hence it is fast as compared to other browsers. One who do not want so many images and m
2 min read
Basic System Controls with Terminal in Linux
Sometimes, basic system services stop working or malfunction, and it becomes challenging to resolve these issues via a Graphical User Interface (GUI). In such situations, terminal commands can be a reliable alternative to control and manage system services manually. Below is a guide to essential terminal commands that help control system services l
3 min read
How to Clear the Terminal History in Linux
The Linux Terminal stores every command you execute in a history file like .bash_history for Bash or .zsh_history for Zsh, making it convenient to access previous commands. However, this history can become a privacy or security issue, especially when dealing with sensitive tasks or working on shared systems.In this article, we’ll explore four effec
6 min read
What is a Controlling Terminal in Linux?
Most of you should be aware of the Terminal in Linux which is a Command-line Interface. However, there are very few individuals who know about the existence of Linux Controlling Terminal.If you are a System Administrator, or a user who interacts with Linux Systems, then knowing about Controlling the Terminal on Linux is very important. This article
5 min read
How Can I do Ctrl + C in the Linux Terminal
If you’re trying to copy text from the Linux terminal, pressing Ctrl + C might not give you the results you expect—it’s designed to stop commands, not copy text. Instead, to copy from the terminal, use Ctrl + Shift + C. This shortcut ensures you can easily select and copy output or commands without disrupting terminal processes.In this guide, we’ll
4 min read
How to Download File on Linux Terminal
Downloading file on Linux is a basic operation, and the right command-line tool makes a huge impact in terms of speed, efficacy, and customization. While the graphical interface for simple downloads, CLI-based programs like wget, curl, axel, and aria2 come with features of parallel downloading, authentication, bandwidth limiting, as well as support
7 min read