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: Invokes the
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.
alias ll='ls -al': This alias creates a new command called
llthat is equivalent to running the
ls -alcommand. You could use this alias to list the contents of a directory in long format by typing
alias df='df -h': This alias creates a new command called
dfthat is equivalent to running the
df -hcommand. The
-hflag 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 called
grepthat is equivalent to running the
grep --color=autocommand. The
grepto highlight the matching text in the output, making it easier to spot.
alias shutdown='sudo shutdown -h now': This alias creates a new command called
shutdownthat is equivalent to running the
sudo shutdown -h nowcommand. The
-hflag tells the
shutdowncommand to halt the system, and the
nowargument tells it to do so immediately.
alias update='sudo apt update && sudo apt upgrade -y': This alias creates a new command called
updatethat is equivalent to running the
sudo apt updateand
sudo apt upgrade -ycommands. The
updatecommand updates the package manager's list of available packages, and the
upgradecommand installs any available updates for installed packages. The
aptto 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
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:
Then navigate back to the project folder
cd .. && cd ..
We can write an
alias for this
alias activate="source venv/bin/activate && cd .. && cd .."
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 using the command below
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.