Manjaro Translations:Aliases in .bashrc/3/en

Translations:Aliases in .bashrc/3/en

From Manjaro

Let’s create a simple bash function which will create a directory and then navigate into it:

~/.bashrc
...
mkcd ()
{
  mkdir -p -- "$1" && cd -P -- "$1"
}
...

Now instead of using mkdir to create a new directory and then cd to move into that directory , you can simply type:

user $ mkcd new_directory COPY TO CLIPBOARD


Keeping bash alias in a different file

Bash allows you to add local aliases in your ~/.bashrc file. To do this create a file called ~/.bash_aliases and add these contents in your ~/.bashrc file:

~/.bashrc
...
if [ -e $HOME/.bash_aliases ]; then
    source $HOME/.bash_aliases
fi
...

Now you can add any aliases in your ~/.bash_aliases file and then load them into your Bash session with the source ~/.bashrc command.

Conclusion

This list is not comprehensive. Almost anything that is commonly used can be shortened with an alias

See Also

Bash documentation ArchWiki

Cookies help us deliver our services. By using our services, you agree to our use of cookies.