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.
- Ghost in the Shell – Part 1
- Ghost in the Shell – Part 2
- Ghost in the Shell – Part 3
- Ghost in the Shell – Part 4
- Ghost in the Shell – Part 5
- Ghost in the Shell – Part 6 – Learn Shell Scripting
- Ghost in the Shell – Part 7 – ZSH Setup
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
[CTRL]+[Z]
[CTRL]+[C]
Which Which
% which caja
Record Session
% script script.out
Edit Command Before Executing
% fc
Edit or Just View
# less /etc/rc.conf
Reset
% reset
~
Ghost in the Shell – Part 3
Query Functions
% q
% Q
% h
% H
% g
% G
% c
% e
Where Is My Space
% du -sm * | sort -n
% ncdu
Where Are My Files
% files-count.sh
% files-big.sh
How Many Copies Do You Keep
% dedup.sh -M .
Unusual cron(1)Β Intervals
@reboot
@yearly
@annually
@monthly
@weekly
@daily
@midnight
@hourly
@every_minute
@every_second
Check cron(1) Environment
% cat ENV.sh
Simple HTTP Server
% python -m SimpleHTTPServer PORT
% python -m http.server PORT
Simple FTP Server
% ftp.py PORT
~
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
${name}
${name#*/}
${name##*/}
${name%%.*}
${name%/*}
${URL%%/*}
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 kld.0.4.sh #!/bin/sh FORMAT="%8s %-s\n" printf "${FORMAT}" SIZE NAME kldstat \ | sed 1d \ | while read ID REFS ADDRESS SIZE NAME do SIZE=$( printf "%d" 0x${SIZE} ) printf "${FORMAT}" ${SIZE} ${NAME} done