topic title: Bash Aliases
Alanarchy
Posts 0
Alanarchy
#1
I knocked up a '.bash_aliases' file to make life easier and I thought I'd share.

Code: Select all

# ~/.bashr_aliases: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
#
# some more ls aliases
alias upd8='sudo apt-get update && sudo apt-get dist-upgrade'
alias aclean='sudo apt-get autoclean'
alias arem='sudo apt-get autoremove'
alias grubup='sudo update-grub'
alias initup='sudo update-initramfs -k all -u -t'
It uses sudo, which you might not like.
Posts: 18
greywolf
Joined: 02 Feb 2014
#2
Here is mine, just to add more food for thought:

Code: Select all

## Colorize 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'

# install  colordiff package :)
alias diff='colordiff'

alias mount='mount |column -t'

## 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'
 
## older system use /proc/cpuinfo ##
##alias cpuinfo='less /proc/cpuinfo' ##
 
## get GPU ram on desktop / laptop##
alias gpumeminfo='grep -i --color memory /var/log/Xorg.0.log'
 
# some more ls aliases
alias ls='ls --color=auto'
alias lx='ls -lXB'        # sort by extension
alias lk='ls -lSr'        # sort by size
alias la='ls -Al'        # show hidden files
alias lr='ls -lR'        # recursice ls
alias lt='ls -ltr'        # sort by date
alias lm='ls -al |more'        # pipe through 'more'
alias tree='tree -Cs'        # nice alternative to 'ls'
alias ll='ls -l'        # long listing
alias l='ls -hF --color'    # quick listing
alias lsize='ls --sort=size -lhr' # list by size
alias lsd='ls -l | grep"^d"'   #list only directories

#Command substiution
alias ff='sudo find / -name $1'
alias df='df -h -x tmpfs -x usbfs'
alias psg='ps -ef | grep $1'
alias h='history | grep $1'
#alias rm='rm -i'
#alias cp='cp -i'
#alias mv='mv -i'
alias mkdir='mkdir -p -v'
alias which='type -all'
alias path='echo -e ${PATH//:/\\n}'
alias vi='vim'
alias du='du -h -c --max-depth=1'
alias reload='source ~/.bashrc'
#alias dupgrd='sudo apt-get update && sudo apt-get dist-upgrade -d'
alias c='clear'

#Personal Help
#alias dn='OPTIONS=$(\ls -F | grep /$); select s in $OPTIONS; do cd $PWD/$s; break;done'
#alias help='OPTIONS=$(\ls ~/.tips -F);select s in $OPTIONS; do less ~/.tips/$s; break;done' 

#show most popular commands
alias top-commands='history | awk"{print $2}" | awk"BEGIN {FS="|"} {print $1}" |sort|uniq -c | sort -rn | head -10'

# search for a package
alias acs="apt-cache search"

# empty trash
alias trash="rm -fr ~/.Trash"

## Moving around & all that jazz
alias back='cd"$OLDPWD"'
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."

## Dir shortcuts
alias home='cd ~/'
alias documents='cd ~/Documents'
alias downloads='cd ~/downloads'
alias images='cd ~/images'
alias videos='cd ~/videos'
alias music='cd ~/music'

## App-specific
alias wget='wget -c'
alias scrot='scrot -cd 5'

## Sudo fixes
alias install='sudo apt-get install'
alias acp='apt-cache policy'
alias remove='sudo apt-get remove'
alias orphand='sudo deborphan | xargs sudo apt-get -y remove --purge'
alias cleanup='sudo apt-get autoclean && sudo apt-get autoremove && sudo apt-get clean && sudo apt-get remove && orphand'
alias updatedb='sudo updatedb'
alias htop='sudo htop'
alias swapclear='sudo swapoff -a && sleep 2s && sudo swapon -a'

cheers,
greywolf.
Posts: 1,308
BitJam
Joined: 31 Aug 2009
#3
Some nice ones there greywolf. Thanks. Does your"mount" alias cause problems when you actually try to mount things?

Here are some of mine:

Code: Select all

psg() {
    content=$(ps -ef | tail -n +2 | grep"$@" | grep -v grep)
    echo"$content" | grep -q . || return
    printf"\e[1;36m"
    ps -f | head -n 1
    printf"\e[0;39m%s\n""$content"
}

