Bash Index : A - The 'A' Bash commands : description, flags and examples

aptitude

Usage :

Text-based interface to the Debian GNU/Linux package system. It is _sometimes_ redundant with apt-get and dpkg (which is why I seldom use it). But it also has some interesting features others lack, which is what we'll see here

TIL that "aptitude " pops a ncurses interface (.. in which you can play Minesweeper ).

It's your attitude, not your aptitude, that determines your altitude.

Flags :

Flag Usage
why package
why-not package
Explains the reason that package should or cannot be installed on the system :
  • why finds a dependency chain that installs package
  • why-not finds a dependency chain leading to a conflict with package
See output flags below.

Output flags (source) :

1st character : state of package. 2nd character : action (if any, otherwise "space").

  • c.. : package was deleted but its configuration files remain on the system
  • i.. : package is installed
  • p.. : no trace of package exists on the system (i.e. been purged)
  • v.. : package is virtual
  • .d. : package will be deleted
  • .i. : package will be installed
  • .p. : package and its configuration files will be removed (i.e. purged)
  • ..A : package was automatically installed
  • It wasn't possible to find a reason to install package : package was manually installed

alias

Temporary alias (will exist until the end of the session)

alias ll='ls -lh'

List existing aliases :

alias

View details of an alias :

To read :
  • which command it refers to (command + flags)
  • the source code of a function (when applicable)
use :

Unset an alias (source) :

unalias aliasName

Permanent alias (saved into user preferences)

  1. edit ~/.bashrc (or — even better — : ~/.bash_aliases)
  2. append : alias ll="ls -lh"
  3. reload the modified file: source ~/.bashrc (or . ~/.bashrc)

If your alias expects parameter(s), consider creating a Bash function instead :

gzcat() {
	gunzip < "$@" | less;
	}

My favorite aliases :

No space character is allowed around the = sign.
# COLORIZED LS
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'

# GREP / EGREP
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'

# LESS
alias less='less -Ri'

# LS
alias ll='ls -lh'
alias lsd='ls -ld */'
alias lt="ls -l --time-style='+%d-%m-%Y %H:%M:%S'"
alias lt="ls --time-style='full-iso' -l"

# SSH
alias ssh='ssh -i ~/.ssh/id_rsa'
alias scp='scp -i ~/.ssh/id_rsa'

Hack :

How to temporarily bypass an alias (source) ?

  1. alias lo='echo hello world'
  2. lo
    hello world
    • \lo
    • 'lo'
    • "lo"
    • /full/path/to/lo (if exists)
    bash: lo: command not found
For a permanent effect, consider unalias.

at

Usage :

Execute commands at a later time.

Flags :

Flag Usage
-c jobId View the contents of the job jobId
-f file specify file containing commands to execute
-l list queued jobs. Similar to atq
-r jobId remove job with ID jobId from the queue. Or atrm jobId
-t dateTime specify execution time with format : [[CC]YY]MMDDhhmm[.ss]

Example :

Specify dateTime of execution :

Explicitly :
  • at 12:34
  • at 1234
As a delay from now :
at $(date --date "now +3 minutes" +%H%M)

Register commands :

A single command :
A list of commands :
at dateTime
prompt# command1 
prompt# command2 
prompt# CTRL-d
A command requiring Bash (at defaults to /bin/sh) :
at dateTime
prompt# /bin/bash -c "myCommand"
prompt# CTRL-d
If you want to run a command such as :
[ -f "someFile" ] && rm "someFile"
the whole command must be passed to Bash, meaning quotes are required :
/bin/bash -c "[ -f 'someFile' ] && rm 'someFile'"
and if you're doing this in a script, even more quotes are required (because the " enclosing the whole Bash command must be sent to at) :
echo /bin/bash -c ""\[ -f '$someFile' ] && rm '$someFile'\"" | at $(date --date "now +$delayMinutes minutes" +%H%M)

View the at queue :

atq

apropos

Each man page has a short description available within it. apropos searches the descriptions for instances of keyword(s) passed as arguments.