DEV Community

4 Simple Steps For Custom Bash Commands

Molly Nemerever on April 08, 2019

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 ty...
Collapse
 
jericomanapsal profile image
jericomanapsal

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.

Collapse
 
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.

Collapse
 
mollynem profile image
Molly Nemerever

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.

Collapse
 
drawcard profile image
Drawcard

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

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

.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: medium.com/@kingnand.90/what-is-th...

I recommend revising the text accordingly.

Collapse
 
artiya4u profile image
Artiya

My .inputrc

## arrow up
"\e[A":history-search-backward
## arrow down
"\e[B":history-search-forward
Enter fullscreen mode Exit fullscreen mode
Collapse
 
archagy profile image
archagy
Collapse
 
calvinbarajas profile image
Calvin Barajas

Thank you so much, this is awesome!

Collapse
 
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. github.com/pushkar-anand/bashAlias...

Collapse
 
mollynem profile image
Molly Nemerever

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