li(){
    if [[ $# -gt 1 ]]; then
        ls --color -F $@
    elif [[ -d $1 ]]; then
        ls --color -F $1/
    elif [[ -f $1 ]]; then
        vimpager -c :AnsiEsc $1
    else
        ls --color -F $1
    fi
}

lst() { ls --color -tr $@ | tail -n 30 }
alias lstd="ls -tr ~/Downloads/ | tail -n 30"

}
My psg is like your but fancied up a little. The"li" command is used for poking around. It sort of combines"ls" with"less". If there is more than one argument or if the argument is a directory then it does"ls" but if the argument is a single file then it does the equivalent of running"less" on the file. Maybe I should do a"file $1" before viewing the file to handle binary files better but so far (many years) this has been fine. It is incredibly handy.

My"lst" lists only the 30 most recent files in a directory. This is handy for directories with a lot of entries when I am only interested in what is recent.

These are from my .zshrc so for Bash you may need to add more double quotes around variables that might contain spaces. I tried adding some back in.

Assuming you are using a recent version of antiX, you could also try adding this to the end of your .bashrc:

Code: Select all

source /usr/local/bin/fancy-prompts.bash
prompt-fancy
If you want to test drive it first then at the command line run:

Code: Select all

source /usr/local/bin/fancy-prompts.bash
prompt-fancy -h
prompt-fancy
I've attached a screenshot of what prompt-curl looks like. There are about a dozen different prompts to choose from and they can all be easily customized with command line parameters. Even more customization is available via a config file. I use urxvt with my own color definitions so the colors you get will probably be a little different.
Posts: 18
greywolf
Joined: 02 Feb 2014
#4
Thanks for the interesting additions @BitJam. I will look at them in some detail.

The 'mount' alias has not given me any trouble. However, you have prompted me to do some overdue maintainance on all this generic config stuff I have. I now use"mount binds" and udev devices in / etc/fstab so manual mounting is almost a dodo!. I run multiple distros/desktops as I support a couple of hundred folk, so I need to get this stuff a little less generic & sorted.

Without wanting to drift OT, can you briefly advise what advantages you find in zsh over bash. I have often thought of trying it out on a test user but wasn't sure what I would gain.

BTW, I tried 3 times to post this reply until I found the forum bug posts on etc stuff!! How obscure?!

greywolf.
Posts: 1,308
BitJam
Joined: 31 Aug 2009
#5
For starters, I like the tab completion and history in Zsh. Another cool thing is that you can just type in the name of a directory to cd to it. Then with"alias ...=../../.." and so on you can just type in"..." to move up two directories. This combines well with the history mechanism. You can also alias directories, for example:

Code: Select all

hash -d LiveUSB=~/Projects/antiX/LiveUSB
This allows my to type either"cd ~LiveUSB" or just"~LiveUSB" or even just"~L<tab>" to get to that specific directory. I try to design my aliases and functions to make the command history as useful as possible. I'm constantly using tab completion and history. For example I have an isomount function for mounting iso files. I had originally named it"mountiso" but by naming it"isomount" instead,"mo<up-arrow>" gets me my most recent"mount" command while"iso<up-arrow>" gets me my most recent isomount command and further up-arrows cycle through just the isomount commands instead of mixing mount and mountiso commands. Usually 2 or 3 letters suffice to specify a command. To help this along I added aliases"sucp" and"sumv" and maybe some others. This keeps"sudo .." separate from"sucp" and"sumv" in the command history.

Of course, you can also do history searches that include parameters as well as commands. I have these bound to <pg-up> and <pg-dn> while the command history is bound to <up-arrow> and <dn-arrow>.

I'm sure I've only scratched the surface. Here is a user's guide:
========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"http://zsh.sourceforge.net/Guide/zshguide.html"
linktext was:"http://zsh.sourceforge.net/Guide/zshguide.html"
====================================


Depending on your users, it might cause more trouble that it's worth, mostly because there is a ubiquitous assumption that everyone runs Bash. For example, online instructions often tell people to edit their .bashrc regardless of which shell is being used. You would certainly need to provide them with a good default .zshrc.

IMO, for someone who does not spend a lot of time at the command line, it is not worth it but for someone who spends hours per day at the command line then it is a good investment. BTW: I got started with antiX development because I wanted to add Zsh to the antiX LiveCD/USB. The SysRescueCD was brain-dead at that time. It had very long boot times and high resolution (>640-x580) virtual consoles were not available. The antiX LiveCD had everything I wanted except Zsh.

The reason I mentioned Zsh is that some of your aliases seemed to be reaching in the direction of the convenience of Zsh. IMO Zsh would let you take what you are doing in some of your aliases to the next step.
Posts: 18
greywolf
Joined: 02 Feb 2014
#6
Thanks again @BitJam.

I would not move my"tribe" untilI was very comfortable with Zsh myself; I'm not a sadist!! __{{emoticon}}__

I will definitely do some study though and create a user on my test machine with that shell to practice & learn with.

It is not just aliases either; I have many many many....... bash scripts sitting around that I have created/collected over the years.

Hmm, time to make a plan.. __{{emoticon}}__

cheers,
greywolf