Hacker News new | past | comments | ask | show | jobs | submit login
10 handy Bash aliases for Linux (opensource.com)
17 points by jhibbets on Sept 28, 2018 | hide | past | favorite | 11 comments



From HN Guidelines:

If the original title begins with a number or number + gratuitous adjective, we'd appreciate it if you'd crop it. E.g. translate "10 Ways To Do X" to "How To Do X," and "14 Amazing Ys" to "Ys." Exception: when the number is meaningful, e.g. "The 5 Platonic Solids."


Noted.


Here is one that should reset your terminal after accidentally reading a binary file, in most cases. Some of these are different on linux vs. unix vs. mac. You could put these in a file in /etc/profile.d/ or in your ~/.bashrc

    alias fix='reset; stty sane; tput rs1; clear; echo -e "\033c"'
List only directories:

    alias lsd='ls -h -b --color=auto -d */'
List by size:

    alias lss='ls -Ao --sort=s'
Hand dyslexia, or the alternate to installing "sl"

    alias sl=ls
    alias xit=exit
    alias moer="more"
    alias mroe="more"
Long PS

    alias p="ps -Hefcwww"
Shorthand for disk and memory usage:

    alias f="df -Ph;free -m"
Bash function to display colors:

    function colors()
    {
    for fgbg in 38 48 ; do
    for color in {0..256} ; do
    echo -en "\e[${fgbg};5;${color}m ${color}\t\e[0m"
    if [ $((($color + 1) % 10)) == 0 ] ; then
    echo
    fi
    done
    echo
    done
    }
Functions to do rot13 and rot47 to get around word filters

    function rot13() { if [ -r $1 ]; then cat $1 | tr '[N-ZA-Mn-za-m5-90-4]' '[A-Za-z0-9]'; else echo $* | tr '[N-ZA-Mn-za-m5-90-4]' '[A-Za-z0-9]'; fi }
    function rot47() { if [ -r $1 ]; then cat $1 | tr '\!-~' 'P-~\!-O' ; else echo $* | tr '\!-~' 'P-~\!-O'; fi }

A couple of memory stat functions

    function memfree() {
    free|awk '/^Mem/ {printf "%4.1f",($2-$4-$6-$7)/$2*100}'
    }

    function memperuser() {
    ps aux | awk 'NR != 1 {x[$1] += $4} END{ for(z in x) {print z, x[z]"%"}}'
    }


These are pretty neat, but weirdly uninformed on some things .

If you're using GNU tar the alias should just be "tar -xvf" since it can autodetect compression (though I'm not sure if that's suffix-based or file type). This also means you can append your own -j or whatever for different compression types if you need to do so manually.

Specifying "wget -c" does not mean you'll be able to resume if something goes wrong, it forces resumption from a partial file you already have on a subsequent invocation. The reason to specify it on the first invocation is just so that you can be lazy and reuse that command line.

The shasum command is from Perl on most (all?) platforms, sha256sum from GNU coreutils or equivalent may be needed if it's missing and may have higher performance.

Probably most importantly, ipconfig is OS and distro-specific. It was missing on the first linux systems I checked (Ubuntu and openSUSE). It's useful, but it's a bit like listing a launchctl alias without specifying it's largely macOS-specific.


This article covers gems like `alias c='clear'` - very handy! scnr


On a more serious note,

> alias www='python -m SimpleHTTPServer 8000'

that'll only work on systems where python is python2

> alias speed='speedtest-cli --server 2406 --simple'

speedtest-cli automatically selects a server, invoking it without any opts at all is perfectly fine

> alias ipi='ipconfig getifaddr en0'

the interface name is not predictable, nor portable - `ip a`

Most if not all of these aliases seem rather pointless after all


> A normal ping will go on forever. We don't want that. Instead, let's limit that to just five pings.

It almost always what I want.

> alias getpass="openssl rand -base64 20"

If you really want to be handy, use "pass generate -c" instead of openssl, you got the password stored in your passstore and temporary copied to the clipboard.


On Mac ⌘ + k works well in iTerm and the stock terminal. I can't be sure if it is a standard thing or not so I'm not going to make any assumptions about it working in other places.


I prefer ctrl+L


They're not quite equivalent. `clear` clears the scroll-buffer, but ctrl+l doesn't, it just clears the screen.

ctrl+l is generally the one I want.


That's emacs, not bash. It only works when "set -o emacs"




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: