Skip to content

Commit 62bfb7a

Browse files
committed
Split some utils, logrotate, improve posix.
1 parent d15a57c commit 62bfb7a

17 files changed

+445
-330
lines changed

ctags/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,5 @@ Supports 55 languages
150150

151151
exuberant-ctags a.c
152152
less tags
153+
154+
Seems to be the main Ubuntu package that offers a `ctags` utility.

desktop/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ Keep examining the properties, and print if changes happen:
227227

228228
Modify key maps.
229229

230-
For example, to exchange exc and caps lock:
230+
For example, to exchange ESC and Caps Lock:
231231

232232
f=~/.Xmodmap
233233
echo "! Swap caps lock and escape
@@ -246,6 +246,14 @@ To make this happen every time at startup TODO broken?:
246246

247247
The `~/.xsession` file could also be used depending on system
248248

249+
##xinitrc
250+
251+
Sourced in Ubuntu 12.04, but not 14.04.
252+
253+
##xsessionrc
254+
255+
TODO vs `xinitrc`?
256+
249257
##xdotool
250258

251259
Send clicks and manage window properties from sh.

filesystem.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Use the same username on new systems, and mount the partition automatically with
118118

119119
30GiB is a good size for each root partition. Leave everything else for the home partition.
120120

121-
#Partition table
121+
##Partition table
122122

123123
Contained in the MBR.
124124

gpu.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,20 @@ Xorg is getting old and the future Wayland is considering the shift towards swit
5050

5151
Bumblebee seems to be the best bet to support NVIDIA Optimus as of 2013.
5252

53-
#nvidia
53+
#NVIDIA
5454

55-
##nvidia settings
55+
##NVIDIA version names
5656

57-
To check that the installation is working, use `nvidia-settings`, which monitors the GPU, and will show if the GPU is not properly installed.
57+
Each hardware has two names:
58+
59+
- model: precise name of a single piece of hardware
60+
- codename: marketing name that may group several models
61+
62+
For example, from the `lspci` output, in `GF108M [NVS 5400M]`:
5863

59-
##nvidia settings
64+
- `NVS 5400M` is the model name
65+
- `GF108M` is the codename
66+
67+
##NVIDIA settings
68+
69+
To check that the installation is working, use `nvidia-settings`, which monitors the GPU, and will show if the GPU is not properly installed.

logrotate.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
A log file is a file that stores notifications, often automatically made by programs that run on the background like servers or the kernel.
2+
3+
Log file for system wide utilities are often stored under `/var/log`.
4+
5+
Log files contain information that can be useful to debug the system.
6+
7+
Most applications simply append to the end of a single log file.
8+
9+
This has two problems:
10+
11+
- you can run out of disk space
12+
- opening each file takes a very long time
13+
14+
It would be easy to solve those two problems if it were possible to write to the beginning of a file efficiently: applications could just do that and truncate the file to a size, keeping the most recent messages at the top. Unfortunately there is no efficient way of writing to the beginning of a file: you would have to move everything forward to make up space.
15+
16+
Logrotate solves both of those problems with the premise that more recent logs are more important.
17+
18+
For example, you can configure logrotate to do the following:
19+
20+
- if log the file `a.log` is larger than 100Kb, zip it into `a.log.1.gz`.
21+
22+
This will make up room for the application to create a new log file.
23+
24+
- if `a.log.1.gz` already exists, create `a.log.2.gz`, and so on, up to a configurable limit, like `a.log.4.gz`.
25+
26+
After that, the `.gz` would be removed.
27+
28+
This is why it is called logrotate: at the same time, it transforms:
29+
30+
- remove `a.log.4.gz`
31+
- rename `a.log.3.gz` into `a.log.4.gz`
32+
- ...
33+
- rename `a.log.1.gz` into `a.log.2.gz`
34+
- zip `a.log` into `a.log.1.gz`
35+
- remove `a.log`
36+
37+
Most distributions run logrotate by default from cron.

make/README.md

+22-33
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,37 @@
11
Make allows you to:
22

3-
- make command line interfaces of the type:
3+
- make command line interfaces of the type:
44

55
make <something> a=b c=d
66

7-
*very* easily
7+
*very* easily.
88

9-
- only build outputs when inputs have changed
9+
- only build outputs when inputs have changed
1010

11-
this may save lots of time when building large projects
11+
This may save lots of time when building large projects.
1212

13-
Make is specified by posix and implemented by GNU with extensions
13+
Make is specified by POSIX and implemented by GNU with extensions
1414
It is the de facto standard make tool for POSIX systems.
1515

16-
#downsides of make
16+
#Downsides of Make
1717

1818
The main problems of make are:
1919

20-
- low cross-platform portability
21-
- its Yet Another Scripting Language to learn (and not a very powerful one at that)
20+
- not available on Windows
21+
- its Yet Another Scripting Language to learn, and uses Bash inside of it
2222

23-
#alternatives
23+
#Alternatives
2424

