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

mail

avconv

  • I've been mislead into thinking that avconv obsoleted ffmpeg (details), which is why I present many examples based on avconv whereas ffmpeg still is the right tool for audio/video-related tasks.
  • Hopefully, both tools are compatible with each other, and using either avconv or ffmpeg in command lines should do the job .
mail

arping

Usage

send ARP requests to a neighbour host

Flags

Flag Usage
-c nbRequests stop after sending nbRequests ARP requests
-D enable Duplicate address detection mode
-I interfaceName send requests via the interfaceName network interface
-w timeoutSeconds stop after timeoutSeconds seconds regardless of the number of packets sent/received
mail

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
mail

alias

Create an alias :

a simple command for the CLI

  • a temporary alias (which will exist until the end of the session) :
    alias ll='ls -lh'
  • a permanent alias
    • for a single user
      1. add to ~/.bashrc (or —even better— : ~/.bash_aliases) :
        alias ll='ls -lh'no space allowed around the = sign
      2. reload the modified file:
        . ~/.bashrc
    • for all users : same as above, but write to /etc/bash.bashrc instead

an alias that takes argument(s)

Create a Bash function :
gzcat() {
	gunzip < "$@" | less;
	}

within a script

aliases are made for interactive use, so this goes beyond their initial purpose. But it's feasible anyway (source) :
  1. create a script with :
    #!/usr/bin/env bash
    
    alias hello='echo hello word'
    hello
    
    shopt -s expand_aliases
    
    alias hello='echo hello word'
    hello
  2. run it :
    /path/to/test.sh: line 4: hello: command not found
    hello word
  3. and if you try :
    hello
    hello: command not found
    the alias only exists within the script context

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

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.
mail

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
mail

apropos

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