Tech Reflect
  • Home
  • About This Site
  • Contact me
  • Search Icon
Shell aliases

Shell aliases

2017-08-17

Table of Contents

Toggle
  • “ls” command
  • Common sets of flags
  • Paths
  • Shortcuts to machines or devices you ssh to often.
  • Complicated commands
  • Functions

Shell aliases are woefully underused. Painfully, I frequently see people do the following:

  • Type a shell command with the same 4 arguments cd into the same folders
  • ssh into the same machines or devices
  • Run the same sequence of commands

Aliases are super easy. Just open your ~/.bashrc file (or equivalent) and start adding them. I’ll now give a bunch of examples I use.

“ls” command

I have many variations I use on the “ls” command. I don’t even remember what the arguments mean anymore because I’ve been using these shortcuts for so long.

# default arguments I like
alias l='ls -AG'

# Long listing
alias ll='ls -aAlGh'

# Do a grep afterwards (My most often used)
alias lg='ls -AlGOh@ | grep -i '

# Newest files at bottom (My second most often used)
alias lt='ls -AltrGhu'

# Largest files at bottom
alias lz='ls -AlGrhS'

# Extended attributes
alias lx='ls -aAlGh@O'

# kitchen sink
alias le='ls -aAlGh@eOR'

Common sets of flags

When I run “du” or “top” I always use the same flags, so I have this set up:

alias ds='du -chs'
alias t='top -stats pid,command,cpu,time,threads,ports,mem,state,username -o cpu'

Note that you could redefine the meaning of a command (e.g. alias ls = ls -l) but note that if you want to use different arguments, you’re stuck unless you define it as a function (see below).

Paths

If you type the same path at least once a day, just make an alias for it.

alias cr='cd ~/Library/Logs/CrashReporter/MobileDevice/<device name>'
alias dl='cd ~/Library/Logs/CrashReporter/MobileDevice/<device name>/DiagnosticLogs'
alias sd='cd ~/Library/Logs/CrashReporter/MobileDevice/<device name>/DiagnosticLogs/sysdiagnose'

Shortcuts to machines or devices you ssh to often.

If you ssh to other machines often, it’s tedious to type out the command every time, so set up an alias.

alias sandfly='ssh admin@sandfly'
alias trilobite='ssh admin@trilobite'
alias weta='ssh admin@weta'

Complicated commands

For verbose or complicated commands, you’ll quickly tire of typing them over and over.

alias lc='launchctl unload /Library/LaunchAgents/org.cricket.install-xcode; launchctl load /Library/LaunchAgents/org.cricket.inst

Functions

I’ll mostly leave this as an exercise to the reader, but you can create functions in your .bashrc (or equivalent) file that allow you to pass in arguments. For example:

function installbuild () {
sudo asr -source $1 -target $2 -erase -noverify
}

This is one way you could redefine a command so that it always uses your desired set of flags, but also allows you to pass in new flags and override what’s in your function. You could even define a function that always adds flags to the default set when you add the flags on the command line.

Reserve functions for times when the time investment will pay off. It’s easy to get addicted to improving your productivity but make sure it’s worth the investment.


geeky, macOS tips

Post navigation

NEXT
Moderately advanced searching in Mail
PREVIOUS
Xcode nuclear option
Comments are closed.

Get Monthly Updates

Recent Posts

  • Inserting random email sigs in Mail on iOS
  • Keep Instagram open to finish posting…
  • How I predicted the rise of Twitter, barely used it, and amassed 35,000 followers
  • Apple Books 2022, in pictures
  • Killing one bird with two-and-a-half stones in Mac OS X Mail

Categories

  • analog (1)
  • apple career (12)
  • apple inside (19)
  • apple stories (20)
  • bertrand serlet (3)
  • bugs (3)
  • essays (15)
  • geeky (21)
  • interviews (4)
  • iOS tips (4)
  • Mac OS X (7)
  • macOS tips (36)
  • personal (8)
  • predictions (1)
  • products (5)
  • prototypes (6)
  • scott forstall (7)
  • scripting (2)
  • siri (2)
  • steve jobs (16)
  • tim cook (1)
  • workplace (15)

Get Monthly Updates

About cricket


Me with Guiness the owl

25 years in tech. I like to write manifestos. I like to offer interesting tips. I like making fun of things. Everyone copes differently.

My Other Blogs

  • Free Range Parrots
  • Plucky Tree (personal)
© 2025   All Rights Reserved.