Custom Bash Profile For Web Development

back to tech articles
CentOS 6.5, x86_64

I like tweaking my terminal prompt. It makes my life so much simpler to have some info easily available and especially to have alias shortcuts. I’m feeling generous this morning, so here’s my own .bashrc file for you. Tweak it to your own liking.

Profile .bashrc

I really like the look, but you may disagree. Here’s what it looks like in action:

Custom_Bashrc

For the uneducated, this file is located in your user’s root directory (not the server root directory). Here’s how you can be sure you’re in the right place:

1
$ vi ~/.bashrc

You are now editing the .bashrc file for the currently logged in user. In my case, I’m logged in as root.

The File

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# do not delete / or prompt if deleting more than 3 files at a time
alias rm='rm -I --preserve-root'

# confirmation
alias cp='cp -i'
alias mv='mv -i'
alias ln='ln -i'

# Parenting changing perms on /
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

# pass options to free
alias meminfo='free -m -l -t'

# get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'

# get top process eating cpu
alias pscpu='ps auxf | sort -nr -k 3'
alias pscpu10='ps auxf | sort -nr -k 3 | head -10'

# Get server cpu info
alias cpuinfo='lscpu'

# get GPU ram on desktop / laptop
alias gpumeminfo='grep -i --color memory /var/log/Xorg.0.log'

# resume wget by default
alias wget='wget -c'

# show open ports
alias ports='netstat -tulanp'

# create parent directories on demand
alias mkdir='mkdir -pv'

# colour the grep command output for ease of use (good for log files)
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'

# colour the ls output
alias ls='ls --color=auto'
alias lsl='ls -la --color=auto'

# reboot
alias reboot='reboot --verbose'

# cd shortcuts
alias gotosites='cd /var/www/html/'

# custom bash
PS1="(\[\e[0;36m\]\u\[\e[0m\]\[\e[37;1m\]@\[\e[0m\]\[\e[1;36m\]\h\[\e[0m\])-(\[\e[1;35m\]\$PWD\[\e[0m\])-(\[\e[0;32m\]\t\[\e[0m\])\n(\[\e[0;32m\]\!\[\e[0m\]) \[\e[1;32m\]\$ \[\e[0m\]"

I’m guessing you already know your way around bash so I won’t walk through the file step-by-step. It’s lightweight but still very useful. To list out the available aliases, simply type alias in the terminal:

1
$ alias

Enjoy and contribute your own in the comments if you like.

Leave a Reply

Your email address will not be published. Required fields are marked *