DEV Community

Cover image for A small byte of bash aliases and functions.
Nilkun
Nilkun

Posted on

A small byte of bash aliases and functions.

I'd like to share a few of my favorite bash aliases and functions. All I ask for in return is for you to share your own in the comments!

# Set up ls to use my preferences
alias ls='ls -l --color=auto --group-directories-first'

# Quickly add things to a todo-list. Usage: remember milk
alias remember="xargs -I TODO  echo \"[ ] TODO\" >> ~/remember <<<"

# I often find files that I don't know what to do with, but I don't want to delete. So I just move them to dev-hell. usage: devhell mysuperniftyfunctionthatiwillneveruse.js
alias devhell='mv -t ~/dev-hell/'

# I don't know how many times I typed this in before I made it an alias. Usage: pid vim
alias pid="ps -aux | grep "

# I use the following function and alias to jump back and forth between home and the current directory.
function home() {
        PREVIOUS=$(pwd)
        cd ~
}
alias back="cd $PREVIOUS"

# I use Arch Linux, and often download from AUR. Usage: aur chromium
alias aur="xargs -I FILENAME git clone https://aur.archlinux.org/FILENAME <<<"
Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
moopet profile image
Ben Sinclair

For your process finding one, you might want to exclude the grep command itself, depending on what system you're on. On a Mac, for example, you'll get the process used to grep listed, which is generally not what you want. Also on a Mac, ps -aux will fail if there isn't a user called "x" because ps interprets commands differently depending whether you use a dash or not (I know!).

alias pid='ps aux | grep -v grep | grep'
Enter fullscreen mode Exit fullscreen mode

Or if you're only interested in the PID (as implied by the alias name, you can use pgrep which fits nicely with pkill because without any other options it just returns the PID.

I know you tagged this with #linux but I think it's good to make things as general as possible so if you have to work on a BSD system or a Mac you can re-use the same commands.

Collapse
 
waylonwalker profile image
Waylon Walker

I need to use pgrep more I still hand type the alias that you showed.

Collapse
 
waylonwalker profile image
Waylon Walker

remember and devhell are quite interesting, I may try to implement something similar myself.