Bash profile best practice

Posted on 2011-10-21
Last Modified: 2012-05-12
Can any one provide me best practice to bash profile? Or a good template ?
Thank you.
Question by:tamirmilo
    LVL 31

    Expert Comment

    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
    LVL 31

    Expert Comment

    Here is a good reference for you
    LVL 19

    Accepted Solution

    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.

    LVL 31

    Assisted Solution

    You typically keep aliases for commands you frequently use

    like in ~/.bash_profile file

    alias ll='ls -al'

    Author Closing Comment

    Thank you,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
    Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now