Time Saving Tricks Reference (PAL Series)

Update: These were written for my students while my role was a PAL (Peer Assisted Learning) Leader for my course, I intended to keep all the basic/intermediate commands necessary for terminal use in one place to ease the students into using Linux efficiently. I’ve kept them up just in case they’re of use to someone.

Brace Expansion

Expanding two sets of braces

$ touch {a,b}{x,y,z}
$ ls
ax ay az bx by bz

Nesting expanding braces with existing directories

$ mkdir include src
$ touch include/{vector,matrix,complex}.h src/{vector,matrix,complex,main}.c
$ ls
include src
$ ls include/
complex.h matrix.h vector.h
$ ls src/
complex.c matrix.c main.c vector.c

As you can see, brace expansions work like expanding the brackets in algebra.
They’re very handy for quickly generating directory structures with little typing. Manual page.

Sequence Expansion

Create 16 files

$ touch file_{0..16}.txt # Sequence from 0 to 16
$ ls
file_0.txt file_12.txt file_15.txt file_2.txt file_5.txt file_8.txt
file_10.txt file_13.txt file_16.txt file_3.txt file_6.txt file_9.txt
file_11.txt file_14.txt file_1.txt file_4.txt file_7.txt

Create directories with odd numbers only in their names

$ mkdir dir_{1..9..2}     # Sequence from 1 to 9, with a step of 2 (skip every other number)
$ ls
dir_1 dir_3 dir_5 dir_7 dir_9