Home  »  Linux  »  Custom bash_profile for Advanced Shell Users

by 9 comments

Looking for some advanced uses for the shell? Here is some of my best. Works for all shells I encounter, including BackTrack, Debian, Knoppix, Arch Linux, etc. Also works for many hosting environments I use including DreamHost, HostGator, WiredTree, and pretty much any linux VPS.

Want to get started? Type the following in your shell to download the script and run it. You should go over the code first and then you can just save it as your .bash_profile - whenever you want to get updated to the latest version just type aaup, a cool update function that auto dos2unix's and runs via an exec command.

curl -O && source askapache-bash-profile.txt
Or if you trust me and my hosting provider (and you aren't on production)
curl -o ~/.bash_profile && exec bash -l

For those of you power users and server admins that use Bash, ksh, csh, vanilla sh, etc.., or if you are just passionate about shell scripting, because it allows you to get advanced tasks done fast and efficiently, not to mention automated automatically. I give you my .bash_profile file. You should edit it to fit your needs, (especially the exported vars like PATH, LDFLAGS, if you don't understand something just comment it out) but it's pretty universal because I work on alot of other people's servers not to mention many different distros and platforms, and when I get hired to do some server work through a shell, I bring this script along for the ride.


You can download the latest version:

The functions and variables below are the way bash sees them, using declare -f, and alias, to make it easier for you to read and understand them. The actual file at will always be the most updated version, as I use it personally. And it has the whole file the way I wrote it, meaning many extra notes and much simpler to follow. Enjoy!

Gist of the Script..

I also rely on this heavily from within shell scripts I write to access all the functions and stuff in this .bash_profile, and to do that I just do like:


source ~/.bash_profile &>/dev/nulll

pm "PM is a function to output nice messages with color"
yn "Are you enjoying the shell" && pm "Thats great!" || pm "Perhaps you're better suited for DOS"
yn "Show Calendar" && aa_calendar
yn "Show Fortune" && aa_fortune
alias chmod='command chmod -c'
alias cpr='command cp -rpv'
alias df='command df -kTh'
alias df1='command df -iTa'
alias diff='diff -up'
alias dsiz='du -sk * | sort -n --'
alias du='command du -kh'
alias du1='echo *|tr " " "n" |xargs -iFF command du -hs FF|sort'
alias env='command env | sort'
alias h='history'
alias inice='ionice -c3 -n7 nice'
alias j='jobs -l'
alias la='command ls -Al --color=auto'
alias lc='command ls -lAcr --color=auto'
alias less='vless'
alias lessc='ccze -A |`type -P less` -R'
alias lk='command ls -lASr --color=auto'
alias llh='ll -h'
alias lll='stat -c %a %N %G %U ${PWD}/*|sort'
alias lr='command ls -lAR --color=auto'
alias lt='command ls -lAtr --color=auto'
alias lu='command ls -lAur --color=auto'
alias lx='command ls -lAXB --color=auto'
alias mann='command man -H'
alias n='/usr/bin/nano3'
alias p='command ps -HAcl -F S -A f|uniq -w3'
alias path='echo -e ${PATH//:/\n}'
alias php='php -d report_memleaks=1 -d report_zend_debug=1 -d log_errors=0 -d ignore_repeated_errors=0 -d ignore_repeated_source=0 -d error_reporting=30719 -d display_startup_errors=1 -d display_errors=1'
alias pp='command ps -HAcl -F S -A f'
alias ps1='command ps -lFA'
alias ps2='command ps -H'
alias resetw='echo $'''33[H33[2J''''
alias subash='sudo sh -c '''export HOME=/root; cd /root; exec bash -l''''
alias top='top -c'
alias tree='command tree -Csuflapi'
alias updatedb='( ( updatedb 2>/dev/null ) & )'
alias vim='command vim --noplugin'
alias who='command who -ar -pld'
alias wtf='watch -n 1 w -hs'



November 23rd, 2009

Comments Welcome

  • Wojtek

    The script looks great but for some reason I'm getting:

    # ./
    -bash: ./ /bin/bash

    : bad interpreter: No such file or directory

    I do have bash :) and /bin/bash do exists. Any idea why is this happening?

    # dos2unix -dv
  • larsx2

    Amazing! My bash_profile looked so skinny.. thanks for the share. (And truly it is bash that is the heart of evrything on askapache)

  • feigner

    First I want to thank askapache for sharing the fruit of his labor, then, not to complain, but rather query about an issue I'm having using the "bash_profile for Advanced Users.

    When I utilize this .bash_profile, I loose a feature that I really like in bash which is the use of special history completion using "!!", "!$", "!df", "!23", "!-3" and the like.

    I've looked at lots of bash documentation and even tried commenting out parts of you the profile to turn off history functions, but nothing works. Any Ideas?

  • mark


    you have DOS line endings in the file. Open in vim, enter :set ff=unix then :x to save it back out. Then it should work.

  • bogomips

    Thanks for this post and share script. Though, I confirm that sourceing the script in a terminal rids the bash's history expansion (like feigner I would not imagine my life without !! and !$ substitutions). Perhaps, I need no such many aliases from those bangs :-)
    My $.02 medicine was either to source script as bash -lH askapache-bash-profile.txt or to type set -H on login to return history expansion back. What's about histexpand option in your script? And more, some Linux distros have not installed dos2unix by default (e.g. Ubuntu's tofrodos pkg obsoletes dos2unix).

  • Slavik


    Nice script...
    I'm interested only in the last part?
    How did you generate it? I want to be able to call it whenever i feel like it..
    (the pink part with the dates?)
    I'm using Archlinux

  • AskApache

    @slavik ~

    To install calendar files in your ~/.calendar directory:

    $ U='';
    $ mkdir ~/.calendars
    $ cd ~/.calendars
    $ curl $(for f in `curl -sSo - $U|sed '/">calendar./!d;s,^.*">calendar.([^<]*)</a></td>,1,g'`;do echo -n " -O ${U}calendar.${f}";done);

    This will then print out the calendar items

    $ sed -n "/$(date +%m/%d|%b* %d)/p" $(find ~/.calendar /usr/share/calendar -maxdepth 1 -type f -name 'c*' 2>/dev/null);
  • NameRubem

    I loved the hint, now how do I remove the AskApache bash_profile? My problem was with the accent that does not work.

    My English is poor, sorry!

  • Pingback: Delicious Bookmarks for June 27th through June 30th « Lâmôlabs

Related Articles

My Online Tools
Popular Articles

Hacking and Hackers

The use of "hacker" to mean "security breaker" is a confusion on the part of the mass media. We hackers refuse to recognize that meaning, and continue using the word to mean someone who loves to program, someone who enjoys playful cleverness, or the combination of the two. See my article, On Hacking.
-- Richard M. Stallman


It's very simple - you read the protocol and write the code. -Bill Joy

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. NCSA HTTPd.
UNIX ® is a registered Trademark of The Open Group. POSIX ® is a registered Trademark of The IEEE.

+Askapache | askapache

Site Map | Contact Webmaster | License and Disclaimer | Terms of Service

↑ TOPMain