25-
Because of the downsides of make, many other make systems have been devised. None has yet dominated on most applications, but important ones include:
25+
Because of the downsides of make, many other make systems have been devised.
26+
None has yet dominated on most applications, but important ones include:
2627

27-
- cmake
28+
- CMake
2829

29-
Generates programs that make the project, including projects for IDEs.
30-
31-
For example, it can generated:
32-
33-
- POSIX `Makefiles` on Linux,
34-
- `cmd.exe` build scripts for Windows
35-
- CodeBlocks project
36-
37-
all from the same input file.
38-
39-
Makefiles for cmake (called `CMakeLists.txt`) are written in Yet Another Scripting Language.
40-
41-
- rake
30+
- Rake.
4231

4332
Similar to `make`, Ruby implemented with makefiles written in pure Ruby.
4433

45-
- apache ant
34+
- Apache Ant.
4635

4736
Written in Java, mainly used for Java project.
4837

@@ -52,20 +41,20 @@ Because of the downsides of make, many other make systems have been devised. Non
5241

5342
- <http://stackoverflow.com/questions/12669367/should-i-name-makefile-or-makefile>
5443

55-
`make` tries the following names, in order: GNUmakefile, makefile and Makefile
44+
make tries the following names, in order: `GNUmakefile`, `makefile` and `Makefile`.
5645

5746
`Makefile` has the advantages:
5847

59-
- appears at the top of ls by default (because ascii uppercase comes before ascii lowercase)
48+
- appears at the top of ls by default (because ASCII uppercase comes before ASCII lowercase)
6049
- is more conventional
6150

6251
`makefile` has the advantages:
6352

6453
- sticks to the other widespread convention of naming everything lowercase
6554

66-
#command line options
55+
#Command line options
6756

68-
- `-j5`: let make run in 5 threads.
57+
- `-j5`: let make run in 5 threads.
6958

7059
*Be warned*: this will make standard output of all threads mix up so the stdout will be meaningless.
7160

@@ -76,10 +65,10 @@ Because of the downsides of make, many other make systems have been devised. Non
7665
`a`, `b`, and `c` are run in parallel, it it might be the case that
7766
`c` *must* run only after `a` and `b`.
7867

79-
#sources
68+
#Sources
8069

81-
- <http://www.jfranken.de/homepages/johannes/vortraege/make_inhalt.en.html>
70+
- <http://www.jfranken.de/homepages/johannes/vortraege/make_inhalt.en.html>
8271

83-
good first tutorial to make
72+
Good first tutorial to make.
8473

85-
- <http://www-cip.physik.uni-bonn.de/pool/infos/make/advanced.html>
74+
- <http://www-cip.physik.uni-bonn.de/pool/infos/make/advanced.html>

posix.md

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
Cheat on POSIX.
2-
31
For a cheat on the POSIX C API see: <https://github.com/cirosantilli/cpp/tree/99ad8ab9aee7bf2d8c47c9e25f4631eddb556ccf/posix>
42

53
POSIX command line utilities shall not be discussed here because it is better to group utilities together with other non-POSIX utilities which have similar functions, for example discussing both `kill` (POSIX) and `killall` (non-POSIX) side by side.
64

7-
POSIX is means: Portable Operating System Interface for uniX.
5+
POSIX means: `Portable Operating System Interface for uniX`.
86

97
POSIX is also known as: Single Unix specification (SUS)
108

@@ -24,7 +22,7 @@ Currently, GNU/Linux and mac systems are largely POSIX compliant but not certifi
2422

2523
The specification if free to view.
2624

27-
Has several versions. The last at the time of writting was made in 2008
25+
Has several versions.
2826

2927
POSIX issue 7: IEEE formal name: `IEEE Std 1003.1-2008` highly recommended link: <http://pubs.opengroup.org/onlinepubs/9699919799/>
3028

@@ -62,7 +60,7 @@ Examples:
6260
- `ls`
6361
- `cat`
6462
- `mkdir`
65-
- `c99` and `fortr77`: compiler interfaces for C99 and Fortran77!
63+
- `c99` and `fortr77`: compiler interfaces for C99 and Fortran 77!
6664

6765
and tons of others which most people never heard of
6866

@@ -110,8 +108,21 @@ The following variables have fixed purposes in POSIX 7:
110108
- `PWD`
111109
- `TMPDIR`
112110
- `COLUMNS` and `LINES`: current width of terminal
113-
- `SHELL`: this is *not* the current shell! It contains the path of the default shell.
114-
- `TERM`: analogous to shell
111+
- `SHELL`: this is *not* the current shell! It contains the path of the default shell.
112+
- `TERM`: analogous to shell
113+
114+
The following variables determine the locale applications should use:
115+
116+
- `LC_CTYPE`: Character classification and case conversion.
117+
- `LC_COLLATE`: Collation order.
118+
- `LC_MONETARY`: Monetary formatting.
119+
- `LC_NUMERIC`: Numeric, non-monetary formatting.
120+
- `LC_TIME`: Date and time formats.
121+
- `LC_MESSAGES`: Formats of informative and diagnostic messages and interactive responses.
122+
123+
They are defined at: <http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html>
124+
POSIX also offers interfaces to modify those variables. The exact location where they are implemented
125+
is not specified. E.g., on Ubuntu 14.04, they are stored under `/etc/default/locale`.
115126

