Some of my BASH aliases...


Some of my BASH aliases...

Below is some of the aliases i use very often and i don't think i saw them else where. There are many aliases to find on the Net and use, but these are the ones, i am most proud of :)


alias l='/usr/bin/ls --color' That simple... typing ls is tyring... so why not just type l?


These two, are the most common i use:

function ewhich() {
  micro $(which $1)
}

function cwhich() {
  bat $(which $1)
}

Most of the times i tend to look for a script, which i don't remember where i placed it inside my PATH directories and then either i want to edit it or view it. So instead of typing which script and then micro /path/script, i just use ewhich script and it will edit the file with micro editor. cwhich is just for viewing a file. At the beggining i used cat but i switched to bat... perhaps i should have renamed as bwhich?


My backup command... the simplest solution to backup important files, for me, is to use the following function:

backup() {
    file=${1:?"error: I need a file to backup"}

    timestamp=$(date '+%Y-%m-%d-%H:%M:%S')
    backupdir=~/backups

    [ -d ${backupdir} ] || mkdir -p ${backupdir}
    cp -a ${file} ${backupdir}/$(basename ${file}).${timestamp}
    return $?
}

It will make a copy of the file given, with a timestamp, inside a default backup directory i have. So, when i am at the terminal and change/create a file, if i want to have it backed up, i use this. The timestamp, makes a big difference, cause this way i can have multiple copies of the same file, in case i want to restore an even older version of it.


function ..() {
if [ $# -eq 0 ]; then
        cd ..
    else
        cd ../"$1"
    fi
}

The .. alias is very common, i have seen it in many places on the Net... but why use just .. when you can also pass a parameter and cd into a directory. So this alias/function, if used with no parameters, it will just go back one directory, but if you use it like .. dir_name, it will also cd into that directory.


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

When i want to create a dir. and also change into that, typing mkdir name and then cd name is too much. That's why i made this function. mkcd will create the directory and also change into that, with just a simple command.


fzf should be used everywhere, it's the most useful tool i think. So i thend to use it with many commands. One of these is this one...

alias fhistory='cat ~/.bash_history | fzf'

I think there is also a key shortcut by default, but i tend to forget that, as i do now :P


Some more common, that it should be the default commands, for some of the most used linux commands are these:

alias dd="dd status=progress"
alias wget='wget -c' 
alias free='free -h' 

So... what do you think? Do you like them? Do you find these useful? Have you all ready used some of them? Do you have similar ones?

Add a comment

Previous