DEV Community


4 Simple Steps For Custom Bash Commands

mollynem profile image Molly Nemerever ・2 min read

The terminal isn’t the most user friendly - sensitive to errors, challenging to read, and it requires a lot of typing! I frequently find myself typing the same commands over and over into my terminal. If only there was a way to create my own shortcuts to access my main folders by typing a single keyword…

Luckily this functionality exists! Let's walk through 4 simple steps to creating your personalized bash commands:

1. Locate Your .bash_profile (OSX) or .bashrc (Linux)

  • Navigate through your terminal to either your .bash_profile file or .bashrc depending on your operating system. Your shortcuts will live in these files so that each time you open a new terminal session, the shortcuts are accessible.

navigate to bash profile in osx
navigate to .bash_profile within OSX

2. Add Your Commands

  • Inside the file start creating your own commands! Use them to help you navigate to frequently accessed folders, shorten git commands, open applications, or anything you think would be helpful and time saving. Examples below:

bash shortcut command examples

a few examples of personalized bash commands

3. Update Your Command File Through the Terminal

  • For best practice, after you add new commands to your shortcut file, be sure to run the command below to refresh your file via the terminal: source ~/.yourfilenamehere

update file through bash
run this command after editing your file

4. Run Your Commands!

  • Use your commands and enjoy the time you’ve saved by working smarter - not harder! Go back and add commands as you need throughout the future.

get work done gif

Discussion (10)

jericomanapsal profile image

Great post! Aliases really makes things easy and short. In addition, if you are using bash, you can put your aliases on ~/.bashrc. That way, you won't have to execute ~/.custom_bash_commands for every session.

audioboxer217 profile image
Scott Eppler

I have my aliases in one dotfile, functions in another, then I source both in my .bashrc

I like keeping them separate for cleanliness and testing while also having them sourced in every session automatically.

mollynem profile image
Molly Nemerever Author

That's awesome organization! I think as I gain experience and discover which functions I'll want as shortcuts I'll restructure how I've saved these functions.

drawcard profile image

Or better yet ask .bashrc to reference ~/.custom_bash_commands at login:

# Put this in your .bashrc file
source ~/.custom_bash_commands
linaran profile image

.bash_profile and .bashrc are two semantically different files. Both can be found on both linux and osx (which is also a linux os because it has linux kernel).

Difference between .bash_profile and .bashrc is explained here:

I recommend revising the text accordingly.

archagy profile image
maxwassiljew profile image
Max Wassiljew

Nice post, btw there is no need to alias home. Just type 'cd' without parameters and it will bring you $HOME.

mollynem profile image
Molly Nemerever Author

I didn't know this! Thank you for sharing!

artiya4u profile image

My .inputrc

## arrow up
## arrow down
anandpushkar088 profile image
Pushkar Anand

I had recently created a simple tool that allows me to simply add aliases without editing .bashrc files every time.

Forem Open with the Forem app