In Linux, an alias
is a command that executes another command or series of commands using a different name. Aliases are typically used to make it easier to run frequently used or complex commands by typing a shorter, easier-to-remember version. The alias command takes the following structure:
alias [alias-name]='[command]'
alias
: Invokes thealias
command.alias-name
: An alias is a user-defined string that acts as a reference to a command, with the exception of certain special characters and the words 'alias' and 'unalias'.command
: Specifies the command the alias references.
For example:
alias ll='ls -al'
: This alias creates a new command calledll
that is equivalent to running thels -al
command. You could use this alias to list the contents of a directory in long format by typingll
instead ofls -al
.alias df='df -h'
: This alias creates a new command calleddf
that is equivalent to running thedf -h
command. The-h
flag is used to display the sizes of files in "human-readable" format (e.g., in MB or GB instead of bytes).alias grep='grep --color=auto'
: This alias creates a new command calledgrep
that is equivalent to running thegrep --color=auto
command. The--color=auto
flag tellsgrep
to highlight the matching text in the output, making it easier to spot.alias shutdown='sudo shutdown -h now'
: This alias creates a new command calledshutdown
that is equivalent to running thesudo shutdown -h now
command. The-h
flag tells theshutdown
command to halt the system, and thenow
argument tells it to do so immediately.alias update='sudo apt update && sudo apt upgrade -y'
: This alias creates a new command calledupdate
that is equivalent to running thesudo apt update
andsudo apt upgrade -y
commands. Theupdate
command updates the package manager's list of available packages, and theupgrade
command installs any available updates for installed packages. The-y
flag tellsapt
to assume "yes" as the answer to all prompts.
A few ways I use the alias command in my day to day development:
Copying trading bots from wine
to my documents.
I currently work on Linux but need to do MQL5 programming from time to time. With MQL5, I can write trading bots for clients. However, to compile the MQL5 code to an .ex5
executable, I need to have MT5 installed. MT5 is a Windows and Mac program; therefore, I have to install wine
on Linux. Wine
is a compatibility layer that allows you to run Windows applications on Linux. It does this by translating the Windows application's calls into calls that the Linux operating system can understand and processing them on behalf of the application. This allows you to run Windows applications on Linux without installing a copy of the Windows operating system. Once the code is compiled into an executable, the files are stored in the wine
drive. To copy the .ex5
to a specific folder, I would normally run the following command
cd /home/wamaitha/.wine/drive_c/Program\ Files/Deriv/MQL5
The MQL5
directory has a folder that holds all the trading bots I program. Therefore, I can copy all the .ex5
files to the EAS
folder with the command below.
cp -r Experts/**/*.ex5 ~/Documents/FOREX/EAS
To make my work easier, I've written an alias command that does all this
alias fxeas="cd /home/wamaitha/.wine/drive_c/Program\ Files/Deriv/MQL5 && cp -r Experts/**/*.ex5 ~/Documents/FOREX/EAS"
Activating virtual environments
In Python when using virtualenv
, to activate the environment on Linux we need to type the following command:
source venv/bin/activate
Then navigate back to the project folder
cd .. && cd ..
We can write an alias
for this
alias activate="source venv/bin/activate && cd .. && cd .."
Permanent aliases
Using the alias
command only applies to the current terminal session. To make the commands useful on other terminal sessions, you would need to edit the .bashrc
file if running bash
or the .zshrc
if on zsh
. I'm currently on zsh
, therefore I add these commands at the end of the .zshrc
file.
Launch the .zshrc
using the command below
nano ~/.zshrc
Add the alias
commands at the end of the file
alias activate="source venv/bin/activate && cd .. && cd .."
alias fxeas="cd /home/wamaitha/.wine/drive_c/Program\ Files/Deriv/MQL5 && cp -r Experts/**/*.ex5 ~/Documents/FOREX/EAS"
Run the command below to activate the changes for all terminal sessions.
source ~/.zshrc