If you’re a Linux user, you’ve probably heard of the bashrc file. This file allows you to customize your bash shell, including setting up aliases to make your life easier. An alias is a shortcut for a longer command, allowing you to execute a command with just a few keystrokes.
One way to set up aliases is to edit your bashrc file. To do this, open a terminal and enter the following command:
This will open the bashrc file in the nano text editor. From here, you can add your aliases. For example, let’s say you frequently visit the website itvraag.nl. You can create an alias for this by adding the following line to your bashrc file:
alias itvraag='firefox itvraag.nl'
Now, whenever you want to visit itvraag.nl, you can simply enter the command “itvraag” in your terminal and it will open the website in Firefox.
After applying any changes to bashrc file you’ll need to reload it using the
source command followed by the path to the bashrc file. For example:
This will execute the commands in the bashrc file, allowing you to apply any customizations or settings that you have defined. Keep in mind that the bashrc file is only sourced when you start a new bash session, so you will need to use the
source command anytime you make changes to the file and want them to take effect immediately.
Here’s another example. Let’s say you want to create an alias for quickly creating a new directory and moving into it. You can do this with the following alias:
alias mkcd='mkdir $1 && cd $1'
Now, you can create a new directory and move into it by entering the command “mkcd [directory name]”. For example:
This will create a new directory called “itvraag” and move you into it.
There are many other ways you can use aliases to increase your productivity and efficiency. Here are five examples:
Create an alias for quickly checking your system resources. For example:
alias sysinfo='top -n1 -b'
Create an alias for quickly accessing a frequently used directory. For example:
alias docs='cd /home/user/documents'
Create an alias for quickly finding a file. For example:
alias findfile='find . -name "itvraag*"'
Create an alias for quickly killing a process. For example:
alias killproc='kill -9 [pid]'
Create an alias for quickly restarting a service. For example:
alias restartservice='systemctl restart [service name]'
Keep in mind when using aliases to choose descriptive names that are easy to remember. This will make it easier to use your aliases and increase your productivity even further.
One thing that many people don’t know about aliases and bashrc is that you can use them to create custom functions. For example, the following bash function will retrieve the IP address of the domain
itvraag.nl using the
dig command and save it to a variable called
ip_address=$(dig itvraag.nl +short)
The most important thing to keep in mind when using aliases and bashrc is that they are specific to your user account, so you will need to set them up for each user that needs access to them.
Here are some examples of how you can use aliases and bashrc to increase your productivity and efficiency:
Create an alias for frequently used commands:
alias ll='ls -l'
This alias allows you to use the
ll command to list the contents of a directory in long format, instead of typing out the full
ls -l command every time.
Set up a bash function to perform a series of tasks:
npm run build
This function combines the
npm install, and
npm run build commands into a single function that can be executed with the
Use bashrc to customize your prompt:
This setting will change your prompt to include your username, hostname, and current working directory, making it easier to navigate your file system.
Create an alias for a command with arguments:
alias ws='ssh -L 8000:itvraag.nl:80'
This alias sets up an SSH tunnel to
itvraag.nl on port 80, allowing you to access the website locally at
Use bashrc to set up environment variables:
This setting will ensure that the
nano text editor is used whenever a command prompts you to edit a file.
It’s also worth noting that the bashrc file is specific to the bash shell, so these customizations will only apply when you are using bash. If you are using a different shell, such as zsh or fish, you will need to set up your customizations in the appropriate configuration file for that shell.
By using aliases and bashrc, you can streamline your workflow and save time on tasks that you perform frequently. With a little bit of customization, you can greatly increase your productivity and efficiency when working with the command line.
Here are 10 commonly used aliases that can help increase productivity:
alias ll='ls -al'– This alias displays the contents of the current directory in a detailed list format, showing hidden files as well.
alias grep='grep --color=auto'– This alias highlights the search term in the output of the grep command, making it easier to visually identify the relevant information.
alias l='ls -CF'– This alias displays the contents of the current directory in a list format, showing directories with a trailing “/” character and executables with a trailing “*” character.
alias c='clear'– This alias clears the terminal screen, making it easier to read the output of previous commands.
alias mv='mv -i'– This alias prompts the user for confirmation before overwriting an existing file when using the “mv” command.
alias cp='cp -i'– Similar to the above alias, this alias prompts the user for confirmation before overwriting an existing file when using the “cp” command.
alias vi='vim'– This alias allows you to use the “vi” command to open the Vim text editor.
alias e='exit'– This alias allows you to quickly exit the terminal by typing “e” instead of “exit”.
alias p='cd ..'– This alias allows you to navigate to the parent directory of the current directory by typing “p” instead of “cd ..”.
alias h='history'– This alias allows you to display the command history by typing “h” instead of “history”.
In conclusion, the bashrc file is a powerful tool for customizing your bash shell and increasing your productivity and efficiency. By setting up aliases, you can streamline your workflow and save time by executing common tasks with just a few keystrokes. With a little creativity and some practice, you can use aliases to make your life as a Linux user even easier.