This is an old revision of the document!
The Unix philosophy prizes modularity and reusability, and heavily favors small tools that solve a given problem. A basic mastery of Unix tools and workflows can go a long way for user's who are proficient in a Unix environment.
This section assumes a basic working knowledge of Unix development including the use of an command-line editor (e.g., Emacs, Vim), basic Unix commands and utilities (e.g., ls, cd, man), and development toolchains (g++, Python3, Make).
The Python3 interactive interpreter (typically invoked with python3
on the command line) allows for the entry of arbitrary Python3 commands, making it a great calculator and a great place to test simple ideas.
>>> from math import * >>> for i in range(10): ... print(int(log(2**i, 10))+1, end=' ') # single space before the print() to simulate indentation ... # additional lines in the loop here or <return> to end 1 1 1 1 2 2 2 3 3 3 >>>
The above fragment computes powers of two, and then uses the decimal logarithm to compute the number of digits in each power.
This can be extended to basic nested structures.
>>> for i in range(3): ... for j in range(3): # preceded by a single space ... print(i, j, sep=',', end=" ") # preceded by two spaces ... # single <return> keystroke 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 >>>
If you are looking to do anything more complicated, it is likely that you should create a temporary '.py
' file.
The import
statement can be used to import arbitrary Python3 files, which can be useful for quick unit tests (and doesn't require further file manipulation to drive tests).
Consider the Python code:
While only occasionally convenient, limited Python3 code can also be entered directly on the command line with the command (-c
) flag.
$ python3 -c "print('Hello') ; print('World!')" Hello World!
Pipes |
and redirects >
are common tools for creating basic workflows by manipulating input and output of programs and files or streams. Like many
In order to illustrate the use of pipes and redirects, consider the following
time
wc
man
/dev/null
/dev/random
/tmp/