• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 647
  • Last Modified:

Bash profile best practice

Can any one provide me best practice to bash profile? Or a good template ?
Thank you.
  • 3
2 Solutions
This is kind of subjective.  Do you have any specifics in your mind?

Do you want to customize the prompt, you will have to have modify PS1 environment variable.

You can set certain aliases for command you frequently use.

You also would set up path to include your current directory so that you don't have to do ./
Just put
export PATH=$PATH:.

You can make the history file very long, I typically make it 100000 commands so that you can recall really older commands as well
Here is a good reference for you

There's really no "best" practice for a default profile.  Most modern Unix/Linux systems have a global /etc/profile which gets read first upon login, and then the shell reads the .bash_profile file in the user home directory.

The general line of thinking is that your own personal .bash_profile is a place to override or add to any system variables that don't work for your situation.  For instance, the system may not give you all the directories in your PATH variable that you need access to (like for instance /your/homedir/bin) so you could add a line in your personal profile that says:

export PATH

Usually a personal .bash_profile will also source (this is like an "include" in programming terms) a .bashrc, so it will look like this:

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc

What this line says is that "if the file .bashrc exists, read it and source it".  Then in your .bashrc, you'd put aliases for common commands or functions that you use:

alias l="ls -latr"
myfunction () {
  # I can now use this function in all my programs
  echo "Hello world"

That's really all there is to it!  Feel free to ask if there's something more you were looking for.

You typically keep aliases for commands you frequently use

like in ~/.bash_profile file

alias ll='ls -al'
tamirmiloAuthor Commented:
Thank you,

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now