Skip to content

Instantly share code, notes, and snippets.

@yanil3500
Last active October 1, 2019 06:11
Show Gist options
  • Save yanil3500/00352b50676629b4a2925d5193916896 to your computer and use it in GitHub Desktop.
Save yanil3500/00352b50676629b4a2925d5193916896 to your computer and use it in GitHub Desktop.
Bash Profile for Remote Host

Adding helpful shortcuts to your bash profile

After ssh-ing into our host, do the following:

  1. Ensure that you are currently in your home directory by running cd ~/.

  2. Run vi ~/.bash_profile. This command translates to "edit this text file in the vim text editor"

  3. Once you're in the text editor, press i to go into insert mode.

  4. Copy/paste the block of code below into your file:

    # reload bash
    alias rb=". ~/.bash_profile"
    
    # get to home directory from anywhere
    alias home="cd ~/"
    
    # edit bash profile
    alias eb="vi ~/.bash_profile"
    
    # connect to the database
    alias db="psql -U postgres"
    
    # list databases
    alias db_list="psql -U postgres -l"
    
    # check db status
    alias db_status="service postgresql status"
    
    # start db
    alias db_start="service postgresql start"
    
    # stop db
    alias db_stop="service postgresql stop"
    
    # shows the columns for the given table, otherwise only the tables are listed
    function db_col() {
        psql -U postgres -c "\d $1"
    }
    
    # deletes a database when given the database's name as an argument
    function db_deldb() {
        psql -U postgres -c "DROP DATABASE $1;"
    }
    
  5. To save your changes, press the 'Esc' key then hold the 'Shift' key and press 'z' twice. This will save your changes and exit out of the text editor. (Esc + Shift ZZ).

  6. Finally, simply enter . ~/.bash_profile so that bash picks up your new shortcuts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment