69
octoxan
6y

Share your most useful terminal aliases and functions.

alias gs='git status'
alias gcm='git commit -m'
alias push='git push'
alias pull='git pull'
alias hosts='sudo nano /etc/hosts'
alias glog='git log --graph --oneline --decorate -n 10 --color'
alias mykey='cat ~/.ssh/id_rsa.pub | xclip -sel clip'

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

As well as one for each major project (lets say 1+ weeks of dev time) to immediately cd to it from anywhere. How about you guys?

Always looking to improve my terminal commands, so am curious what everyone else uses for shortcuts.

Comments
  • 4
    Don't have much myself anymore, but love the mkcd function you have, might use that too.
  • 6
    alias clearLogsOlderThan30='sudo find /var/log -mtime +30 -type f -delete'
  • 4
    @JoshBent @killermenpl

    It also just cd's if the directory already exists instead of throwing an error. =]
  • 3
    @incognito Ohhh I like that one.
  • 11
    alias cd..="cd .."
  • 3
    alias g+="g++ -std=c++11"
    Really saves the day.
  • 4
    alias vim=nvim
    alias zshrc="nvim $HOME/.zshrc && source $HOME/.zshrc"
  • 4
    alias ls="ls --color=auto"

    I fucking hate ls without coloring...

    And also what @host127001 said...
  • 1
    @RantSomeWhere I love this! Thanks!
  • 1
    alias chamod="chmod 777"
    I use that in my Unix shell scripting lab
  • 4
    Use oh-my-zsh with plugins
  • 0
    Would go for VIM, but neat function!
  • 3
    With oh-my-zsh git plugin, `git pull` is `gl` and `git push` is `gp`. And I use this terminal plugin called "autojump" which will jump to any path anywhere provided you give a fuzzy path name. And they prioritize based on the time you spent in each dir. And I also have a function where you accidentally unzipped a zip file with no parent dir, end up with a lot of files in current dir. Then that'll help remove it. If anyone interested, I'll post it.
  • 1
    @zerouplink Def. have interest in that
  • 6
    @JoshBent

    function ununzip() {
    unzip -t $1 | awk '{print $2}' | tail -n +2 | xargs rm -rf
    }
    Undo the unzip that you accidentally spread a lot of files to $pwd and don't know which one is which one to delete manually.

    function gtdy() {
    git log --shortstat --since yesterday | grep 'changed, ' | awk '{files+=$1; inserted+=$4; deleted+=$6} END {print "files changed:", files, "; lines inserted:", inserted, "; lines deleted:",deleted}'
    }

    Shows how many git commits you made, how many lines in total modified and changed

    https://gist.github.com/the-c0d3r/...
    I also use this, because I'm at the KVM console most of the time and I can't scrollback if I accidentally 'cat' a very long file. This will trigger 'less' if it is longer than terminal height, and 'cat' if shorter.
  • 3
    # Add ssh if necessary and git pull

    alias gpull='sshadd; git pull origin $(git_current_branch)'

    #Add ssh if necessary and git push

    alias gp='sshadd; git push'

    alias grep='grep --color=auto'

    alias ls='ls -h --color=tty'

    # Install a package with aurman with no confirmation

    alias aur='aurman -S --noedit --noconfirm --color always'

    function sshadd()

    {

    ssh-add -l > /dev/null || ssh-add

    }

    function le { "$1" | less }

    function cd { builtin cd "$1"; ls --color=tty; echo "$PWD" }
  • 2
    Some commands I found over the internet:

    alias cat='bat'

    alias du='ncdu --color dark --exclude .git'

    function extract() # Handy Extract Program.

    {

    if [ -f $1 ] ; then

    case $1 in

    *.tar.bz2) tar xvjf $1 ;;

    *.tar.gz) tar xvzf $1 ;;

    *.bz2) bunzip2 $1 ;;

    *.rar) unrar x $1 ;;

    *.gz) gunzip $1 ;;

    *.tar) tar xvf $1 ;;

    *.tbz2) tar xvjf $1 ;;

    *.tgz) tar xvzf $1 ;;

    *.zip) unzip $1 ;;

    *.Z) uncompress $1 ;;

    *.7z) 7z x $1 ;;

    *) echo "'$1' cannot be extracted via >extract<" ;;

    esac

    else

    echo "'$1' is not a valid file"

    fi

    }
  • 1
    @zerouplink @brunofontes some really great stuff I never knew I needed, thanks
  • 0
    For creating a directory and then get into that directory, I present to you:
    md () { mkdir -p "$@" && cd "$@"; }
  • 0
    Regarding your last sentence, about the large project and being able to change directory to it.
    I use ZSH, so it does that automatically. Really suggest that.
  • 1
    alias fuckingconnect='sudo service network-manager restart'

    Yes, I may have connectivity issues, especially when waking my computer from sleep mode
  • 0
    @brunofontes could you pastebin/hastebin/.. the original formatted extract() function?
  • 1
  • 1
    @brunofontes awesome, thank you!
  • 2
    @4nur44g If you use https://ohmyz.sh/ (works in any Linux terminal) the cd is implied. I love it, can just type a directories name or can just type .. to go up a directory.

    ... goes up 2
    .... goes up 3

    I still catch myself typing cd though sometimes even though it's not needed haha
  • 2
    @flocke I use https://github.com/athityakumar/... and have my ls set to

    ls = 'cls'
  • 1
    @octoxan

    You should check this.
    https://github.com/rupa/z

    That's most number of times used shortcut. And absolutely I love it.
Add Comment