116127
The following variables don't have fixed purposes, but POSIX says that they must be used with caution:
117128

@@ -203,7 +214,9 @@ A few of the most interesting suggests for argument and utility name syntax:
203214
Good discussion about command line interface conventions: <http://stackoverflow.com/questions/10818443/short-long-options-with-option-argument-is-this-some-sort-of-convention>
204215

205216
- `--` marks the last of the options
217+
206218
- `-` means stdin/stdout when the utility expects a filename as argument
219+
207220
- `-W` is reserved for vendor options
208221

209222
##Exit status

sort.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Sort line wise.
2+
3+
Uses External R-Way merge.
4+
This algorithm allows to sort files that are larger than RAM memory.
5+
6+
Sort `f1`, `f2` together line wise:
7+
8+
sort f1 f2
9+
10+
Useful options:
11+
12+
- `-r` : reverse order
13+
14+
- `-n` : numbers
15+
16+
- `-u` : `uniq`
17+
18+
- `-t:`: set field separator to `:`
19+
20+
- `-k5`: sort by the Nth field.
21+
22+
Example:
23+
24+
sort -k 2,2n -k 4,4hr
25+
26+
- sort field `2` (from `2` to `2`) numerically
27+
- sort field `4` by human sizes and reverse
28+
29+
From field 2 to 2, numerically, then from 4 to 4, human and reverse
30+
31+
- `-R` : randomize: pseudo reverse of sorting.
32+
33+
- `-h` : sort by human readable file sizes like `1k`, `2M`, `3G`
34+
35+
- `-f` : ignore case
36+
37+
- `-fs`: ignore case and put always upper before lower
38+
39+
- `-b` : ignore leading blanks
40+
41+
- `-uf`: remove duplicates case insensitive
42+
43+
- `-m` : suppose `f1` and `f2` are already sorted, making sort faster
44+
45+
- `-c` : check if is sorted
46+
47+
#GNU extensions
48+
49+
- `-V`: sort dot separated versions numbers:
50+
51+
[ "$(printf '10.0\n9.10\n9.9\n' | sort -V)" = "$(printf '9.9\n9.10\n10.0\n')" ] || exit 1
52+

tee.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
POSIX 7
2+
3+
Echo stdin to multiple files ant to stdout.
4+
5+
To stdout and file:
6+
7+
echo a | tee file
8+
9+
To file and stderr:
10+
11+
echo a | tee file 1>&2
12+
13+
Append to file:
14+
15+
echo a | tee –a file
16+
17+
To multiple files:
18+
19+
echo a | tee f1 f2 f3
20+
21+
To multiple processes:
22+
23+
echo a | tee >(seqn 2) tee >(seqn 2) | tr a b
24+
25+
Process are run in parallel so the output order is variable.

tmux.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Window shortcuts:
8787

8888
Pane shortcuts:
8989

90-
- `n`: and `p`: next and previous window
90+
- `n` and `p`: next and previous window
9191
- `0`: to `9`: switch to given window ID
9292
- `%`: split horizontally
9393
- `"`: split vertically:
@@ -96,7 +96,7 @@ Pane shortcuts:
9696
- `o`: cycle through panes in order
9797
- `{}`: current pane's position with next / previous one
9898
- `!`: remove pane from window and open it in a window of its own
99-
- `x`: kill the current pane
99+
- `x`: kill / close the current pane
100100

101101
#Send keys
102102

tr.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
POSIX 7
2+
3+
Character-wise text operations.
4+
5+
Replace `a` by `A`, `b` by `B` and `c` by `C`:
6+
7+
[ `echo -n cab | tr abc ABC` = CAB ] || exit 1
8+
9+
Ranges work as expected. Convert to uppercase:
10+
11+
[ `echo -n cab | tr a-z A-Z` = CAB ] || exit 1
12+
13+
POSIX character classes are understood. Remove non-alphanumeric characters:
14+
15+
[ `echo -n 'ab_@' | tr -cd "[:alpha:]"` = ab ] || exit 1
16+
17+
- `-c`: complement and replace. Replace all non `abc` chars by `d`:
18+
19+
[ `echo -n dcba | tr -c abc 0` = 0cba ] || exit 1
20+
21+
- `-d`: delete `abc` characters:
22+
23+
[ `echo -n dcba | tr -d abc` = d ] || exit 1
24+
25+
- `s`: replace multiple consecutive `a` and `b` by a single character:
26+
27+
[ `echo -n aabbaac | tr -s ab` = abac ] || exit 1

0 commit comments

Comments
 (0)