Ghost in the Shell

The Ghost in the Shell series are about efficient working in the shell environment. There are actually a lot articles and blog posts about efficient working in the terminal, but a lot of them are biased towards very specific uses, like hints only for Bash shell or only for specific terminal emulator. These series are about universal knowledge that would work on most shells and environments.

I made a separate Ghost in the Shell series dedicated ‘global’ page that links to all episodes of the series along with table of contents for each episode’s contents.

Hope that will make it more useful and readable as a whole.

List of the episodes in the Ghost in the Shell series.

Below are the contents of each episode.


Ghost in the Shell – Part 1

Recall Last Argument of Previous Command

% cd !$

Swap First Occurrence of a Word

% ^mkdir^cd

There and Back Again

% cd -

Repeat Command from History

% !pkg


Ghost in the Shell – Part 2

Alias with Arguments

% alias lsg='ls | grep'

Color grep(1) Patterns

% export GREP_COLOR=1;31

Process Management

% command &

% fg

% bg

% jobs

% kill

% disown

% nohup



Which Which

% which caja

Record Session

% script script.out

Edit Command Before Executing

% fc

Edit or Just View

# less /etc/rc.conf


% reset


Ghost in the Shell – Part 3

Query Functions

% q

% Q

% qq

% QQ

% h

% H

% g

% G

% c

% e

Where Is My Space

% du -sm * | sort -n

% ncdu

Where Are My Files



How Many Copies Do You Keep

% -M .

Unusual cron(1)Β Intervals











Check cron(1) Environment

% cat

Simple HTTP Server

% python -m SimpleHTTPServer PORT

% python -m http.server PORT

Simple FTP Server



Ghost in the Shell – Part 4

Named Pipes

FreeBSD # mkfifo /tmpPIPE

Linux # mknod /tmp/PIPE p

Modify Command Environment on the Fly

% env LC_ALL=pl_PL.UTF-8 gls -l

The Real Path

% realpath

Browsing the PATH

% echo "${PATH//:/\n}"

% export IFS=":"

% for I in $( echo ${PATH} ); do echo ${I}; done

Parameter Expansion







Sort Human Readable Values

% du -sh /usr/*

% zfs list | sort -h -k 2

Write a File from vi(1) with Different Rights

:w !doas tee %

Search Contents of PDF Files

% pdfgrep -i -n bhyve *.pdf


Ghost in the Shell – Part 5

Less More Useful

% less -r -S -N --mouse --quit-if-one-screen

Detox These Filenames

% detox FILE

% for FILE in *; do detox ${FILE}; done

% find . -type f -exec detox {} ';'

Man Up the Info Pages

% info ls | less

Real UNIX Sorting

% env LC_ALL=C ls -1

Faster Better Uptime

% w

Filter Huge Files

% env LC_ALL=C LANG=C grep string HUGEFILE


Ghost in the Shell – Part 6 – Learn Shell Scripting

Learn the basics of shell scripting.

% cat

FORMAT="%8s %-s\n"
printf "${FORMAT}" SIZE NAME
kldstat \
  | sed 1d \
      SIZE=$( printf "%d" 0x${SIZE} )
      printf "${FORMAT}" ${SIZE} ${NAME}


Ghost in the Shell – Part 7 – ZSH Setup

Get your ZSH shell configured.