File: 01_gnu_linux_tutorials.rawxml

package info (click to toggle)
debian-reference 2.128
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,588 kB
  • sloc: python: 586; makefile: 572; sh: 526; sed: 80
file content (2642 lines) | stat: -rw-r--r-- 186,279 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
<!-- vim: set sw=2 et sts=2 ft=xml: -->
<!-- Last content review: 2024-01-20T00:15:15 UTC -->
  <chapter id="_gnu_linux_tutorials">
    <title>GNU/Linux tutorials</title>
    <para>I think learning a computer system is like learning a new foreign language.  Although tutorial books and documentation are helpful, you have to practice it yourself.  In order to help you get started smoothly, I elaborate a few basic points.</para>
    <para>The powerful design of <ulink url="https://www.debian.org">Debian</ulink> <ulink url="https://en.wikipedia.org/wiki/GNU">GNU</ulink>/<ulink url="https://en.wikipedia.org/wiki/Linux">Linux</ulink> comes from the <ulink url="https://en.wikipedia.org/wiki/Unix">Unix</ulink> operating system, i.e., a <ulink url="https://en.wikipedia.org/wiki/Multi-user">multiuser</ulink>, <ulink url="https://en.wikipedia.org/wiki/Computer_multitasking">multitasking</ulink> operating system.  You must learn to take advantage of the power of these features and similarities between Unix and GNU/Linux.</para>
    <para>Don't shy away from Unix oriented texts and don't rely solely on GNU/Linux texts, as this robs you of much useful information.</para>
    <note> <para>If you have been using any <ulink url="https://en.wikipedia.org/wiki/Unix-like">Unix-like</ulink> system for a while with command line tools, you probably know everything I explain here.  Please use this as a reality check and refresher.</para> </note>
    <section id="_console_basics">
      <title>Console basics</title>
      <section id="_the_shell_prompt">
        <title>The shell prompt</title>
        <para>Upon starting the system, you are presented with the character based login screen if you did not install any <ulink url="https://en.wikipedia.org/wiki/Graphical_user_interface">GUI</ulink> environment such as <ulink url="https://en.wikipedia.org/wiki/GNOME">GNOME</ulink> or <ulink url="https://en.wikipedia.org/wiki/KDE">KDE</ulink> desktop system. Suppose your hostname is <literal>foo</literal>, the login prompt looks as follows.</para>
        <para>If you installed a <ulink url="https://en.wikipedia.org/wiki/Graphical_user_interface">GUI</ulink> environment, then you can still get to the character based login prompt by Ctrl-Alt-F3, and you can return to the GUI environment via Ctrl-Alt-F2 (see <xref linkend="_virtual_consoles"/> below for more).</para>
        <screen>foo login:</screen>
        <para>At the login prompt, you type your username, e.g. <literal>penguin</literal>, and press the Enter-key, then type your password and press the Enter-key again.</para>
        <note> <para>Following the Unix tradition, the username and password of the Debian system are case sensitive.  The username is usually chosen only from the lowercase.  The first user account is usually created during the installation.  Additional user accounts can be created with <literal>adduser</literal>(8) by root.</para> </note>
        <para>The system starts with the greeting message stored in "<literal>/etc/motd</literal>" (Message Of The Day) and presents a command prompt.</para>
        <screen>Debian GNU/Linux 12 foo tty3

foo login: penguin
Password:

Linux foo 6.5.0-0.deb12.4-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.5.10-1~bpo12+1 (2023-11-23) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

Last login: Wed Dec 20 09:39:00 JST 2023 on tty3
foo:~$</screen>
        <para>Now you are in the <ulink url="https://en.wikipedia.org/wiki/Shell_(computing)">shell</ulink>. The shell interprets your commands.</para>
      </section>
      <section id="_the_shell_prompt_under_gui">
        <title>The shell prompt under GUI</title>
        <para>If you installed a <ulink url="https://en.wikipedia.org/wiki/Graphical_user_interface">GUI</ulink> environment during the installation, you are presented with the graphical login screen upon starting your system.  You type your username and your password to login to the non-privileged user account.  Use tab to navigate between username and password, or use the primary click of the mouse.</para>
        <para>You can gain the shell prompt under GUI environment by starting a <literal>x-terminal-emulator</literal> program such as <literal>gnome-terminal</literal>(1), <literal>rxvt</literal>(1) or <literal>xterm</literal>(1).  Under the GNOME desktop environment, press SUPER-key (Windows-key) and typing in "terminal" to the search prompt does the trick.</para>
        <para>Under some other Desktop systems (like <literal>fluxbox</literal>), there may be no obvious starting point for the menu.  If this happens, just try (right) clicking the background of the desktop screen and hope for a menu to pop-up.</para>
      </section>
      <section id="_the_root_account">
        <title>The root account</title>
        <para>The root account is also called <ulink url="https://en.wikipedia.org/wiki/Superuser">superuser</ulink> or privileged user.  From this account, you can perform the following system administration tasks.</para>
        <itemizedlist>
          <listitem> <para> Read, write, and remove any files on the system irrespective of their file permissions </para> </listitem>
          <listitem> <para> Set file ownership and permissions of any files on the system </para> </listitem>
          <listitem> <para> Set the password of any non-privileged users on the system </para> </listitem>
          <listitem> <para> Login to any accounts without their passwords </para> </listitem>
        </itemizedlist>
        <para>This unlimited power of root account requires you to be considerate and responsible when using it.</para>
        <warning> <para>Never share the root password with others.</para> </warning>
        <note> <para>File permissions of a file (including hardware devices such as CD-ROM etc. which are just another file for the Debian system) may render it unusable or inaccessible by non-root users.  Although the use of root account is a quick way to test this kind of situation, its resolution should be done through proper setting of file permissions and user's group membership (see <xref linkend="_filesystem_permissions"/>).</para> </note>
      </section>
      <section id="_the_root_shell_prompt">
        <title>The root shell prompt</title>
        <para>Here are a few basic methods to gain the root shell prompt by using the root password.</para>
        <itemizedlist>
          <listitem> <para> Type <literal>root</literal> at the character based login prompt.  </para> </listitem>
          <listitem>
	    <para> Type "<literal>su -l</literal>" from any user shell prompt.  </para>
            <itemizedlist>
              <listitem> <para> This does not preserve the environment of the current user.  </para> </listitem>
            </itemizedlist>
          </listitem>
          <listitem>
            <para> Type "<literal>su</literal>" from any user shell prompt.  </para>
            <itemizedlist>
              <listitem> <para> This preserves some of the environment of the current user.  </para> </listitem>
            </itemizedlist>
          </listitem>
        </itemizedlist>
      </section>
      <section id="_gui_system_administration_tools">
        <title>GUI system administration tools</title>
        <para>When your desktop menu does not start GUI system administration tools automatically with the appropriate privilege, you can start them from the root shell prompt of the terminal emulator, such as <literal>gnome-terminal</literal>(1), <literal>rxvt</literal>(1), or <literal>xterm</literal>(1). See <xref linkend="_the_root_shell_prompt"/> and <xref linkend="_x_server_connection"/>.</para>
        <warning>
          <para>Never start the GUI display/session manager under the root account by typing in <literal>root</literal> to the prompt of the display manager such as <literal>gdm3</literal>(1).</para>
          <para>Never run untrusted remote GUI program under X Window when critical information is displayed since it may eavesdrop your X screen.</para>
        </warning>
      </section>
      <section id="_virtual_consoles">
        <title>Virtual consoles</title>
        <para>In the default Debian system, there are six switchable <ulink url="https://en.wikipedia.org/wiki/VT100">VT100-like</ulink> character consoles available to start the command shell directly on the Linux host.  Unless you are in a GUI environment, you can switch between the virtual consoles by pressing the <literal>Left-Alt-key</literal> and one of the <literal>F1</literal> — <literal>F6</literal> keys simultaneously.  Each character console allows independent login to the account and offers the multiuser environment.  This multiuser environment is a great Unix feature, and very addictive.</para>
        <para>If you are in the GUI environment, you gain access to the character console 3 by pressing <literal>Ctrl-Alt-F3</literal> key, i.e., the <literal>left-Ctrl-key</literal>, the <literal>left-Alt-key</literal>, and the <literal>F3-key</literal> are pressed together.   You can get back to the GUI environment, normally running on the virtual console 2, by pressing <literal>Alt-F2</literal>.</para>
        <para>You can alternatively change to another virtual console, e.g. to the console 3, from the commandline.</para>
        <screen># chvt 3</screen>
      </section>
      <section id="_how_to_leave_the_command_prompt">
        <title>How to leave the command prompt</title>
        <para>You type <literal>Ctrl-D</literal>, i.e., the <literal>left-Ctrl-key</literal> and the <literal>d-key</literal> pressed together, at the command prompt to close the shell activity.  If you are at the character console, you return to the login prompt with this.  Even though these control characters are referred as "control D" with the upper case, you do not need to press the Shift-key. The short hand expression, <literal>^D</literal>, is also used for <literal>Ctrl-D</literal>.  Alternately, you can type "exit".</para>
        <para>If you are at <literal>x-terminal-emulator</literal>(1), you can close <literal>x-terminal-emulator</literal> window with this.</para>
      </section>
      <section id="_how_to_shutdown_the_system">
        <title>How to shutdown the system</title>
        <para>Just like any other modern OS where the file operation involves <ulink url="https://en.wikipedia.org/wiki/Cache">caching data</ulink> in memory for improved performance, the Debian system needs the proper shutdown procedure before power can safely be turned off. This is to maintain the integrity of files, by forcing all changes in memory to be written to disk. If the software power control is available, the shutdown procedure automatically turns off power of the system. (Otherwise, you may have to press power button for few seconds after the shutdown procedure.)</para>
        <para>You can shutdown the system under the normal multiuser mode from the commandline.</para>
        <screen># shutdown -h now</screen>
        <para>You can shutdown the system under the single-user mode from the commandline.</para>
        <screen># poweroff -i -f</screen>
        <para>See <xref linkend="_how_to_shutdown_the_remote_system_on_ssh"/>.</para>
      </section>
      <section id="_recovering_a_sane_console">
        <title>Recovering a sane console</title>
        <para>When the screen goes berserk after doing some funny things such as "<literal>cat <emphasis>some-binary-file</emphasis></literal>", type "<literal>reset</literal>" at the command prompt. You may not be able to see the command echoed as you type.  You may also issue "<literal>clear</literal>" to clean up the screen.</para>
      </section>
      <section id="_additional_package_suggestions_for_the_newbie">
        <title>Additional package suggestions for the newbie</title>
        <para>Although even the minimal installation of the Debian system without any desktop environment tasks provides the basic Unix functionality, it is a good idea to install few additional commandline and curses based character terminal packages such as <literal>mc</literal> and <literal>vim</literal> with <literal>apt-get</literal>(8) for beginners to get started by the following.</para>
        <screen># apt-get update
 ...
# apt-get install mc vim sudo aptitude
 ...</screen>
        <para>If you already had these packages installed, no new packages are installed.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of interesting text-mode program packages</title>
          <tgroup cols="4">
            <colspec colwidth="59pt" align="left"/>
            <colspec colwidth="76pt" align="left"/>
            <colspec colwidth="70pt" align="left"/>
            <colspec colwidth="407pt" align="left"/>
            <thead>
              <row>
                <entry> package </entry>
                <entry> popcon </entry>
                <entry> size </entry>
                <entry> description </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>mc</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> A text-mode full-screen file manager </entry>
              </row>
              <row>
                <entry> <literal>sudo</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> A program to allow limited root privileges to users </entry>
              </row>
              <row>
                <entry> <literal>vim</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Unix text editor Vi IMproved, a programmers text editor (standard version) </entry>
              </row>
              <row>
                <entry> <literal>vim-tiny</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Unix text editor Vi IMproved, a programmers text editor (compact version) </entry>
              </row>
              <row>
                <entry> <literal>emacs-nox</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> GNU project Emacs, the Lisp based extensible text editor </entry>
              </row>
              <row>
                <entry> <literal>w3m</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Text-mode WWW browsers </entry>
              </row>
              <row>
                <entry> <literal>gpm</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> The Unix style cut-and-paste on the text console (daemon) </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>It may be a good idea to read some informative documentations.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of informative documentation packages</title>
          <tgroup cols="4">
            <colspec colwidth="124pt" align="left"/>
            <colspec colwidth="76pt" align="left"/>
            <colspec colwidth="70pt" align="left"/>
            <colspec colwidth="342pt" align="left"/>
            <thead>
              <row>
                <entry> package </entry>
                <entry> popcon </entry>
                <entry> size </entry>
                <entry> description </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>doc-debian</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Debian Project documentation, (Debian FAQ) and other documents </entry>
              </row>
              <row>
                <entry> <literal>debian-policy</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Debian Policy Manual and related documents </entry>
              </row>
              <row>
                <entry> <literal>developers-reference</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Guidelines and information for Debian developers </entry>
              </row>
              <row>
                <entry> <literal>debmake-doc</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Guide for Debian Maintainers </entry>
              </row>
              <row>
                <entry> <literal>debian-history</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> History of the Debian Project </entry>
              </row>
              <row>
                <entry> <literal>debian-faq</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Debian FAQ </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>You can install some of these packages by the following.</para>
        <screen># apt-get install package_name</screen>
      </section>
      <section id="_an_extra_user_account">
        <title>An extra user account</title>
        <para>If you do not want to use your main user account for the following training activities, you can create a training user account, e.g. <literal>fish</literal> by the following.</para>
        <screen># adduser fish</screen>
        <para>Answer all questions.</para>
        <para>This creates a new account named as <literal>fish</literal>.  After your practice, you can remove this user account and its home directory by the following.</para>
        <screen># deluser --remove-home fish</screen>
        <para>On non-Debian and specialized Debian systems, above activities need to use lower level <literal>useradd</literal>(8) and <literal>userdel</literal>(8) utilities, instead.</para>
      </section>
      <section id="_sudo_configuration">
        <title>sudo configuration</title>
        <para>For the typical single user workstation such as the desktop Debian system on the laptop PC, it is common to deploy simple configuration of <literal>sudo</literal>(8) as follows to let the non-privileged user, e.g. <literal>penguin</literal>, to gain administrative privilege just with his user password but without the root password.</para>
        <screen># echo "penguin  ALL=(ALL) ALL" &gt;&gt; /etc/sudoers</screen>
        <para>Alternatively, it is also common to do as follows to let the non-privileged user, e.g. <literal>penguin</literal>, to gain administrative privilege without any password.</para>
        <screen># echo "penguin  ALL=(ALL) NOPASSWD:ALL" &gt;&gt; /etc/sudoers</screen>
        <para>This trick should only be used for the single user workstation which you administer and where you are the only user.</para>
        <warning> <para>Do not set up accounts of regular users on multiuser workstation like this because it would be very bad for system security.</para> </warning>
        <caution>
          <para>The password and the account of the <literal>penguin</literal> in the above example requires as much protection as the root password and the root account.</para>
          <para>Administrative privilege in this context belongs to someone authorized to perform the system administration task on the workstation.  Never give some manager in the Admin department of your company or your boss such privilege unless they are authorized and capable.</para>
        </caution>
        <note>
          <para>For providing access privilege to limited devices and limited files, you should consider to use <emphasis role="strong">group</emphasis> to provide limited access instead of using the <literal>root</literal> privilege via <literal>sudo</literal>(8).</para>
          <para>With more thoughtful and careful configuration, <literal>sudo</literal>(8) can grant limited administrative privileges to other users on a shared system without sharing the root password.  This can help with accountability with hosts with multiple administrators so you can tell who did what.  On the other hand, you might not want anyone else to have such privileges.</para>
        </note>
      </section>
      <section id="_play_time">
        <title>Play time</title>
        <para>Now you are ready to play with the Debian system without risks as long as you use the non-privileged user account.</para>
        <para>This is because the Debian system is, even after the default installation, configured with proper file permissions which prevent non-privileged users from damaging the system.  Of course, there may still be some holes which can be exploited but those who worry about these issues should not be reading this section but should be reading <ulink url="https://www.debian.org/doc/manuals/securing-debian-manual/">Securing Debian Manual</ulink>.</para>
        <para>We learn the Debian system as a <ulink url="https://en.wikipedia.org/wiki/Unix-like">Unix-like</ulink> system with the following.</para>
        <itemizedlist>
          <listitem> <para><xref linkend="_unix_like_filesystem"/> (basic concept) </para> </listitem>
          <listitem> <para><xref linkend="_midnight_commander_mc"/> (survival method) </para> </listitem>
          <listitem> <para><xref linkend="_the_basic_unix_like_work_environment"/> (basic method) </para> </listitem>
          <listitem> <para><xref linkend="_the_simple_shell_command"/> (shell mechanism) </para> </listitem>
          <listitem> <para><xref linkend="_unix_like_text_processing"/> (text processing method) </para> </listitem>
        </itemizedlist>
      </section>
    </section>
    <section id="_unix_like_filesystem">
      <title>Unix-like filesystem</title>
      <para>In GNU/Linux and other <ulink url="https://en.wikipedia.org/wiki/Unix-like">Unix-like</ulink> operating systems, <ulink url="https://en.wikipedia.org/wiki/Computer_file">files</ulink> are organized into <ulink url="https://en.wikipedia.org/wiki/Directory_(file_systems)">directories</ulink>.  All files and directories are arranged in one big tree rooted at "<literal>/</literal>". It's called a tree because if you draw the filesystem, it looks like a tree but it is upside down.</para>
      <para>These files and directories can be spread out over several devices. <literal>mount</literal>(8) serves to attach the filesystem found on some device to the big file tree.  Conversely, <literal>umount</literal>(8) detaches it again.  On recent Linux kernels, <literal>mount</literal>(8) with some options can bind part of a file tree somewhere else or can mount filesystem as shared, private, slave, or unbindable.  Supported mount options for each filesystem are available in "<literal>/usr/share/doc/linux-doc-*/Documentation/filesystems/</literal>".</para>
      <para><emphasis role="strong">Directories</emphasis> on Unix systems are called <emphasis role="strong">folders</emphasis> on some other systems.  Please also note that there is no concept for <emphasis role="strong">drive</emphasis> such as "<literal>A:</literal>" on any Unix system.  There is one filesystem, and everything is included. This is a huge advantage compared to Windows.</para>
      <section id="_unix_file_basics">
        <title>Unix file basics</title>
        <para>Here are some Unix file basics.</para>
        <itemizedlist>
          <listitem> <para> Filenames are <emphasis role="strong">case sensitive</emphasis>.  That is, "<literal>MYFILE</literal>" and "<literal>MyFile</literal>" are different files.  </para> </listitem>
          <listitem> <para> The <emphasis role="strong">root directory</emphasis> means root of the filesystem referred as simply "<literal>/</literal>".  Don't confuse this with the home directory for the root user: "<literal>/root</literal>".  </para> </listitem>
          <listitem> <para> Every directory has a name which can contain any letters or symbols <emphasis role="strong">except "<literal>/</literal>"</emphasis>.  The root directory is an exception; its name is "<literal>/</literal>" (pronounced "slash" or "the root directory") and it cannot be renamed.  </para> </listitem>
          <listitem> <para> Each file or directory is designated by a <emphasis role="strong">fully-qualified filename</emphasis>, <emphasis role="strong">absolute filename</emphasis>, or <emphasis role="strong">path</emphasis>, giving the sequence of directories which must be passed through to reach it.  The three terms are synonymous.  </para> </listitem>
          <listitem> <para> All <emphasis role="strong">fully-qualified filenames</emphasis> begin with the "<literal>/</literal>" directory, and there's a "<literal>/</literal>" between each directory or file in the filename.  The first "<literal>/</literal>" is the top level directory, and the other "<literal>/</literal>"'s separate successive subdirectories, until we reach the last entry which is the name of the actual file.  The words used here can be confusing.  Take the following  <emphasis role="strong">fully-qualified filename</emphasis> as an example: "<literal>/usr/share/keytables/us.map.gz</literal>".  However, people also refers to its basename "<literal>us.map.gz</literal>" alone as a filename.  </para> </listitem>
          <listitem> <para> The root directory has a number of branches, such as "<literal>/etc/</literal>" and "<literal>/usr/</literal>".  These subdirectories in turn branch into still more subdirectories, such as "<literal>/etc/systemd/</literal>" and "<literal>/usr/local/</literal>".  The whole thing viewed collectively is called the <emphasis role="strong">directory tree</emphasis>.  You can think of an absolute filename as a route from the base of the tree ("<literal>/</literal>") to the end of some branch (a file).  You also hear people talk about the directory tree as if it were a <emphasis role="strong">family</emphasis> tree encompassing all direct descendants of a single figure called the root directory ("<literal>/</literal>"): thus subdirectories have <emphasis role="strong">parents</emphasis>, and a path shows the complete ancestry of a file.  There are also relative paths that begin somewhere other than the root directory.  You should remember that the directory "<literal>../</literal>" refers to the parent directory.  This terminology also applies to other directory like structures, such as hierarchical data structures.  </para> </listitem>
          <listitem> <para> There's no special directory path name component that corresponds to a physical device, such as your hard disk.  This differs from <ulink url="https://en.wikipedia.org/wiki/RT-11">RT-11</ulink>, <ulink url="https://en.wikipedia.org/wiki/CP/M">CP/M</ulink>, <ulink url="https://en.wikipedia.org/wiki/OpenVMS">OpenVMS</ulink>, <ulink url="https://en.wikipedia.org/wiki/MS-DOS">MS-DOS</ulink>, <ulink url="https://en.wikipedia.org/wiki/AmigaOS">AmigaOS</ulink>, and <ulink url="https://en.wikipedia.org/wiki/Microsoft_Windows">Microsoft Windows</ulink>, where the path contains a device name such as "<literal>C:\</literal>".  (However, directory entries do exist that refer to physical devices as a part of the normal filesystem.  See <xref linkend="_filesystem_internals"/>.) </para> </listitem>
        </itemizedlist>
        <note> <para>While you <emphasis role="strong">can</emphasis> use almost any letters or symbols in a file name, in practice it is a bad idea to do so.  It is better to avoid any characters that often have special meanings on the command line, including spaces, tabs, newlines, and other special characters: <literal>{ } ( ) [ ] ' ` " \ / &gt; &lt; | ; ! # &amp; ^ * % @ $</literal> .  If you want to separate words in a name, good choices are the period, hyphen, and underscore.  You could also capitalize each word, "<literal>LikeThis</literal>". Experienced Linux users tend to avoid spaces in filenames.</para> </note>
        <note> <para>The word "root" can mean either "root user" or "root directory".  The context of their usage should make it clear.</para> </note>
        <note> <para>The word <emphasis role="strong">path</emphasis> is used not only for <emphasis role="strong">fully-qualified filename</emphasis> as above but also for the <emphasis role="strong">command search path</emphasis>.  The intended meaning is usually clear from the context.</para> </note>
        <para>The detailed best practices for the file hierarchy are described in the Filesystem Hierarchy Standard ("<literal>/usr/share/doc/debian-policy/fhs/fhs-2.3.txt.gz</literal>" and <literal>hier</literal>(7)).  You should remember the following facts as the starter.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of usage of key directories</title>
          <tgroup cols="2">
            <colspec colwidth="65pt" align="left"/>
            <colspec colwidth="499pt" align="left"/>
            <thead>
              <row>
                <entry> directory </entry>
                <entry> usage of the directory </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>/</literal> </entry>
                <entry> the root directory </entry>
              </row>
              <row>
                <entry> <literal>/etc/</literal> </entry>
                <entry> system wide configuration files </entry>
              </row>
              <row>
                <entry> <literal>/var/log/</literal> </entry>
                <entry> system log files </entry>
              </row>
              <row>
                <entry> <literal>/home/</literal> </entry>
                <entry> all the home directories for all non-privileged users </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
      </section>
      <section id="_filesystem_internals">
        <title>Filesystem internals</title>
        <para>Following the <emphasis role="strong">Unix tradition</emphasis>, the Debian GNU/Linux system provides the <ulink url="https://en.wikipedia.org/wiki/File_system">filesystem</ulink> under which physical data on hard disks and other storage devices reside, and the interaction with the hardware devices such as console screens and remote serial consoles are represented in an unified manner under "<literal>/dev/</literal>".</para>
        <para>Each file, directory, named pipe (a way two programs can share data), or physical device on a Debian GNU/Linux system has a data structure called an <ulink url="https://en.wikipedia.org/wiki/Inode">inode</ulink> which describes its associated attributes such as the user who owns it (owner), the group that it belongs to, the time last accessed, etc.  The idea of representing just about everything in the filesystem was a Unix innovation, and modern Linux kernels have developed this idea ever further. Now, even information about processes running in the computer can be found in the filesystem.</para>
        <para>This abstract and unified representation of physical entities and internal processes is very powerful since this allows us to use the same command for the same kind of operation on many totally different devices. It is even possible to change the way the kernel works by writing data to special files that are linked to running processes.</para>
        <tip> <para>If you need to identify the correspondence between the file tree and the physical entity, execute <literal>mount</literal>(8) with no arguments.</para> </tip>
      </section>
      <section id="_filesystem_permissions">
        <title>Filesystem permissions</title>
        <para><ulink url="https://en.wikipedia.org/wiki/File_system_permissions">Filesystem permissions</ulink> of <ulink url="https://en.wikipedia.org/wiki/Unix-like">Unix-like</ulink> system are defined for three categories of affected users.</para>
        <itemizedlist>
          <listitem> <para> The <emphasis role="strong">user</emphasis> who owns the file (<emphasis role="strong">u</emphasis>) </para> </listitem>
          <listitem> <para> Other users in the <emphasis role="strong">group</emphasis> which the file belongs to (<emphasis role="strong">g</emphasis>) </para> </listitem>
          <listitem> <para> All <emphasis role="strong">other</emphasis> users (<emphasis role="strong">o</emphasis>) also referred to as "world" and "everyone" </para> </listitem>
        </itemizedlist>
        <para>For the file, each corresponding permission allows following actions.</para>
        <itemizedlist>
          <listitem> <para> The <emphasis role="strong">read</emphasis> (<emphasis role="strong">r</emphasis>) permission allows owner to examine contents of the file.  </para> </listitem>
          <listitem> <para> The <emphasis role="strong">write</emphasis> (<emphasis role="strong">w</emphasis>) permission allows owner to modify the file.  </para> </listitem>
          <listitem> <para> The <emphasis role="strong">execute</emphasis> (<emphasis role="strong">x</emphasis>) permission allows owner to run the file as a command.  </para> </listitem>
        </itemizedlist>
        <para>For the directory, each corresponding permission allows following actions.</para>
        <itemizedlist>
          <listitem> <para> The <emphasis role="strong">read</emphasis> (<emphasis role="strong">r</emphasis>) permission allows owner to list contents of the directory.  </para> </listitem>
          <listitem> <para> The <emphasis role="strong">write</emphasis> (<emphasis role="strong">w</emphasis>) permission allows owner to add or remove files in the directory.  </para> </listitem>
          <listitem> <para> The <emphasis role="strong">execute</emphasis> (<emphasis role="strong">x</emphasis>) permission allows owner to access files in the directory.  </para> </listitem>
        </itemizedlist>
        <para>Here, the <emphasis role="strong">execute</emphasis> permission on a directory means not only to allow reading of files in that directory but also to allow viewing their attributes, such as the size and the modification time.</para>
        <para><literal>ls</literal>(1) is used to display permission information (and more) for files and directories.  When it is invoked with the "<literal>-l</literal>" option, it displays the following information in the order given.</para>
        <itemizedlist>
          <listitem> <para><emphasis role="strong">Type of file</emphasis> (first character) </para> </listitem>
          <listitem> <para> Access <emphasis role="strong">permission</emphasis> of the file (nine characters, consisting of three characters each for user, group, and other in this order) </para> </listitem>
          <listitem> <para><emphasis role="strong">Number of hard links</emphasis> to the file </para> </listitem>
          <listitem> <para> Name of the <emphasis role="strong">user</emphasis> who owns the file </para> </listitem>
          <listitem> <para> Name of the <emphasis role="strong">group</emphasis> which the file belongs to </para> </listitem>
          <listitem> <para><emphasis role="strong">Size</emphasis> of the file in characters (bytes) </para> </listitem>
          <listitem> <para><emphasis role="strong">Date and time</emphasis> of the file (mtime) </para> </listitem>
          <listitem> <para><emphasis role="strong">Name</emphasis> of the file </para> </listitem>
        </itemizedlist>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of the first character of "<literal>ls -l</literal>" output</title>
          <tgroup cols="2">
            <colspec colwidth="54pt" align="left"/>
            <colspec colwidth="119pt" align="left"/>
            <thead>
              <row>
	        <entry> character </entry>
                <entry> meaning </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>-</literal> </entry>
                <entry> normal file </entry>
              </row>
              <row>
                <entry> <literal>d</literal> </entry>
                <entry> directory </entry>
              </row>
              <row>
                <entry> <literal>l</literal> </entry>
                <entry> symlink </entry>
              </row>
              <row>
                <entry> <literal>c</literal> </entry>
                <entry> character device node </entry>
              </row>
              <row>
                <entry> <literal>b</literal> </entry>
                <entry> block device node </entry>
              </row>
              <row>
                <entry> <literal>p</literal> </entry>
                <entry> named pipe </entry>
              </row>
              <row>
                <entry> <literal>s</literal> </entry>
                <entry> socket </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para><literal>chown</literal>(1) is used from the root account to change the owner of the file.  <literal>chgrp</literal>(1) is used from the file's owner or root account to change the group of the file.  <literal>chmod</literal>(1) is used from the file's owner or root account to change file and directory access permissions.  Basic syntax to manipulate a <literal>foo</literal> file is the following.</para>
        <screen># chown <emphasis>newowner</emphasis> foo
# chgrp <emphasis>newgroup</emphasis> foo
# chmod  [ugoa][+-=][rwxXst][,...] foo</screen>
        <para>For example, you can make a directory tree to be owned by a user <literal>foo</literal> and shared by a group <literal>bar</literal> by the following.</para>
        <screen># cd <emphasis>/some/location/</emphasis>
# chown -R foo:bar .
# chmod -R ug+rwX,o=rX .</screen>
        <para>There are three more special permission bits.</para>
        <itemizedlist>
          <listitem> <para> The <emphasis role="strong">set user ID</emphasis> bit (<emphasis role="strong">s</emphasis> or <emphasis role="strong">S</emphasis> instead of user's <emphasis role="strong">x</emphasis>) </para> </listitem>
          <listitem> <para> The <emphasis role="strong">set group ID</emphasis> bit (<emphasis role="strong">s</emphasis> or <emphasis role="strong">S</emphasis> instead of group's <emphasis role="strong">x</emphasis>) </para> </listitem>
          <listitem> <para> The <emphasis role="strong">sticky</emphasis> bit (<emphasis role="strong">t</emphasis> or <emphasis role="strong">T</emphasis> instead of other's <emphasis role="strong">x</emphasis>) </para> </listitem>
        </itemizedlist>
        <para>Here the output of "<literal>ls -l</literal>" for these bits is <emphasis role="strong">capitalized</emphasis> if execution bits hidden by these outputs are <emphasis role="strong">unset</emphasis>.</para>
        <para>Setting <emphasis role="strong">set user ID</emphasis> on an executable file allows a user to execute the executable file with the owner ID of the file (for example <emphasis role="strong">root</emphasis>).  Similarly, setting <emphasis role="strong">set group ID</emphasis> on an executable file allows a user to execute the executable file with the group ID of the file (for example <emphasis role="strong">root</emphasis>).  Because these settings can cause security risks, enabling them requires extra caution.</para>
        <para>Setting <emphasis role="strong">set group ID</emphasis> on a directory enables the <ulink url="https://en.wikipedia.org/wiki/Berkeley_Software_Distribution">BSD-like</ulink> file creation scheme where all files created in the directory belong to the <emphasis role="strong">group</emphasis> of the directory.</para>
        <para>Setting the <emphasis role="strong">sticky bit</emphasis> on a directory prevents a file in the directory from being removed by a user who is not the owner of the file.  In order to secure contents of a file in world-writable directories such as "<literal>/tmp</literal>" or in group-writable directories, one must not only reset the <emphasis role="strong">write</emphasis> permission for the file but also set the <emphasis role="strong">sticky bit</emphasis> on the directory.  Otherwise, the file can be removed and a new file can be created with the same name by any user who has write access to the directory.</para>
        <para>Here are a few interesting examples of file permissions.</para>
        <screen>$ ls -l /etc/passwd /etc/shadow /dev/ppp /usr/sbin/exim4
crw------T 1 root root   108, 0 Oct 16 20:57 /dev/ppp
-rw-r--r-- 1 root root     2761 Aug 30 10:38 /etc/passwd
-rw-r----- 1 root shadow   1695 Aug 30 10:38 /etc/shadow
-rwsr-xr-x 1 root root   973824 Sep 23 20:04 /usr/sbin/exim4
$ ls -ld /tmp /var/tmp /usr/local /var/mail /usr/src
drwxrwxrwt 14 root root  20480 Oct 16 21:25 /tmp
drwxrwsr-x 10 root staff  4096 Sep 29 22:50 /usr/local
drwxr-xr-x 10 root root   4096 Oct 11 00:28 /usr/src
drwxrwsr-x  2 root mail   4096 Oct 15 21:40 /var/mail
drwxrwxrwt  3 root root   4096 Oct 16 21:20 /var/tmp</screen>
        <para>There is an alternative numeric mode to describe file permissions with <literal>chmod</literal>(1).  This numeric mode uses 3 to 4 digit wide octal (radix=8) numbers.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>The numeric mode for file permissions in <literal>chmod</literal>(1) commands</title>
          <tgroup cols="2">
            <colspec colwidth="103pt" align="left"/>
            <colspec colwidth="456pt" align="left"/>
            <thead>
              <row>
                <entry> digit </entry>
                <entry> meaning </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> 1st optional digit </entry>
                <entry> sum of <emphasis role="strong">set user ID</emphasis> (=4), <emphasis role="strong">set group ID</emphasis> (=2), and <emphasis role="strong">sticky bit</emphasis> (=1) </entry>
              </row>
              <row>
                <entry> 2nd digit </entry>
                <entry> sum of <emphasis role="strong">read</emphasis> (=4), <emphasis role="strong">write</emphasis> (=2), and <emphasis role="strong">execute</emphasis> (=1) permissions for <emphasis role="strong">user</emphasis> </entry>
              </row>
              <row>
                <entry> 3rd digit </entry>
                <entry> ditto for <emphasis role="strong">group</emphasis> </entry>
              </row>
              <row>
                <entry> 4th digit </entry>
                <entry> ditto for <emphasis role="strong">other</emphasis> </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>This sounds complicated but it is actually quite simple.  If you look at the first few (2-10) columns from "<literal>ls -l</literal>" command output and read it as a binary (radix=2) representation of file permissions ("-" being "0" and "rwx" being "1"), the last 3 digit of the numeric mode value should make sense as an octal (radix=8) representation of file permissions to you.</para>
        <para>For example, try the following</para>
        <screen>$ touch foo bar
$ chmod u=rw,go=r foo
$ chmod 644 bar
$ ls -l foo bar
-rw-r--r-- 1 penguin penguin 0 Oct 16 21:39 bar
-rw-r--r-- 1 penguin penguin 0 Oct 16 21:35 foo</screen>
        <tip>
          <para>If you need to access information displayed by "<literal>ls -l</literal>" in shell script, you should use pertinent commands such as <literal>test</literal>(1), <literal>stat</literal>(1) and <literal>readlink</literal>(1).  The shell builtin such as "<literal>[</literal>" or "<literal>test</literal>" may be used too.</para>
        </tip>
      </section>
      <section id="_control_of_permissions_for_newly_created_files_umask">
        <title>Control of permissions for newly created files: umask</title>
        <para>What permissions are applied to a newly created file or directory is restricted by the <literal>umask</literal> shell builtin command.  See <literal>dash</literal>(1), <literal>bash</literal>(1), and <literal>builtins</literal>(7).</para>
        <screen> (file permissions) = (requested file permissions) &amp; ~(umask value)</screen>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>The <emphasis role="strong">umask</emphasis> value examples</title>
          <tgroup cols="4">
            <colspec colwidth="38pt" align="left"/>
            <colspec colwidth="135pt" align="left"/>
            <colspec colwidth="162pt" align="left"/>
            <colspec colwidth="141pt" align="left"/>
            <thead>
              <row>
                <entry> umask </entry>
                <entry> file permissions created </entry>
                <entry> directory permissions created </entry>
                <entry> usage </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>0022</literal> </entry>
                <entry> <literal>-rw-r--r--</literal> </entry>
                <entry> <literal>-rwxr-xr-x</literal> </entry>
                <entry> writable only by the user </entry>
              </row>
              <row>
                <entry> <literal>0002</literal> </entry>
                <entry> <literal>-rw-rw-r--</literal> </entry>
                <entry> <literal>-rwxrwxr-x</literal> </entry>
                <entry> writable by the group </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>The Debian system uses a user private group (UPG) scheme as its default. A UPG is created whenever a new user is added to the system. A UPG has the same name as the user for which it was created and that user is the only member of the UPG. UPG scheme makes it safe to set umask to <literal>0002</literal> since every user has their own private group.  (In some Unix variants, it is quite common to setup all normal users belonging to a single <emphasis role="strong"><literal>users</literal></emphasis> group and is a good idea to set umask to <literal>0022</literal> for security in such cases.)</para>
        <tip> <para>Enable UPG by putting "<literal>umask 002</literal>" in the <literal>~/.bashrc</literal> file.</para> </tip>
      </section>
      <section id="_permissions_for_groups_of_users_group">
        <title>Permissions for groups of users (group)</title>
        <warning> <para>Please make sure to save unsaved changes before doing reboot or similar actions.</para> </warning>
        <!--
          * "adduser" package is "Priority: important" and not "Priority: required"
          * I had trouble after "kill -TERM -1".
          * I had odd password prompt and WIFI was missing found by using
              $ iwconfig
          * My solution was to run:
              $ systemctl restart NetworkManager.service
          * For trouble shooting this kind of events, people also use:
            $ rfkill list
            $ lspci -nnk | grep -iA3 net
          * Interesting references
            https://github.com/id01/nm-applet-fix
            https://www.freedesktop.org/wiki/Software/urfkill/
            https://askubuntu.com/questions/425155/my-wireless-wifi-connection-does-not-work-what-information-is-needed-to-diagnos
            https://askubuntu.com/questions/1476184/i-have-a-wifi-connection-but-it-wont-show-up-in-gui
            https://bugzilla.kernel.org/show_bug.cgi?id=203709
            https://unix.stackexchange.com/questions/755576/cannot-connect-to-wi-fi-wireless-toggle-is-not-displayed
            https://stackoverflow.com/questions/32334870/how-to-do-a-true-rescan-of-pcie-bus
        -->
        <para>You can add a user <literal>penguin</literal> to a group <literal>bird</literal> in two steps:</para>
        <itemizedlist>
          <listitem>
            <para> Change group configuration using one of following:</para>
            <itemizedlist>
              <listitem> <para> Execute "<literal>sudo usermod -aG bird penguin</literal>". </para> </listitem>
              <listitem> <para> Execute "<literal>sudo adduser penguin bird</literal>". (only on typical Debian systems) </para></listitem>
              <listitem> <para> Execute "<literal>sudo vigr</literal>" for <literal>/etc/group</literal> and "<literal>sudo vigr -s</literal>" for <literal>/etc/gshadow</literal> to append <literal>penguin</literal> in the line for <literal>bird</literal>. </para> </listitem>
            </itemizedlist>
          </listitem>
          <listitem>
            <para> Apply configuration using one of following:</para>
            <itemizedlist>
              <listitem> <para> Cold reboot and login. (Best option) </para> </listitem>
              <listitem> <para> Execute "<literal>kill -TERM -1</literal>" and do some fix-up actions such as "<literal>systemctl restart NetworkManager.service</literal>".</para> </listitem>
              <listitem> <para> Logout via GUI menu and login. </para> </listitem>
            </itemizedlist>
          </listitem>
        </itemizedlist>
        <para>You can remove a user <literal>penguin</literal> from a group <literal>bird</literal> in two steps:</para>
        <itemizedlist>
          <listitem>
            <para> Change group configuration using one of following:</para>
            <itemizedlist>
              <listitem> <para> Execute "<literal>sudo usermod -rG bird penguin</literal>". </para> </listitem>
              <listitem> <para> Execute "<literal>sudo deluser penguin bird</literal>". (only on typical Debian systems) </para></listitem>
              <listitem> <para> Execute "<literal>sudo vigr</literal>" for <literal>/etc/group</literal> and "<literal>sudo vigr -s</literal>" for <literal>/etc/gshadow</literal> to remove <literal>penguin</literal> in the line for <literal>bird</literal>. </para> </listitem>
            </itemizedlist>
          </listitem>
          <listitem>
            <para> Apply configuration using one of following:</para>
            <itemizedlist>
              <listitem> <para> Cold reboot and login. (Best option) </para> </listitem>
              <listitem> <para> Execute "<literal>kill -TERM -1</literal>" and do some fix-up actions such as "<literal>systemctl restart NetworkManager.service</literal>".</para> </listitem>
              <listitem> <para> Logout via GUI menu is not an option for Gnome Desktop. </para> </listitem>
            </itemizedlist>
          </listitem>
        </itemizedlist>
        <para> Any warm reboot attempts are fragile replacements of the real cold reboot under the modern desktop system.</para>
        <note> <para>Alternatively, you may dynamically add users to groups during the authentication process by adding "<literal>auth optional pam_group.so</literal>" line to "<literal>/etc/pam.d/common-auth</literal>" and setting "<literal>/etc/security/group.conf</literal>".  (See <xref linkend="_authentication"/>.)</para> </note>
        <para>The hardware devices are just another kind of file on the Debian system.  If you have problems accessing devices such as CD-ROM and USB memory stick from a user account, you should make that user a member of the relevant group.</para>
        <para>Some notable system-provided groups allow their members to access particular files and devices without <literal>root</literal> privilege.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of notable system-provided groups for file access</title>
          <tgroup cols="2">
            <colspec colwidth="54pt" align="left"/>
            <colspec colwidth="423pt" align="left"/>
            <thead>
              <row>
                <entry> group </entry>
                <entry> description for accessible files and devices </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>dialout</literal> </entry>
                <entry> full and direct access to serial ports ("<literal>/dev/ttyS[0-3]</literal>") </entry>
              </row>
              <row>
                <entry> <literal>dip</literal> </entry>
                <entry> limited access to serial ports for <emphasis role="strong">Dialup IP</emphasis> connection to trusted peers </entry>
              </row>
              <row>
                <entry> <literal>cdrom</literal> </entry>
                <entry> CD-ROM, DVD+/-RW drives </entry>
              </row>
              <row>
                <entry> <literal>audio</literal> </entry>
                <entry> audio device </entry>
              </row>
              <row>
                <entry> <literal>video</literal> </entry>
                <entry> video device </entry>
              </row>
              <row>
                <entry> <literal>scanner</literal> </entry>
                <entry> scanner(s) </entry>
              </row>
              <row>
                <entry> <literal>adm</literal> </entry>
                <entry> system monitoring logs </entry>
              </row>
              <row>
                <entry> <literal>staff</literal> </entry>
                <entry> some directories for junior administrative work: "<literal>/usr/local</literal>", "<literal>/home</literal>" </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <tip> <para>You need to belong to the <literal>dialout</literal> group to reconfigure modem, dial anywhere, etc.  But if <literal>root</literal> creates pre-defined configuration files for trusted peers in "<literal>/etc/ppp/peers/</literal>", you only need to belong to the <literal>dip</literal> group to create <emphasis role="strong">Dialup IP</emphasis> connection to those trusted peers using <literal>pppd</literal>(8), <literal>pon</literal>(1), and <literal>poff</literal>(1) commands.</para> </tip>
        <para>Some notable system-provided groups allow their members to execute particular commands without <literal>root</literal> privilege.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of notable system provided groups for particular command executions</title>
          <tgroup cols="2">
            <colspec colwidth="54pt" align="left"/>
            <colspec colwidth="418pt" align="left"/>
            <thead>
              <row>
                <entry> group </entry>
                <entry> accessible commands </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>sudo</literal> </entry>
                <entry> execute any command with superuser privileges </entry>
              </row>
              <row>
                <entry> <literal>lpadmin</literal> </entry>
                <entry> execute commands to add, modify, and remove printers from printer databases </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>For the full listing of the system provided users and groups, see the recent version of the "Users and Groups" document in "<literal>/usr/share/doc/base-passwd/users-and-groups.html</literal>" provided by the <literal>base-passwd</literal> package.</para>
        <para>See <literal>passwd</literal>(5), <literal>group</literal>(5), <literal>shadow</literal>(5), <literal>newgrp</literal>(1), <literal>vipw</literal>(8), <literal>vigr</literal>(8), and <literal>pam_group</literal>(8) for management commands of the user and group system.</para>
      </section>
      <section id="_timestamps">
        <title>Timestamps</title>
        <para>There are three types of timestamps for a GNU/Linux file.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of types of timestamps</title>
          <tgroup cols="2">
            <colspec colwidth="54pt" align="left"/>
            <colspec colwidth="211pt" align="left"/>
            <thead>
              <row>
	        <entry> type </entry>
                <entry> meaning (historic Unix definition) </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <emphasis role="strong">mtime</emphasis> </entry>
                <entry> the file modification time (<literal>ls -l</literal>) </entry>
              </row>
              <row>
                <entry> <emphasis role="strong">ctime</emphasis> </entry>
                <entry> the file status change time (<literal>ls -lc</literal>) </entry>
              </row>
              <row>
                <entry> <emphasis role="strong">atime</emphasis> </entry>
                <entry> the last file access time (<literal>ls -lu</literal>) </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <note> <para><emphasis role="strong">ctime</emphasis> is not file creation time.</para> </note>
        <note> <para>The actual value of <emphasis role="strong">atime</emphasis> on GNU/Linux system may be different from that of the historic Unix definition.</para> </note>
        <itemizedlist>
          <listitem> <para> Overwriting a file changes all of the <emphasis role="strong">mtime</emphasis>, <emphasis role="strong">ctime</emphasis>, and <emphasis role="strong">atime</emphasis> attributes of the file.  </para> </listitem>
          <listitem> <para> Changing ownership or permission of a file changes the <emphasis role="strong">ctime</emphasis> and <emphasis role="strong">atime</emphasis> attributes of the file.  </para> </listitem>
          <listitem> <para> Reading a file changes the <emphasis role="strong">atime</emphasis> attribute of the file on the historic Unix system.  </para> </listitem>
          <listitem> <para> Reading a file changes the <emphasis role="strong">atime</emphasis> attribute of the file on the GNU/Linux system if its filesystem is mounted with "<literal>strictatime</literal>".  </para> </listitem>
          <listitem> <para> Reading a file for the first time or after one day changes the <emphasis role="strong">atime</emphasis> attribute of the file on the GNU/Linux system if its filesystem is mounted with "<literal>relatime</literal>". (default behavior since Linux 2.6.30) </para> </listitem>
          <listitem> <para> Reading a file doesn't change the <emphasis role="strong">atime</emphasis> attribute of the file on the GNU/Linux system if its filesystem is mounted with "<literal>noatime</literal>".  </para> </listitem>
        </itemizedlist>
        <note> <para>The "<literal>noatime</literal>" and "<literal>relatime</literal>" mount options are introduced to improve the filesystem read performance under the normal use cases.  Simple file read operation under the "<literal>strictatime</literal>" option accompanies the time-consuming write operation to update the <emphasis role="strong">atime</emphasis> attribute.  But the <emphasis role="strong">atime</emphasis> attribute is rarely used except for the <literal>mbox</literal>(5) file.  See <literal>mount</literal>(8).</para> </note>
        <para>Use <literal>touch</literal>(1) command to change timestamps of existing files.</para>
        <para>For timestamps, the <literal>ls</literal> command outputs localized strings under non-English locale ("<literal>fr_FR.UTF-8</literal>").</para>
        <screen>$ LANG=C  ls -l foo
-rw-rw-r-- 1 penguin penguin 0 Oct 16 21:35 foo
$ LANG=en_US.UTF-8  ls -l foo
-rw-rw-r-- 1 penguin penguin 0 Oct 16 21:35 foo
$ LANG=fr_FR.UTF-8  ls -l foo
-rw-rw-r-- 1 penguin penguin 0 oct. 16 21:35 foo</screen>
        <tip> <para>See <xref linkend="_customized_display_of_time_and_date"/> to customize "<literal>ls -l</literal>" output.</para> </tip>
      </section>
      <section id="_links">
        <title>Links</title>
        <para>There are two methods of associating a file "<literal>foo</literal>" with a different filename "<literal>bar</literal>".</para>
        <itemizedlist>
          <listitem>
	    <para> <ulink url="https://en.wikipedia.org/wiki/Hard_link">Hard link</ulink> </para>
            <itemizedlist>
              <listitem> <para> Duplicate name for an existing file </para> </listitem>
              <listitem> <para> "<literal>ln foo bar</literal>" </para> </listitem>
            </itemizedlist>
          </listitem>
          <listitem>
            <para> <ulink url="https://en.wikipedia.org/wiki/Symbolic_link">Symbolic link or symlink</ulink> </para>
            <itemizedlist>
              <listitem> <para> Special file that points to another file by name </para> </listitem>
              <listitem> <para> "<literal>ln -s foo bar</literal>" </para> </listitem>
            </itemizedlist>
          </listitem>
        </itemizedlist>
        <para>See the following example for changes in link counts and the subtle differences in the result of the <literal>rm</literal> command.</para>
        <screen>$ umask 002
$ echo "Original Content" &gt; foo
$ ls -li foo
1449840 -rw-rw-r-- 1 penguin penguin 17 Oct 16 21:42 foo
$ ln foo bar     # hard link
$ ln -s foo baz  # symlink
$ ls -li foo bar baz
1449840 -rw-rw-r-- 2 penguin penguin 17 Oct 16 21:42 bar
1450180 lrwxrwxrwx 1 penguin penguin  3 Oct 16 21:47 baz -&gt; foo
1449840 -rw-rw-r-- 2 penguin penguin 17 Oct 16 21:42 foo
$ rm foo
$ echo "New Content" &gt; foo
$ ls -li foo bar baz
1449840 -rw-rw-r-- 1 penguin penguin 17 Oct 16 21:42 bar
1450180 lrwxrwxrwx 1 penguin penguin  3 Oct 16 21:47 baz -&gt; foo
1450183 -rw-rw-r-- 1 penguin penguin 12 Oct 16 21:48 foo
$ cat bar
Original Content
$ cat baz
New Content</screen>
        <para>The hardlink can be made within the same filesystem and shares the same inode number which the "<literal>-i</literal>" option with <literal>ls</literal>(1)  reveals.</para>
        <para>The symlink always has nominal file access permissions of "<literal>rwxrwxrwx</literal>", as shown in the above example, with the effective access permissions dictated by permissions of the file that it points to.</para>
        <caution> <para>It is generally a good idea not to create complicated symbolic links or hardlinks at all unless you have a very good reason.  It may cause nightmares where the logical combination of the symbolic links results in loops in the filesystem.</para> </caution>
        <note> <para>It is generally preferable to use symbolic links rather than hardlinks unless you have a good reason for using a hardlink.</para> </note>
        <para>The "<literal>.</literal>"  directory links to the directory that it appears in, thus the link count of any new directory starts at 2.  The "<literal>..</literal>"  directory links to the parent directory, thus the link count of the directory increases with the addition of new subdirectories.</para>
        <para>If you are just moving to Linux from Windows, it soon becomes clear how well-designed the filename linking of Unix is, compared with the nearest Windows equivalent of "shortcuts".  Because it is implemented in the filesystem, applications can't see any difference between a linked file and the original. In the case of hardlinks, there really is no difference.</para>
      </section>
      <section id="_named_pipes_fifos">
        <title>Named pipes (FIFOs)</title>
        <para>A <ulink url="https://en.wikipedia.org/wiki/Named_pipe">named pipe</ulink> is a file that acts like a pipe.  You put something into the file, and it comes out the other end.  Thus it's called a FIFO, or First-In-First-Out: the first thing you put in the pipe is the first thing to come out the other end.</para>
        <para>If you write to a named pipe, the process which is writing to the pipe doesn't terminate until the information being written is read from the pipe.  If you read from a named pipe, the reading process waits until there is nothing to read before terminating.  The size of the pipe is always zero --- it does not store data, it just links two processes like the functionality offered by the shell "<literal>|</literal>" syntax.  However, since this pipe has a name, the two processes don't have to be on the same command line or even be run by the same user. Pipes were a very influential innovation of Unix.</para>
        <para>For example, try the following</para>
        <screen>$ cd; mkfifo mypipe
$ echo "hello" &gt;mypipe &amp; # put into background
[1] 8022
$ ls -l mypipe
prw-rw-r-- 1 penguin penguin 0 Oct 16 21:49 mypipe
$ cat mypipe
hello
[1]+  Done                    echo "hello" &gt;mypipe
$ ls mypipe
mypipe
$ rm mypipe</screen>
      </section>
      <section id="_sockets">
        <title>Sockets</title>
        <para>Sockets are used extensively by all the Internet communication, databases, and the operating system itself. It is similar to the named pipe (FIFO) and allows processes to exchange information even between different computers.  For the socket, those processes do not need to be running at the same time nor to be running as the children of the same ancestor process.  This is the endpoint for <ulink url="https://en.wikipedia.org/wiki/Inter-process_communication">the inter process communication (IPC)</ulink>.  The exchange of information may occur over the network between different hosts.  The two most common ones are <ulink url="https://en.wikipedia.org/wiki/Internet_socket">the Internet socket</ulink> and <ulink url="https://en.wikipedia.org/wiki/Unix_domain_socket">the Unix domain socket</ulink>.</para>
        <tip> <para>"<literal>netstat -an</literal>" provides a very useful overview of sockets that are open on a given system.</para> </tip>
      </section>
      <section id="_device_files">
        <title>Device files</title>
        <para><ulink url="https://en.wikipedia.org/wiki/Device_file">Device files</ulink> refer to physical or virtual devices on your system, such as your hard disk, video card, screen, or keyboard.  An example of a virtual device is the console, represented by "<literal>/dev/console</literal>".</para>
        <para>There are 2 types of device files.</para>
        <itemizedlist>
          <listitem>
            <para> <emphasis role="strong">Character device</emphasis> </para>
            <itemizedlist>
              <listitem> <para> Accessed one character at a time </para> </listitem>
              <listitem> <para> 1 character = 1 byte </para> </listitem>
              <listitem> <para> E.g. keyboard device, serial port, … </para> </listitem>
            </itemizedlist>
          </listitem>
          <listitem>
            <para> <emphasis role="strong">Block device</emphasis> </para>
            <itemizedlist>
              <listitem> <para> accessed in larger units called blocks </para> </listitem>
              <listitem> <para> 1 block &gt; 1 byte </para> </listitem>
              <listitem> <para> E.g. hard disk, … </para> </listitem>
            </itemizedlist>
          </listitem>
        </itemizedlist>
        <para>You can read and write device files, though the file may well contain binary data which may be an incomprehensible-to-humans gibberish.  Writing data directly to these files is sometimes useful for the troubleshooting of hardware connections.  For example, you can dump a text file to the printer device "<literal>/dev/lp0</literal>" or send modem commands to the appropriate serial port "<literal>/dev/ttyS0</literal>".  But, unless this is done carefully, it may cause a major disaster.  So be cautious.</para>
        <note> <para>For the normal access to a printer, use <literal>lp</literal>(1).</para> </note>
        <para>The device node number are displayed by executing <literal>ls</literal>(1) as the following.</para>
        <screen>$ ls -l /dev/sda /dev/sr0 /dev/ttyS0 /dev/zero
brw-rw---T  1 root disk     8,  0 Oct 16 20:57 /dev/sda
brw-rw---T+ 1 root cdrom   11,  0 Oct 16 21:53 /dev/sr0
crw-rw---T  1 root dialout  4, 64 Oct 16 20:57 /dev/ttyS0
crw-rw-rw-  1 root root     1,  5 Oct 16 20:57 /dev/zero</screen>
        <itemizedlist>
          <listitem> <para> "<literal>/dev/sda</literal>" has the major device number 8 and the minor device number 0.  This is read/write accessible by users belonging to the <literal>disk</literal> group.  </para> </listitem>
          <listitem> <para> "<literal>/dev/sr0</literal>" has the major device number 11 and the minor device number 0.  This is read/write accessible by users belonging to the <literal>cdrom</literal> group.  </para> </listitem>
          <listitem> <para> "<literal>/dev/ttyS0</literal>" has the major device number 4 and the minor device number 64.  This is read/write accessible by users belonging to the <literal>dialout</literal> group.  </para> </listitem>
          <listitem> <para> "<literal>/dev/zero</literal>" has the major device number 1 and the minor device number 5.  This is read/write accessible by anyone.  </para> </listitem>
        </itemizedlist>
        <para>On the modern Linux system, the filesystem under "<literal>/dev/</literal>" is automatically populated by the <literal>udev</literal>(7) mechanism.</para>
      </section>
      <section id="_special_device_files">
        <title>Special device files</title>
        <para>There are some special device files.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of special device files</title>
          <tgroup cols="3">
            <colspec colwidth="81pt" align="left"/>
            <colspec colwidth="38pt" align="left"/>
            <colspec colwidth="532pt" align="left"/>
            <thead>
              <row>
                <entry> device file </entry>
                <entry> action </entry>
                <entry> description of response </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>/dev/null</literal> </entry>
                <entry> read </entry>
                <entry> return "end-of-file (EOF) character" </entry>
              </row>
              <row>
                <entry> <literal>/dev/null</literal> </entry>
                <entry> write </entry>
                <entry> return nothing (a bottomless data dump pit) </entry>
              </row>
              <row>
                <entry> <literal>/dev/zero</literal> </entry>
                <entry> read </entry>
                <entry> return "the <literal>\0</literal> (NUL) character" (not the same as the number zero ASCII) </entry>
              </row>
              <row>
                <entry> <literal>/dev/random</literal> </entry>
                <entry> read </entry>
                <entry> return random characters from a true random number generator, delivering real entropy (slow) </entry>
              </row>
              <row>
                <entry> <literal>/dev/urandom</literal> </entry>
                <entry> read </entry>
                <entry> return random characters from a cryptographically secure pseudorandom number generator </entry>
              </row>
              <row>
                <entry> <literal>/dev/full</literal> </entry>
                <entry> write </entry>
                <entry> return the disk-full (ENOSPC) error </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>These are frequently used in conjunction with the shell redirection (see <xref linkend="_typical_command_sequences_and_shell_redirection"/>).</para>
      </section>
      <section id="_procfs_and_sysfs">
        <title>procfs and sysfs</title>
        <para>The <ulink url="https://en.wikipedia.org/wiki/Procfs">procfs</ulink> and <ulink url="https://en.wikipedia.org/wiki/Sysfs">sysfs</ulink> mounted on "<literal>/proc</literal>" and "<literal>/sys</literal>" are the pseudo-filesystem and expose internal data structures of the kernel to the userspace.  In other word, these entries are virtual, meaning that they act as a convenient window into the operation of the operating system.</para>
        <para>The directory "<literal>/proc</literal>" contains (among other things) one subdirectory for each process running on the system, which is named after the process ID (PID). System utilities that access process information, such as <literal>ps</literal>(1), get their information from this directory structure.</para>
        <para>The directories under "<literal>/proc/sys/</literal>" contain interfaces to change certain kernel parameters at run time.  (You may do the same through the specialized <literal>sysctl</literal>(8) command or its preload/configuration file "<literal>/etc/sysctl.conf</literal>".)</para>
        <para>People frequently panic when they notice one file in particular - "<literal>/proc/kcore</literal>" - which is generally huge.  This is (more or less) a copy of the content of your computer's memory.  It's used to debug the kernel.  It is a virtual file that points to computer memory, so don't worry about its size.</para>
        <para>The directory under "<literal>/sys</literal>" contains exported kernel data structures, their attributes, and their linkages between them. It also contains interfaces to change certain kernel parameters at run time.</para>
        <para>See "<literal>proc.txt(.gz)</literal>", "<literal>sysfs.txt(.gz)</literal>" and other related documents in the Linux kernel documentation ("<literal>/usr/share/doc/linux-doc-*/Documentation/filesystems/*</literal>") provided by the <literal>linux-doc-*</literal> package.</para>
      </section>
      <section id="_tmpfs">
        <title>tmpfs</title>
        <para>The <ulink url="https://en.wikipedia.org/wiki/Tmpfs#Linux">tmpfs</ulink> is a temporary filesystem which keeps all files in the <ulink url="https://en.wikipedia.org/wiki/Virtual_memory">virtual memory</ulink>.  The data of the tmpfs in the <ulink url="https://en.wikipedia.org/wiki/Page_cache">page cache</ulink> on memory may be swapped out to the <ulink url="https://en.wikipedia.org/wiki/Paging">swap space</ulink> on disk as needed.</para>
        <para>The directory "<literal>/run</literal>" is mounted as the tmpfs in the early boot process.  This enables writing to it even when the directory "<literal>/</literal>" is mounted as read-only.  This is the new location for the storage of transient state files and replaces several locations described in the <ulink url="https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard">Filesystem Hierarchy Standard</ulink> version 2.3:</para>
        <itemizedlist>
          <listitem> <para> "<literal>/var/run</literal>" → "<literal>/run</literal>" </para> </listitem>
          <listitem> <para> "<literal>/var/lock</literal>" → "<literal>/run/lock</literal>" </para> </listitem>
          <listitem> <para> "<literal>/dev/shm</literal>" → "<literal>/run/shm</literal>" </para> </listitem>
        </itemizedlist>
        <para>See "<literal>tmpfs.txt(.gz)</literal>" in the Linux kernel documentation ("<literal>/usr/share/doc/linux-doc-*/Documentation/filesystems/*</literal>") provided by the <literal>linux-doc-*</literal> package.</para>
      </section>
    </section>
    <section id="_midnight_commander_mc">
      <title>Midnight Commander (MC)</title>
      <para><ulink url="https://en.wikipedia.org/wiki/Midnight_Commander">Midnight Commander (MC)</ulink> is a GNU "Swiss army knife" for the Linux console and other terminal environments.  This gives newbie a menu driven console experience which is much easier to learn than standard Unix commands.</para>
      <para>You may need to install the Midnight Commander package which is titled "<literal>mc</literal>" by the following.</para>
      <screen>$ sudo apt-get install mc</screen>
      <para>Use the <literal>mc</literal>(1) command to explore the Debian system.  This is the best way to learn.  Please explore few interesting locations just using the cursor keys and Enter key.</para>
      <itemizedlist>
        <listitem> <para> "<literal>/etc</literal>" and its subdirectories </para> </listitem>
        <listitem> <para> "<literal>/var/log</literal>" and its subdirectories </para> </listitem>
        <listitem> <para> "<literal>/usr/share/doc</literal>" and its subdirectories </para> </listitem>
        <listitem> <para> "<literal>/usr/sbin</literal>" and "<literal>/usr/bin</literal>" </para> </listitem>
      </itemizedlist>
      <section id="_customization_of_mc">
        <title>Customization of MC</title>
        <para>In order to make MC to change working directory upon exit and <literal>cd</literal> to the directory, I suggest to modify "<literal>~/.bashrc</literal>" to include a script provided by the <literal>mc</literal> package.</para>
        <screen>. /usr/lib/mc/mc.sh</screen>
        <para>See <literal>mc</literal>(1) (under the "<literal>-P</literal>" option) for the reason. (If you do not understand what exactly I am talking here, you can do this later.)</para>
      </section>
      <section id="_starting_mc">
        <title>Starting MC</title>
        <para>MC can be started by the following.</para>
        <screen>$ mc</screen>
        <para>MC takes care of all file operations through its menu, requiring minimal user effort.  Just press F1 to get the help screen.  You can play with MC just by pressing cursor-keys and function-keys.</para>
        <note> <para>In some consoles such as <literal>gnome-terminal</literal>(1), key strokes of function-keys may be stolen by the console program.   You can disable these features in "Preferences" → "General" and "Shortcuts" menu for <literal>gnome-terminal</literal>.</para> </note>
        <para>If you encounter character encoding problem which displays garbage characters, adding "<literal>-a</literal>" to MC's command line may help prevent problems.</para>
        <para>If this doesn't clear up your display problems with MC, see <xref linkend="_the_terminal_configuration"/>.</para>
      </section>
      <section id="_file_manager_in_mc">
        <title>File manager in MC</title>
        <para>The default is two directory panels containing file lists.  Another useful mode is to set the right window to "information" to see file access privilege information, etc.  Following are some essential keystrokes.  With the <literal>gpm</literal>(8) daemon running, one can use a mouse on Linux character consoles, too.  (Make sure to press the shift-key to obtain the normal behavior of cut and paste in MC.)</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>The key bindings of MC</title>
          <tgroup cols="2">
            <colspec colwidth="114pt" align="left"/>
            <colspec colwidth="293pt" align="left"/>
            <thead>
              <row>
                <entry> key </entry>
                <entry> key binding </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>F1</literal> </entry>
                <entry> help menu </entry>
              </row>
              <row>
                <entry> <literal>F3</literal> </entry>
                <entry> internal file viewer </entry>
              </row>
              <row>
                <entry> <literal>F4</literal> </entry>
                <entry> internal editor </entry>
              </row>
              <row>
                <entry> <literal>F9</literal> </entry>
                <entry> activate pull down menu </entry>
              </row>
              <row>
                <entry> <literal>F10</literal> </entry>
                <entry> exit Midnight Commander </entry>
              </row>
              <row>
                <entry> <literal>Tab</literal> </entry>
                <entry> move between two windows </entry>
              </row>
              <row>
                <entry><literal>Insert</literal> or <literal>Ctrl-T</literal> </entry>
                <entry> mark file for a multiple-file operation such as copy </entry>
              </row>
              <row>
                <entry> <literal>Del</literal> </entry>
                <entry> delete file (be careful---set MC to safe delete mode) </entry>
              </row>
              <row>
                <entry> Cursor keys </entry>
                <entry> self-explanatory </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
      </section>
      <section id="_command_line_tricks_in_mc">
        <title>Command-line tricks in MC</title>
        <itemizedlist>
          <listitem> <para><literal>cd</literal> command changes the directory shown on the selected screen.  </para> </listitem>
          <listitem> <para><literal>Ctrl-Enter</literal> or <literal>Alt-Enter</literal> copies a filename to the command line. Use this with <literal>cp</literal>(1) and <literal>mv</literal>(1) commands together with command-line editing.  </para> </listitem>
          <listitem> <para><literal>Alt-Tab</literal> shows shell filename expansion choices.  </para> </listitem>
          <listitem> <para> One can specify the starting directory for both windows as arguments to MC; for example, "<literal>mc /etc /root</literal>".  </para> </listitem>
          <listitem> <para><literal>Esc</literal> + <literal>n-key</literal> → <literal>Fn</literal> (i.e., <literal>Esc</literal> + <literal>1</literal> → <literal>F1</literal>, etc.; <literal>Esc</literal> + <literal>0</literal> → <literal>F10</literal>) </para> </listitem>
          <listitem> <para> Pressing <literal>Esc</literal> before the key has the same effect as pressing the <literal>Alt</literal> and the key together.; i.e., type <literal>Esc</literal> + <literal>c</literal> for <literal>Alt-C</literal>.  <literal>Esc</literal> is called meta-key and sometimes noted as "<literal>M-</literal>".  </para> </listitem>
        </itemizedlist>
      </section>
      <section id="_the_internal_editor_in_mc">
        <title>The internal editor in MC</title>
        <para>The internal editor has an interesting cut-and-paste scheme.  Pressing <literal>F3</literal> marks the start of a selection, a second <literal>F3</literal> marks the end of selection and highlights the selection.  Then you can move your cursor.  If you press F6, the selected area is moved to the cursor location.  If you press F5, the selected area is copied and inserted at the cursor location.  <literal>F2</literal> saves the file.  <literal>F10</literal> gets you out.  Most cursor keys work intuitively.</para>
        <para>This editor can be directly started on a file using one of the following commands.</para>
        <screen>$ mc -e filename_to_edit</screen>
        <screen>$ mcedit filename_to_edit</screen>
        <para>This is not a multi-window editor, but one can use multiple Linux consoles to achieve the same effect.  To copy between windows, use Alt-F<emphasis>n</emphasis> keys to switch virtual consoles and use "File→Insert file" or "File→Copy to file" to move a portion of a file to another file.</para>
        <para>This internal editor can be replaced with any external editor of choice.</para>
        <para>Also, many programs use the environment variables "<literal>$EDITOR</literal>" or "<literal>$VISUAL</literal>" to decide which editor to use.  If you are uncomfortable with <literal>vim</literal>(1) or <literal>nano</literal>(1) initially, you may set these to "<literal>mcedit</literal>" by adding the following lines to "<literal>~/.bashrc</literal>".</para>
        <screen>export EDITOR=mcedit
export VISUAL=mcedit</screen>
        <para>I do recommend setting these to "<literal>vim</literal>" if possible.</para>
        <para>If you are uncomfortable with <literal>vim</literal>(1), you can keep using <literal>mcedit</literal>(1) for most system maintenance tasks.</para>
      </section>
      <section id="_the_internal_viewer_in_mc">
        <title>The internal viewer in MC</title>
        <para>MC is a very smart viewer.  This is a great tool for searching words in documents.  I always use this for files in the "<literal>/usr/share/doc</literal>" directory.  This is the fastest way to browse through masses of Linux information.  This viewer can be directly started using one of the following commands.</para>
        <screen>$ mc -v path/to/filename_to_view</screen>
        <screen>$ mcview path/to/filename_to_view</screen>
      </section>
      <section id="_auto_start_features_of_mc">
        <title>Auto-start features of MC</title>
        <para>Press Enter on a file, and the appropriate program handles the content of the file (see <xref linkend="_customizing_program_to_be_started"/>).  This is a very convenient MC feature.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>The reaction to the enter key in MC</title>
          <tgroup cols="2">
            <colspec colwidth="184pt" align="left"/>
            <colspec colwidth="211pt" align="left"/>
            <thead>
              <row>
                <entry> file type </entry>
                <entry> reaction to enter key </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> executable file </entry>
                <entry> execute command </entry>
              </row>
              <row>
                <entry> man file </entry>
                <entry> pipe content to viewer software </entry>
              </row>
              <row>
                <entry> html file </entry>
                <entry> pipe content to web browser </entry>
              </row>
              <row>
                <entry> "<literal>*.tar.gz</literal>" and "<literal>*.deb</literal>" file </entry>
                <entry> browse its contents as if subdirectory </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>In order to allow these viewer and virtual file features to function, viewable files should not be set as executable.  Change their status using <literal>chmod</literal>(1) or via the MC file menu.</para>
      </section>
      <section id="_virtual_filesystem_of_mc">
        <title>Virtual filesystem of MC</title>
        <para>MC can be used to access files over the Internet.  Go to the menu by pressing <literal>F9</literal>, "<literal>Enter</literal>" and "<literal>h</literal>" to activate the Shell filesystem.  Enter a URL in the form "<literal>sh://[user@]machine[:options]/[remote-dir]</literal>", which retrieves a remote directory that appears like a local one using <literal>ssh</literal>.</para>
      </section>
    </section>
    <section id="_the_basic_unix_like_work_environment">
      <title>The basic Unix-like work environment</title>
      <para>Although MC enables you to do almost everything, it is very important for you to learn how to use the command line tools invoked from the shell prompt and become familiar with the Unix-like work environment.</para>
      <section id="_the_login_shell">
        <title>The login shell</title>
        <para>Since the login shell may be used by some system initialization programs, it is prudent to keep it as <literal>bash</literal>(1) and avoid switching the login shell with <literal>chsh</literal>(1).</para>
        <!-- NOTE: There were a lot of buggy situations for Wayland and inputmethod configuration.  -->
        <para>If you want to use a different interactive shell prompt, set it from GUI terminal emulator configuration or start it from <literal>~/.bashrc</literal>, e.g., by placing "<literal>exec /usr/bin/zsh -i -l</literal>" or "<literal>exec /usr/bin/fish -i -l</literal>" in it.</para>
        <table id="list-of-shell-programs" pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of shell programs</title>
          <tgroup cols="5">
            <colspec colwidth="43pt" align="left"/>
            <colspec colwidth="76pt" align="left"/>
            <colspec colwidth="70pt" align="left"/>
            <colspec colwidth="65pt" align="left"/>
            <colspec colwidth="494pt" align="left"/>
            <thead>
              <row>
                <entry> package </entry>
                <entry> popcon </entry>
                <entry> size </entry>
                <entry> POSIX shell </entry>
                <entry> description </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>bash</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Yes </entry>
                <entry><ulink url="https://en.wikipedia.org/wiki/Bash_(Unix_shell)">Bash</ulink>: the GNU Bourne Again SHell (de facto standard) </entry>
              </row>
              <row>
                <entry> <literal>bash-completion</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> N/A </entry>
                <entry> programmable completion for the <ulink url="https://en.wikipedia.org/wiki/Bash_(Unix_shell)">bash</ulink> shell </entry>
              </row>
              <row>
                <entry> <literal>dash</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Yes </entry>
                <entry> Debian <ulink url="https://en.wikipedia.org/wiki/Almquist_shell">Almquist Shell</ulink>, good for shell script </entry>
              </row>
              <row>
                <entry> <literal>zsh</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Yes </entry>
                <entry> <ulink url="https://en.wikipedia.org/wiki/Z_shell">Z shell</ulink>: the standard shell with many enhancements </entry>
              </row>
              <row>
                <entry> <literal>tcsh</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> No </entry>
                <entry> <ulink url="https://en.wikipedia.org/wiki/Tcsh">TENEX C Shell</ulink>: an enhanced version of <ulink url="https://en.wikipedia.org/wiki/C_shell">Berkeley csh</ulink></entry>
              </row>
              <row>
                <entry> <literal>mksh</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Yes </entry>
                <entry> A version of the <ulink url="https://en.wikipedia.org/wiki/Korn_shell">Korn shell</ulink> </entry>
              </row>
              <row>
                <entry> <literal>csh</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> No </entry>
                <entry> <ulink url="https://en.wikipedia.org/wiki/OpenBSD">OpenBSD</ulink> C Shell, a version of <ulink url="https://en.wikipedia.org/wiki/C_shell">Berkeley csh</ulink> </entry>
              </row>
              <row>
                <entry> <literal>sash</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Yes </entry>
                <entry> <ulink url="https://en.wikipedia.org/wiki/Stand-alone_shell">Stand-alone shell</ulink> with builtin commands (Not meant for standard "<literal>/usr/bin/sh</literal>") </entry>
              </row>
              <row>
                <entry> <literal>ksh</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Yes </entry>
                <entry> the real, AT&amp;T version of the <ulink url="https://en.wikipedia.org/wiki/Korn_shell">Korn shell</ulink> </entry>
              </row>
              <row>
                <entry> <literal>rc</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> No </entry>
                <entry> implementation of the <ulink url="https://en.wikipedia.org/wiki/Plan_9_from_Bell_Labs">AT&amp;T Plan 9</ulink> <ulink url="https://en.wikipedia.org/wiki/Rc">rc shell</ulink> </entry>
              </row>
              <row>
                <entry> <literal>posh</literal> </entry>
                <entry> @-@popcon1@-@ </entry>
                <entry> @-@psize1@-@ </entry>
                <entry> Yes </entry>
                <entry> Policy-compliant Ordinary SHell (<literal>pdksh</literal> derivative) </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <tip>
          <para>Although POSIX-like shells share the basic syntax, they can differ in behavior for things as basic as shell variables and glob expansions.  Please check their documentation for details.</para>
        </tip>
        <para>In this tutorial chapter, the interactive shell always means <literal>bash</literal>.</para>
      </section>
      <section id="_customizing_bash">
        <title>Customizing bash</title>
        <para>You can customize <literal>bash</literal>(1) behavior by "<literal>~/.bashrc</literal>".</para>
        <para>For example, try the following.</para>
        <screen># enable bash-completion
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

# CD upon exiting MC
. /usr/lib/mc/mc.sh

# set CDPATH to a good one
CDPATH=.:/usr/share/doc:~:~/Desktop:~
export CDPATH

PATH="${PATH+$PATH:}/usr/sbin:/sbin"
# set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then
  PATH="~/bin${PATH+:$PATH}"
fi
export PATH

EDITOR=vim
export EDITOR</screen>
        <tip> <para>You can find more <literal>bash</literal> customization tips, such as <xref linkend="_colorized_commands"/>, in <xref linkend="_system_tips"/>.</para> </tip>
        <tip> <para>The <literal>bash-completion</literal> package enables programmable completion for <literal>bash</literal>.</para> </tip>
      </section>
      <section id="_special_key_strokes">
        <title>Special key strokes</title>
        <para>In the <ulink url="https://en.wikipedia.org/wiki/Unix-like">Unix-like</ulink> environment, there are few key strokes which have special meanings.  Please note that on a normal Linux character console, only the left-hand <literal>Ctrl</literal> and <literal>Alt</literal> keys work as expected.  Here are few notable key strokes to remember.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of key bindings for bash</title>
          <tgroup cols="2">
            <colspec colwidth="233pt" align="left"/>
            <colspec colwidth="352pt" align="left"/>
            <thead>
              <row>
                <entry> key </entry>
                <entry> description of key binding </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>Ctrl-U</literal> </entry>
                <entry> erase line before cursor </entry>
              </row>
              <row>
                <entry> <literal>Ctrl-H</literal> </entry>
                <entry> erase a character before cursor </entry>
              </row>
              <row>
                <entry> <literal>Ctrl-D</literal> </entry>
                <entry> terminate input (exit shell if you are using shell) </entry>
              </row>
              <row>
                <entry> <literal>Ctrl-C</literal>  </entry>
                <entry> terminate a running program </entry>
              </row>
              <row>
                <entry> <literal>Ctrl-Z</literal> </entry>
                <entry> temporarily stop program by moving it to the background job </entry>
              </row>
              <row>
                <entry> <literal>Ctrl-S</literal> </entry>
                <entry> halt output to screen </entry>
              </row>
              <row>
                <entry> <literal>Ctrl-Q</literal> </entry>
                <entry> reactivate output to screen </entry>
              </row>
              <row>
                <entry> <literal>Ctrl-Alt-Del</literal> </entry>
                <entry> reboot/halt the system, see <literal>inittab</literal>(5) </entry>
              </row>
              <row>
                <entry><literal>Left-Alt-key</literal> (optionally, <literal>Windows-key</literal>) </entry>
                <entry> meta-key for Emacs and the similar UI </entry>
              </row>
              <row>
                <entry> <literal>Up-arrow</literal> </entry>
                <entry> start command history search under <literal>bash</literal> </entry>
              </row>
              <row>
                <entry> <literal>Ctrl-R</literal> </entry>
                <entry> start incremental command history search under <literal>bash</literal> </entry>
              </row>
              <row>
                <entry> <literal>Tab</literal> </entry>
                <entry> complete input of the filename to the command line under <literal>bash</literal> </entry>
              </row>
              <row>
                <entry> <literal>Ctrl-V</literal> <literal>Tab</literal> </entry>
                <entry> input <literal>Tab</literal> without expansion to the command line under <literal>bash</literal> </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <tip> <para>The terminal feature of <literal>Ctrl-S</literal> can be disabled using <literal>stty</literal>(1).</para> </tip>
      </section>
      <section id="_mouse_operations">
        <title>Mouse operations</title>
        <para><ulink url="https://specifications.freedesktop.org/clipboards-spec/clipboards-latest.txt">Mouse operations for text on Debian system mix 2 styles</ulink> with some twists:</para>
        <itemizedlist>
          <listitem>
          <para>Traditional Unix style mouse operations:</para>
          <itemizedlist>
            <listitem> <para>use 3 buttons (click) </para> </listitem>
            <listitem> <para>use PRIMARY </para> </listitem>
            <listitem> <para>used by X applications such as <literal>xterm</literal> and text applications in Linux console </para> </listitem>
          </itemizedlist>
        </listitem>
        <listitem>
          <para>Modern GUI style mouse operations:</para>
          <itemizedlist>
            <listitem> <para>use 2 buttons (drag + click) </para> </listitem>
            <listitem> <para>use PRIMARY and CLIPBOARD </para> </listitem>
            <listitem> <para>used in Modern GUI applications such as <literal>gnome-terminal</literal> </para> </listitem>
          </itemizedlist>
          </listitem>
        </itemizedlist>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of mouse operations and related key actions on Debian </title>
          <tgroup cols="2">
            <colspec colwidth="141pt" align="left"/>
            <colspec colwidth="298pt" align="left"/>
            <thead>
              <row>
                <entry> action </entry>
                <entry> response </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> Left-click-and-drag mouse </entry>
                <entry> select range as PRIMARY selection </entry>
              </row>
              <row>
                <entry> Left-click </entry>
                <entry> select the start of range for PRIMARY selection </entry>
              </row>
              <row>
                <entry> Right-click (traditional) </entry>
                <entry> select the end of range for PRIMARY selection </entry>
              </row>
              <row>
                <entry> Right-click (modern) </entry>
                <entry> context dependent menu (cut/copy/paste) </entry>
              </row>
              <row>
                <entry> Middle-click or Shift-<literal>Ins</literal> </entry>
                <entry> insert PRIMARY selection at the cursor </entry>
              </row>
              <row>
                <entry> <literal>Ctrl-X</literal> </entry>
                <entry> cut PRIMARY selection to CLIPBOARD </entry>
              </row>
              <row>
                <entry> <literal>Ctrl-C</literal> (<literal>Shift-Ctrl-C</literal> in terminal) </entry>
                <entry> copy PRIMARY selection to CLIPBOARD </entry>
              </row>
              <row>
                <entry> <literal>Ctrl-V</literal> </entry>
                <entry> paste CLIPBOARD at the cursor </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>Here, the PRIMARY selection is the highlighted text range.  Within the terminal program, <literal>Shift-Ctrl-C</literal> is used instead to avoid terminating a running program.</para>
        <para>The center wheel on the modern wheel mouse is considered middle mouse button and can be used for middle-click.  Clicking left and right mouse buttons together serves as the middle-click under the 2 button mouse system situation.</para>
        <para>In order to use a mouse in Linux character consoles, you need to have <literal>gpm</literal>(8) running as daemon.</para>
      </section>
      <section id="_the_pager">
        <title>The pager</title>
        <para>The <literal>less</literal>(1) command is the enhanced pager (file content browser). It reads the file specified by its command argument or its standard input.  Hit "<literal>h</literal>" if you need help while browsing with the <literal>less</literal> command.  It can do much more than <literal>more</literal>(1) and can be supercharged by executing "<literal>eval $(lesspipe)</literal>" or "<literal>eval $(lessfile)</literal>" in the shell startup script. See more in "<literal>/usr/share/doc/less/LESSOPEN</literal>".  The "<literal>-R</literal>" option allows raw character output and enables ANSI color escape sequences.  See <literal>less</literal>(1).</para>
        <tip> <para>In the <literal>less</literal> command, type "<literal>h</literal>" to see the help screen, type "<literal>/</literal>" or "<literal>?</literal>" to search a string, and type "<literal>-i</literal>" to the change case sensitivity.</para> </tip>
      </section>
      <section id="_the_text_editor">
        <title>The text editor</title>
        <para>You should become proficient in one of variants of <ulink url="https://en.wikipedia.org/wiki/Vim_(text_editor)">Vim</ulink> or <ulink url="https://en.wikipedia.org/wiki/Emacs">Emacs</ulink> programs which are popular in the Unix-like system.</para>
        <para>I think getting used to Vim commands is the right thing to do, since Vi-editor is always there in the Linux/Unix world.  (Actually, original <literal>vi</literal> or new <literal>nvi</literal> are programs you find everywhere.  I chose Vim instead for newbie since it offers you help through <literal>F1</literal> key while it is similar enough and more powerful.)</para>
        <para>If you chose either <ulink url="https://en.wikipedia.org/wiki/Emacs">Emacs</ulink> or <ulink url="https://en.wikipedia.org/wiki/XEmacs">XEmacs</ulink> instead as your choice of the editor, that is another good choice indeed, particularly for programming.  Emacs has a plethora of other features as well, including functioning as a newsreader, directory editor, mail program, etc.  When used for programming or editing shell scripts, it intelligently recognizes the format of what you are working on, and tries to provide assistance.  Some people maintain that the only program they need on Linux is Emacs.  Ten minutes learning Emacs now can save hours later.  Having the GNU Emacs manual for reference when learning Emacs is highly recommended.</para>
        <para>All these programs usually come with tutoring program for you to learn them by practice.  Start Vim by typing "<literal>vim</literal>" and press F1-key.  You should at least read the first 35 lines.  Then do the online training course by moving cursor to "<literal>|tutor|</literal>" and pressing <literal>Ctrl-]</literal>.</para>
        <note> <para>Good editors, such as Vim and Emacs, can handle UTF-8 and other exotic encoding texts correctly.  It is a good idea to use the GUI environment in the UTF-8 locale and to install required programs and fonts to it.  Editors have options to set the file encoding independent of the GUI environment.  Please refer to their documentation on multibyte text.</para> </note>
      </section>
      <section id="_setting_a_default_text_editor">
        <title>Setting a default text editor</title>
        <para>Debian comes with a number of different editors. We recommend to install the <literal>vim</literal> package, as mentioned above.</para>
        <para>Debian provides unified access to the system default editor via command "<literal>/usr/bin/editor</literal>" so other programs (e.g., <literal>reportbug</literal>(1)) can invoke it.  You can change it by the following.</para>
        <screen>$ sudo update-alternatives --config editor</screen>
        <para>The choice "<literal>/usr/bin/vim.basic</literal>" over "<literal>/usr/bin/vim.tiny</literal>" is my recommendation for newbies since it supports syntax highlighting.</para>
        <tip> <para>Many programs use the environment variables "<literal>$EDITOR</literal>" or "<literal>$VISUAL</literal>" to decide which editor to use (see <xref linkend="_the_internal_editor_in_mc"/> and <xref linkend="_customizing_program_to_be_started"/>).  For the consistency on the Debian system, set these to "<literal>/usr/bin/editor</literal>". (Historically, "<literal>$EDITOR</literal>" was "<literal>ed</literal>" and "<literal>$VISUAL</literal>" was "<literal>vi</literal>".)</para> </tip>
      </section>
      <section id="_using_vim">
        <title>Using vim</title>
        <para>The recent <literal>vim</literal>(1) starts itself in the sane "<literal>nocompatible</literal>" option and enters into the <literal>NORMAL</literal> mode.<footnote> <para>Even the older <literal>vim</literal> can starts in the sane "<literal>nocompatible</literal>" mode by starting it with the "<literal>-N</literal>" option.</para> </footnote> </para>
        <table>
          <title>List of basic Vim key strokes</title>
          <tgroup cols="3">
            <colspec colwidth="60pt" align="left"/>
            <colspec colwidth="1000pt" align="left"/>
            <colspec colwidth="500pt" align="left"/>
            <thead>
              <row>
	        <entry> mode </entry>
	        <entry> key strokes </entry>
                <entry> action </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>:help|only</literal> </entry>
                <entry> display the help file </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>:e filename.ext</literal> </entry>
                <entry> open new buffer to edit <literal>filename.ext</literal> </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>:w</literal> </entry>
                <entry> overwrite current buffer to the original file </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>:w filename.ext</literal> </entry>
                <entry> write current buffer to <literal>filename.ext</literal> </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>:q</literal> </entry>
                <entry> quit <literal>vim</literal> </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>:q!</literal> </entry>
                <entry> force to quit <literal>vim</literal> </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>:only</literal> </entry>
                <entry> close all other split open windows </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>:set nocompatible?</literal> </entry>
                <entry> check if <literal>vim</literal> is in the sane <literal>nocompatible</literal> mode </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>:set nocompatible</literal> </entry>
                <entry> set <literal>vim</literal> to the sane <literal>nocompatible</literal> mode </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>i</literal> </entry>
                <entry> enter the <literal>INSERT</literal> mode  </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>R</literal> </entry>
                <entry> enter the <literal>REPLACE</literal> mode  </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>v</literal> </entry>
                <entry> enter the  <literal>VISUAL</literal> mode </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>V</literal> </entry>
                <entry> enter the linewise <literal>VISUAL</literal> mode </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> Ctrl-<literal>V</literal> </entry>
                <entry> enter the  blockwise <literal>VISUAL</literal> mode </entry>
              </row>
              <row>
                <entry> except <literal>TERMINAL-JOB</literal> </entry>
                <entry> <literal>ESC</literal>-key </entry>
                <entry> enter the <literal>NORMAL</literal> mode </entry>
              </row>
              <row>
                <entry> <literal>NORMAL</literal> </entry>
                <entry> <literal>:term</literal> </entry>
                <entry> enter the <literal>TERMINAL-JOB</literal> mode  </entry>
              </row>
              <row>
                <entry> <literal>TERMINAL-NORMAL</literal> </entry>
                <entry> <literal>i</literal> </entry>
                <entry> enter the <literal>TERMINAL-JOB</literal> mode  </entry>
              </row>
              <row>
                <entry> <literal>TERMINAL-JOB</literal> </entry>
                <entry> Ctrl-<literal>W</literal> <literal>N</literal> (or Ctrl-<literal>\</literal> Ctrl-<literal>N</literal>) </entry>
                <entry> enter the <literal>TERMINAL-NORMAL</literal> mode </entry>
              </row>
              <row>
                <entry> <literal>TERMINAL-JOB</literal> </entry>
                <entry> Ctrl-<literal>W</literal> <literal>:</literal> </entry>
                <entry> enter the <literal>Ex</literal>-mode in <literal>TERMINAL-NORMAL</literal> mode</entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para> Please use the "<literal>vimtutor</literal>" program to learn <literal>vim</literal> through an interactive tutorial course. </para>
        <para> The <literal>vim</literal> program changes its behavior to typed key strokes based on <emphasis role="strong">mode</emphasis>.  Typing in key strokes to the buffer is mostly done in <literal>INSERT</literal>-mode and <literal>REPLACE</literal>-mode.  Moving cursor is mostly done in <literal>NORMAL</literal>-mode.  Interactive selection is done in <literal>VISUAL</literal>-mode.  Typing "<literal>:</literal>" in <literal>NORMAL</literal>-mode changes its <emphasis role="strong">mode</emphasis> to <literal>Ex</literal>-mode. <literal>Ex</literal>-mode accepts commands.</para>
        <tip><para>The Vim comes with the <emphasis role="strong">Netrw</emphasis> package.  Netrw supports reading files, writing files, browsing directories over a network, and local browsing!  Try Netrw with "<literal>vim .</literal>" (a period as the argument) and read its manual at "<literal>:help netrw</literal>". </para> </tip>
        <para> For the advanced configuration of <literal>vim</literal>, see <xref linkend="_customizing_vim"/>.</para>
      </section>
      <section id="_recording_the_shell_activities">
        <title>Recording the shell activities</title>
        <para>The output of the shell command may roll off your screen and may be lost forever.  It is a good practice to log shell activities into the file for you to review them later.  This kind of record is essential when you perform any system administration tasks.</para>
        <tip><para>The new Vim (version>=8.2) can be used to record the shell activities cleanly using <literal>TERMINAL-JOB</literal>-mode.  See <xref linkend="_using_vim"/>.</para> </tip>
        <para>The basic method of recording the shell activity is to run it under <literal>script</literal>(1).</para>
        <para>For example, try the following</para>
        <screen>$ script
Script started, file is typescript</screen>
        <para>Do whatever shell commands under <literal>script</literal>.</para>
        <para>Press <literal>Ctrl-D</literal> to exit <literal>script</literal>.</para>
        <screen>$ vim typescript</screen>
        <para>See <xref linkend="_recording_the_shell_activities_cleanly"/> .</para>
      </section>
      <section id="_basic_unix_commands">
        <title>Basic Unix commands</title>
        <para>Let's learn basic Unix commands.  Here I use "Unix" in its generic sense.  Any Unix clone OSs usually offer equivalent commands.  The Debian system is no exception.  Do not worry if some commands do not work as you wish now. If <literal>alias</literal> is used in the shell, its corresponding command outputs are different.  These examples are not meant to be executed in this order.</para>
        <para>Try all following commands from the non-privileged user account.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of basic Unix commands</title>
          <tgroup cols="2">
            <colspec colwidth="179pt" align="left"/>
            <colspec colwidth="570pt" align="left"/>
            <thead>
              <row>
	        <entry> command </entry>
                <entry> description </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>pwd</literal> </entry>
                <entry> display name of current/working directory </entry>
              </row>
              <row>
                <entry> <literal>whoami</literal> </entry>
                <entry> display current user name </entry>
              </row>
              <row>
                <entry> <literal>id</literal> </entry>
                <entry> display current user identity (name, uid, gid, and associated groups) </entry>
              </row>
              <row>
                <entry> <literal>file <emphasis>foo</emphasis></literal> </entry>
                <entry> display a type of file for the file "<literal><emphasis>foo</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>type -p <emphasis>commandname</emphasis></literal> </entry>
                <entry> display a file location of command "<literal><emphasis>commandname</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>which <emphasis>commandname</emphasis></literal> </entry>
                <entry> , , </entry>
              </row>
              <row>
                <entry> <literal>type <emphasis>commandname</emphasis></literal> </entry>
                <entry> display information on command "<literal><emphasis>commandname</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>apropos <emphasis>key-word</emphasis></literal> </entry>
                <entry> find commands related to "<literal><emphasis>key-word</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>man -k <emphasis>key-word</emphasis></literal> </entry>
                <entry> , , </entry>
              </row>
              <row>
                <entry> <literal>whatis <emphasis>commandname</emphasis></literal> </entry>
                <entry> display one line explanation on command "<literal><emphasis>commandname</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>man -a <emphasis>commandname</emphasis></literal> </entry>
                <entry> display explanation on command "<literal><emphasis>commandname</emphasis></literal>" (Unix style) </entry>
              </row>
              <row>
                <entry> <literal>info <emphasis>commandname</emphasis></literal> </entry>
                <entry> display rather long explanation on command "<literal><emphasis>commandname</emphasis></literal>" (GNU style) </entry>
              </row>
              <row>
                <entry> <literal>ls</literal> </entry>
                <entry> list contents of directory (non-dot files and directories) </entry>
              </row>
              <row>
                <entry> <literal>ls -a</literal> </entry>
                <entry> list contents of directory (all files and directories) </entry>
              </row>
              <row>
                <entry> <literal>ls -A</literal> </entry>
                <entry> list contents of directory (almost all files and directories, i.e., skip "<literal>..</literal>" and "<literal>.</literal>") </entry>
              </row>
              <row>
                <entry> <literal>ls -la</literal> </entry>
                <entry> list all contents of directory with detail information </entry>
              </row>
              <row>
                <entry> <literal>ls -lai</literal> </entry>
                <entry> list all contents of directory with inode number and detail information </entry>
              </row>
              <row>
                <entry> <literal>ls -d</literal> </entry>
                <entry> list all directories under the current directory </entry>
              </row>
              <row>
                <entry> <literal>tree</literal> </entry>
                <entry> display file tree contents </entry>
              </row>
              <row>
                <entry> <literal>lsof <emphasis>foo</emphasis></literal> </entry>
                <entry> list open status of file "<literal><emphasis>foo</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>lsof -p <emphasis>pid</emphasis></literal> </entry>
                <entry> list files opened by the process ID: "<literal><emphasis>pid</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>mkdir <emphasis>foo</emphasis></literal> </entry>
                <entry> make a new directory "<literal><emphasis>foo</emphasis></literal>" in the current directory </entry>
              </row>
              <row>
                <entry> <literal>rmdir <emphasis>foo</emphasis></literal> </entry>
                <entry> remove a directory "<literal><emphasis>foo</emphasis></literal>" in the current directory </entry>
              </row>
              <row>
                <entry> <literal>cd <emphasis>foo</emphasis></literal> </entry>
                <entry> change directory to the directory "<literal><emphasis>foo</emphasis></literal>" in the current directory or in the directory listed in the variable "<literal>$CDPATH</literal>" </entry>
              </row>
              <row>
                <entry> <literal>cd /</literal> </entry>
                <entry> change directory to the root directory </entry>
              </row>
              <row>
                <entry> <literal>cd</literal> </entry>
                <entry> change directory to the current user's home directory </entry>
              </row>
              <row>
                <entry> <literal>cd /<emphasis>foo</emphasis></literal> </entry>
                <entry> change directory to the absolute path directory "<literal>/<emphasis>foo</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>cd ..</literal> </entry>
                <entry> change directory to the parent directory </entry>
              </row>
              <row>
                <entry> <literal>cd ~<emphasis>foo</emphasis></literal> </entry>
                <entry> change directory to the home directory of the user "<literal><emphasis>foo</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>cd -</literal> </entry>
                <entry> change directory to the previous directory </entry>
              </row>
              <row>
                <entry> <literal>&lt;/etc/motd pager</literal> </entry>
                <entry> display contents of "<literal>/etc/motd</literal>" using the default pager </entry>
              </row>
              <row>
                <entry> <literal>touch <emphasis>junkfile</emphasis></literal> </entry>
                <entry> create a empty file "<literal><emphasis>junkfile</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>cp <emphasis>foo</emphasis> <emphasis>bar</emphasis></literal> </entry>
                <entry> copy a existing file "<literal><emphasis>foo</emphasis></literal>" to a new file "<literal><emphasis>bar</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>rm <emphasis>junkfile</emphasis></literal> </entry>
                <entry> remove a file "<literal><emphasis>junkfile</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>mv <emphasis>foo</emphasis> <emphasis>bar</emphasis></literal> </entry>
                <entry> rename an existing file "<literal><emphasis>foo</emphasis></literal>" to a new name "<literal><emphasis>bar</emphasis></literal>" ("<literal><emphasis>bar</emphasis></literal>" must not exist) </entry>
              </row>
              <row>
                <entry> <literal>mv <emphasis>foo</emphasis> <emphasis>bar</emphasis></literal> </entry>
                <entry> move an existing file "<literal><emphasis>foo</emphasis></literal>" to a new location "<literal><emphasis>bar</emphasis>/<emphasis>foo</emphasis></literal>" (the directory "<literal><emphasis>bar</emphasis></literal>" must exist) </entry>
              </row>
              <row>
                <entry> <literal>mv <emphasis>foo</emphasis> <emphasis>bar</emphasis>/<emphasis>baz</emphasis></literal> </entry>
                <entry> move an existing file "<literal><emphasis>foo</emphasis></literal>" to a new location with a new name "<literal><emphasis>bar</emphasis>/<emphasis>baz</emphasis></literal>" (the directory "<literal><emphasis>bar</emphasis></literal>" must exist but the directory "<literal><emphasis>bar</emphasis>/<emphasis>baz</emphasis></literal>" must not exist) </entry>
              </row>
              <row>
                <entry> <literal>chmod 600 <emphasis>foo</emphasis></literal> </entry>
                <entry> make an existing file "<literal><emphasis>foo</emphasis></literal>" to be non-readable and non-writable by the other people (non-executable for all) </entry>
              </row>
              <row>
                <entry> <literal>chmod 644 <emphasis>foo</emphasis></literal> </entry>
                <entry> make an existing file "<literal><emphasis>foo</emphasis></literal>" to be readable but non-writable by the other people (non-executable for all) </entry>
              </row>
              <row>
                <entry> <literal>chmod 755 <emphasis>foo</emphasis></literal> </entry>
                <entry> make an existing file "<literal><emphasis>foo</emphasis></literal>" to be readable but non-writable by the other people (executable for all) </entry>
              </row>
              <row>
                <entry> <literal>find .  -name <emphasis>pattern</emphasis></literal> </entry>
                <entry> find matching filenames using shell "<literal><emphasis>pattern</emphasis></literal>" (slower) </entry>
              </row>
              <row>
                <entry> <literal>locate -d .  <emphasis>pattern</emphasis></literal> </entry>
                <entry> find matching filenames using shell "<literal><emphasis>pattern</emphasis></literal>" (quicker using regularly generated database) </entry>
              </row>
              <row>
                <entry> <literal>grep -e "<emphasis>pattern</emphasis>" *.html</literal> </entry>
                <entry> find a "<literal><emphasis>pattern</emphasis></literal>" in all files ending with "<literal>.html</literal>" in current directory and display them all </entry>
              </row>
              <row>
                <entry> <literal>top</literal> </entry>
                <entry> display process information using full screen, type "<literal>q</literal>" to quit </entry>
              </row>
              <row>
                <entry> <literal>ps aux | pager</literal> </entry>
                <entry> display information on all the running processes using BSD style output </entry>
              </row>
              <row>
                <entry> <literal>ps -ef | pager</literal> </entry>
                <entry> display information on all the running processes using Unix system-V style output </entry>
              </row>
              <row>
                <entry> <literal>ps aux | grep -e "[e]xim4*"</literal> </entry>
                <entry> display all processes running "<literal>exim</literal>" and "<literal>exim4</literal>" </entry>
              </row>
              <row>
                <entry> <literal>ps axf | pager</literal> </entry>
                <entry> display information on all the running processes with ASCII art output </entry>
              </row>
              <row>
                <entry> <literal>kill <emphasis>1234</emphasis></literal> </entry>
                <entry> kill a process identified by the process ID: "<emphasis>1234</emphasis>" </entry>
              </row>
              <row>
                <entry> <literal>gzip <emphasis>foo</emphasis></literal> </entry>
                <entry> compress "<literal><emphasis>foo</emphasis></literal>" to create "<literal><emphasis>foo</emphasis>.gz</literal>" using the Lempel-Ziv coding (LZ77) </entry>
              </row>
              <row>
                <entry> <literal>gunzip <emphasis>foo</emphasis>.gz</literal> </entry>
                <entry> decompress "<literal><emphasis>foo</emphasis>.gz</literal>" to create "<literal><emphasis>foo</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>bzip2 <emphasis>foo</emphasis></literal> </entry>
                <entry> compress "<literal><emphasis>foo</emphasis></literal>" to create "<literal><emphasis>foo</emphasis>.bz2</literal>" using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding (better compression than <literal>gzip</literal>) </entry>
              </row>
              <row>
                <entry> <literal>bunzip2 <emphasis>foo</emphasis>.bz2</literal> </entry>
                <entry> decompress "<literal><emphasis>foo</emphasis>.bz2</literal>" to create "<literal><emphasis>foo</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>xz <emphasis>foo</emphasis></literal> </entry>
                <entry> compress "<literal><emphasis>foo</emphasis></literal>" to create "<literal><emphasis>foo</emphasis>.xz</literal>" using the Lempel–Ziv–Markov chain algorithm (better compression than <literal>bzip2</literal>) </entry>
              </row>
              <row>
                <entry> <literal>unxz <emphasis>foo</emphasis>.xz</literal> </entry>
                <entry> decompress "<literal><emphasis>foo</emphasis>.xz</literal>" to create "<literal><emphasis>foo</emphasis></literal>" </entry>
              </row>
              <row>
                <entry> <literal>tar -xvf <emphasis>foo</emphasis>.tar</literal> </entry>
                <entry> extract files from "<literal><emphasis>foo</emphasis>.tar</literal>" archive </entry>
              </row>
              <row>
                <entry> <literal>tar -xvzf <emphasis>foo</emphasis>.tar.gz</literal> </entry>
                <entry> extract files from gzipped "<literal><emphasis>foo</emphasis>.tar.gz</literal>" archive </entry>
              </row>
              <row>
                <entry> <literal>tar -xvjf <emphasis>foo</emphasis>.tar.bz2</literal> </entry>
                <entry> extract files from "<literal><emphasis>foo</emphasis>.tar.bz2</literal>" archive </entry>
              </row>
              <row>
                <entry> <literal>tar -xvJf <emphasis>foo</emphasis>.tar.xz</literal> </entry>
                <entry> extract files from "<literal><emphasis>foo</emphasis>.tar.xz</literal>" archive </entry>
              </row>
              <row>
                <entry> <literal>tar -cvf <emphasis>foo</emphasis>.tar <emphasis>bar</emphasis>/</literal> </entry>
                <entry> archive contents of folder "<literal><emphasis>bar</emphasis>/</literal>" in "<literal><emphasis>foo</emphasis>.tar</literal>" archive </entry>
              </row>
              <row>
                <entry> <literal>tar -cvzf <emphasis>foo</emphasis>.tar.gz <emphasis>bar</emphasis>/</literal> </entry>
                <entry> archive contents of folder "<literal><emphasis>bar</emphasis>/</literal>" in compressed "<literal><emphasis>foo</emphasis>.tar.gz</literal>" archive </entry>
              </row>
              <row>
                <entry> <literal>tar -cvjf <emphasis>foo</emphasis>.tar.bz2 <emphasis>bar</emphasis>/</literal> </entry>
                <entry> archive contents of folder "<literal><emphasis>bar</emphasis>/</literal>" in "<literal><emphasis>foo</emphasis>.tar.bz2</literal>" archive </entry>
              </row>
              <row>
                <entry> <literal>tar -cvJf <emphasis>foo</emphasis>.tar.xz <emphasis>bar</emphasis>/</literal> </entry>
                <entry> archive contents of folder "<literal><emphasis>bar</emphasis>/</literal>" in "<literal><emphasis>foo</emphasis>.tar.xz</literal>" archive </entry>
              </row>
              <row>
                <entry> <literal>zcat README.gz | pager</literal> </entry>
                <entry> display contents of compressed "<literal>README.gz</literal>" using the default pager </entry>
              </row>
              <row>
                <entry> <literal>zcat README.gz &gt; foo</literal> </entry>
                <entry> create a file "<literal>foo</literal>" with the decompressed content of "<literal>README.gz</literal>" </entry>
              </row>
              <row>
                <entry> <literal>zcat README.gz &gt;&gt; foo</literal> </entry>
                <entry> append the decompressed content of "<literal>README.gz</literal>" to the end of the file "<literal>foo</literal>" (if it does not exist, create it first) </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <note>
          <para>Unix has a tradition to hide filenames which start with "<literal>.</literal>".  They are traditionally files that contain configuration information and user preferences.</para>
          <para>For <literal>cd</literal> command, see <literal>builtins</literal>(7).</para>
          <para>The default pager of the bare bone Debian system is <literal>more</literal>(1) which cannot scroll back.  By installing the <literal>less</literal> package using command line "<literal>apt-get install less</literal>", <literal>less</literal>(1) becomes default pager and you can scroll back with cursor keys.</para>
          <para>The "<literal>[</literal>" and "<literal>]</literal>" in the regular expression of the "<literal>ps aux | grep -e "[e]xim4*"</literal>" command above enable <literal>grep</literal> to avoid matching itself.  The "<literal>4*</literal>" in the regular expression means 0 or more repeats of character "<literal>4</literal>" thus enables <literal>grep</literal> to match both "<literal>exim</literal>" and "<literal>exim4</literal>".  Although "<literal>*</literal>" is used in the shell filename glob and the regular expression, their meanings are different.  Learn the regular expression from <literal>grep</literal>(1).</para>
        </note>
        <para>Please traverse directories and peek into the system using the above commands as training.  If you have questions on any of console commands, please make sure to read the manual page.</para>
        <para>For example, try the following</para>
        <screen>$ man man
$ man bash
$ man builtins
$ man grep
$ man ls</screen>
        <para>The style of man pages may be a little hard to get used to, because they are rather terse, particularly the older, very traditional ones. But once you get used to it, you come to appreciate their succinctness.</para>
        <para>Please note that many Unix-like commands including ones from GNU and BSD display brief help information if you invoke them in one of the following ways (or without any arguments in some cases).</para>
        <screen>$ <emphasis>commandname</emphasis> --help
$ <emphasis>commandname</emphasis> -h</screen>
      </section>
    </section>
    <section id="_the_simple_shell_command">
      <title>The simple shell command</title>
      <para>Now you have some feel on how to use the Debian system.  Let's look deep into the mechanism of the command execution in the Debian system. Here, I have simplified reality for the newbie.  See <literal>bash</literal>(1) for the exact explanation.</para>
      <para>A simple command is a sequence of components.</para>
      <orderedlist>
        <listitem> <para> Variable assignments (optional) </para> </listitem>
        <listitem> <para> Command name </para> </listitem>
        <listitem> <para> Arguments (optional) </para> </listitem>
        <listitem> <para> Redirections (optional: <literal>&gt;</literal> , <literal>&gt;&gt;</literal> , <literal>&lt;</literal> , <literal>&lt;&lt;</literal> , etc.) </para> </listitem>
        <listitem> <para> Control operator (optional: <literal>&amp;&amp;</literal> , <literal>||</literal> , <emphasis>newline</emphasis> , <literal>;</literal> , <literal>&amp;</literal> , <literal>(</literal> , <literal>)</literal> ) </para> </listitem>
      </orderedlist>
      <section id="_command_execution_and_environment_variable">
        <title>Command execution and environment variable</title>
        <para>The values of some <ulink url="https://en.wikipedia.org/wiki/Environment_variable">environment variables</ulink> change the behavior of some Unix commands.</para>
        <para>Default values of environment variables are initially set by the PAM system and then some of them may be reset by some application programs.</para>
        <itemizedlist>
          <listitem> <para> The PAM system such as <literal>pam_env</literal> may set environment variables by <literal>/etc/pam.conf</literal>", "<literal>/etc/environment</literal>" and "<literal>/etc/default/locale</literal>".  </para> </listitem>
          <listitem> <para> The display manager such as <literal>gdm3</literal> may reset environment variables for GUI session by "<literal>~/.profile</literal>".  </para> </listitem>
          <listitem> <para> The user specific program initialization may reset environment variables by "<literal>~/.profile</literal>", "<literal>~/.bash_profile</literal>" and "<literal>~/.bashrc</literal>".  </para> </listitem>
        </itemizedlist>
      </section>
      <section id="_the_literal_lang_literal_variable">
        <title>The "<literal>$LANG</literal>" variable</title>
        <para>The default locale is defined in the "<literal>$LANG</literal>" environment variable and is configured as "<literal>LANG=xx_YY.UTF-8</literal>" by the installer or by the subsequent GUI configuration, e.g., "Settings" → "Region &amp; Language" → "Language" / "Formats" for GNOME.</para>
        <note> <para>I recommend you to configure the system environment just by the "<literal>$LANG</literal>" variable for now and to stay away from "<literal>$LC_*</literal>" variables unless it is absolutely needed.</para> </note>
        <para>The full locale value given to "<literal>$LANG</literal>" variable consists of 3 parts: "<literal>xx_YY.ZZZZ</literal>".</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>The 3 parts of locale value</title>
          <tgroup cols="2">
            <colspec colwidth="70pt" align="left"/>
            <colspec colwidth="504pt" align="left"/>
            <thead>
              <row>
                <entry> locale value </entry>
                <entry> meaning </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>xx</literal> </entry>
                <entry> <ulink url="https://en.wikipedia.org/wiki/ISO_639">ISO 639 language codes (lower case) such as "en"</ulink> </entry>
              </row>
              <row>
                <entry> <literal>YY</literal> </entry>
                <entry> <ulink url="https://en.wikipedia.org/wiki/ISO_3166-3">ISO 3166 country codes (upper case) such as "US"</ulink> </entry>
              </row>
              <row>
                <entry> <literal>ZZZZ</literal> </entry>
                <entry> <ulink url="https://en.wikipedia.org/wiki/Codeset">codeset, always set to "UTF-8"</ulink> </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of locale recommendations</title>
          <tgroup cols="2">
            <colspec colwidth="119pt" align="left"/>
            <colspec colwidth="141pt" align="left"/>
            <thead>
              <row>
                <entry> locale recommendation </entry>
                <entry> Language (area) </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>en_US.UTF-8</literal> </entry>
                <entry> English (USA) </entry>
              </row>
              <row>
                <entry> <literal>en_GB.UTF-8</literal> </entry>
                <entry> English (Great Britain) </entry>
              </row>
              <row>
                <entry> <literal>fr_FR.UTF-8</literal> </entry>
                <entry> French (France) </entry>
              </row>
              <row>
                <entry> <literal>de_DE.UTF-8</literal> </entry>
                <entry> German (Germany) </entry>
              </row>
              <row>
                <entry> <literal>it_IT.UTF-8</literal> </entry>
                <entry> Italian (Italy) </entry>
              </row>
              <row>
                <entry> <literal>es_ES.UTF-8</literal> </entry>
                <entry> Spanish (Spain) </entry>
              </row>
              <row>
                <entry> <literal>ca_ES.UTF-8</literal> </entry>
                <entry> Catalan (Spain) </entry>
              </row>
              <row>
                <entry> <literal>sv_SE.UTF-8</literal> </entry>
                <entry> Swedish (Sweden) </entry>
              </row>
              <row>
                <entry> <literal>pt_BR.UTF-8</literal> </entry>
                <entry> Portuguese (Brazil) </entry>
              </row>
              <row>
                <entry> <literal>ru_RU.UTF-8</literal> </entry>
                <entry> Russian (Russia) </entry>
              </row>
              <row>
                <entry> <literal>zh_CN.UTF-8</literal> </entry>
                <entry> Chinese (P.R. of China) </entry>
              </row>
              <row>
                <entry> <literal>zh_TW.UTF-8</literal> </entry>
                <entry> Chinese (Taiwan R.O.C.) </entry>
              </row>
              <row>
                <entry> <literal>ja_JP.UTF-8</literal> </entry>
                <entry> Japanese (Japan) </entry>
              </row>
              <row>
                <entry> <literal>ko_KR.UTF-8</literal> </entry>
                <entry> Korean (Republic of Korea) </entry>
              </row>
              <row>
                <entry> <literal>vi_VN.UTF-8</literal> </entry>
                <entry> Vietnamese (Vietnam) </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>Typical command execution uses a shell line sequence as the following.</para>
        <screen>$ echo $LANG
en_US.UTF-8
$ date -u
Wed 19 May 2021 03:18:43 PM UTC
$ LANG=fr_FR.UTF-8 date -u
mer. 19 mai 2021 15:19:02 UTC</screen>
        <para>Here, the program <literal>date</literal>(1) is executed with different locale values.</para>
        <itemizedlist>
          <listitem> <para> For the first command, "<literal>$LANG</literal>" is set to the system default <ulink url="https://en.wikipedia.org/wiki/Locale">locale</ulink> value "<literal>en_US.UTF-8</literal>".  </para> </listitem>
          <listitem> <para> For the second command, "<literal>$LANG</literal>" is set to the French UTF-8 <ulink url="https://en.wikipedia.org/wiki/Locale">locale</ulink> value "<literal>fr_FR.UTF-8</literal>".  </para> </listitem>
        </itemizedlist>
        <para>Most command executions usually do not have preceding environment variable definition.  For the above example, you can alternatively execute as the following.</para>
        <screen>$ LANG=fr_FR.UTF-8
$ date -u
mer. 19 mai 2021 15:19:24 UTC</screen>
        <tip> <para>When filing a bug report, running and checking the command under "<literal>en_US.UTF-8</literal>" locale is a good idea if you use non-English environment.</para> </tip>
        <para>For fine details of the locale configuration, see <xref linkend="_the_locale"/>.</para>
      </section>
      <section id="_the_literal_path_literal_variable">
        <title>The "<literal>$PATH</literal>" variable</title>
        <para>When you type a command into the shell, the shell searches the command in the list of directories contained in the "<literal>$PATH</literal>" environment variable.  The value of the "<literal>$PATH</literal>" environment variable is also called the shell's search path.</para>
        <para>In the default Debian installation, the "<literal>$PATH</literal>" environment variable of user accounts may not include "<literal>/usr/sbin</literal>" and "<literal>/usr/sbin</literal>".  For example, the <literal>ifconfig</literal> command needs to be issued with full path as "<literal>/usr/sbin/ifconfig</literal>". (Similar <literal>ip</literal> command is located in "<literal>/usr/bin</literal>".)</para>
        <para>You can change the "<literal>$PATH</literal>" environment variable of Bash shell by "<literal>~/.bash_profile</literal>" or "<literal>~/.bashrc</literal>" files.</para>
      </section>
      <section id="_the_literal_home_literal_variable">
        <title>The "<literal>$HOME</literal>" variable</title>
        <para>Many commands stores user specific configuration in the home directory and changes their behavior by their contents.  The home directory is identified by the environment variable "<literal>$HOME</literal>".</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of "<literal>$HOME</literal>" values</title>
          <tgroup cols="2">
            <colspec colwidth="119pt" align="left"/>
            <colspec colwidth="271pt" align="left"/>
            <thead>
              <row>
                <entry> value of "<literal>$HOME</literal>" </entry>
                <entry> program execution situation </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>/</literal> </entry>
                <entry> program run by the init process (daemon) </entry>
              </row>
              <row>
                <entry> <literal>/root</literal> </entry>
                <entry> program run from the normal root shell </entry>
              </row>
              <row>
                <entry> <literal>/home/<emphasis>normal_user</emphasis></literal> </entry>
                <entry> program run from the normal user shell </entry>
              </row>
              <row>
                <entry> <literal>/home/<emphasis>normal_user</emphasis></literal> </entry>
                <entry> program run from the normal user GUI desktop menu </entry>
              </row>
              <row>
                <entry> <literal>/home/<emphasis>normal_user</emphasis></literal> </entry>
                <entry> program run as root with "<literal>sudo program</literal>" </entry>
              </row>
              <row>
                <entry> <literal>/root</literal> </entry>
                <entry> program run as root with "<literal>sudo -H program</literal>" </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <tip> <para>Shell expands "<literal>~/</literal>" to current user's home directory, i.e., "<literal>$HOME/</literal>". Shell expands "<literal>~foo/</literal>" to <literal>foo</literal>'s home directory, i.e., "<literal>/home/foo/</literal>".</para> </tip>
        <para> See <xref linkend="_shell_environment_variables"/> if <literal>$HOME</literal> isn't available for your program.</para>
      </section>
      <section id="_command_line_options">
        <title>Command line options</title>
        <para>Some commands take arguments.  Arguments starting with "<literal>-</literal>" or "<literal>--</literal>" are called options and control the behavior of the command.</para>
        <screen>$ date
Thu 20 May 2021 01:08:08 AM JST
$ date -R
Thu, 20 May 2021 01:08:12 +0900</screen>
        <para>Here the command-line argument "<literal>-R</literal>" changes <literal>date</literal>(1) behavior to output <ulink url="https://datatracker.ietf.org/doc/rfc2822/">RFC2822</ulink> compliant date string.</para>
      </section>
      <section id="_shell_glob">
        <title>Shell glob</title>
        <para>Often you want a command to work with a group of files without typing all of them.  The filename expansion pattern using the shell <emphasis role="strong">glob</emphasis>, (sometimes referred as <emphasis role="strong">wildcards</emphasis>), facilitate this need.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>Shell glob patterns</title>
          <tgroup cols="2">
            <colspec colwidth="103pt" align="left"/>
            <colspec colwidth="548pt" align="left"/>
            <thead>
              <row>
                <entry> shell glob pattern </entry>
                <entry> description of match rule </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>*</literal> </entry>
                <entry> filename (segment) not started with "<literal>.</literal>" </entry>
              </row>
              <row>
                <entry> <literal>.*</literal> </entry>
                <entry> filename (segment) started with "<literal>.</literal>" </entry>
              </row>
              <row>
                <entry> <literal>?</literal> </entry>
                <entry> exactly one character </entry>
              </row>
              <row>
                <entry> <literal>[…]</literal> </entry>
                <entry> exactly one character with any character enclosed in brackets </entry>
              </row>
              <row>
                <entry> <literal>[a-z]</literal> </entry>
                <entry> exactly one character with any character between "<literal>a</literal>" and "<literal>z</literal>" </entry>
              </row>
              <row>
                <entry> <literal>[^…]</literal> </entry>
                <entry> exactly one character other than any character enclosed in brackets (excluding "<literal>^</literal>") </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>For example, try the following</para>
        <screen>$ mkdir junk; cd junk; touch 1.txt 2.txt 3.c 4.h .5.txt ..6.txt
$ echo *.txt
1.txt 2.txt
$ echo *
1.txt 2.txt 3.c 4.h
$ echo *.[hc]
3.c 4.h
$ echo .*
. .. .5.txt ..6.txt
$ echo .*[^.]*
.5.txt ..6.txt
$ echo [^1-3]*
4.h
$ cd ..; rm -rf junk</screen>
        <para>See <literal>glob</literal>(7).</para>
        <note> <para>Unlike normal filename expansion by the shell, the shell pattern "<literal>*</literal>" tested in <literal>find</literal>(1) with "<literal>-name</literal>" test etc., matches the initial "<literal>.</literal>" of the filename. (New <ulink url="https://en.wikipedia.org/wiki/POSIX">POSIX</ulink> feature)</para> </note>
        <note> <para>BASH can be tweaked to change its glob behavior with its shopt builtin options such as "<literal>dotglob</literal>", "<literal>noglob</literal>", "<literal>nocaseglob</literal>", "<literal>nullglob</literal>", "<literal>extglob</literal>", etc.  See <literal>bash</literal>(1).</para> </note>
      </section>
      <section id="_return_value_of_the_command">
        <title>Return value of the command</title>
        <para>Each command returns its exit status (variable: "<literal>$?</literal>") as the return value.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>Command exit codes</title>
          <tgroup cols="3">
            <colspec colwidth="108pt" align="left"/>
            <colspec colwidth="114pt" align="left"/>
            <colspec colwidth="114pt" align="left"/>
            <thead>
              <row>
	        <entry> command exit status </entry>
                <entry> numeric return value </entry>
                <entry> logical return value </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> success </entry>
                <entry> zero, 0 </entry>
                <entry> <emphasis role="strong">TRUE</emphasis> </entry>
              </row>
              <row>
                <entry> error </entry>
                <entry> non-zero, -1 </entry>
                <entry> <emphasis role="strong">FALSE</emphasis> </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>For example, try the following.</para>
        <screen>$ [ 1 = 1 ] ; echo $?
0
$ [ 1 = 2 ] ; echo $?
1</screen>
        <note> <para>Please note that, in the logical context for the shell, <emphasis role="strong">success</emphasis> is treated as the logical <emphasis role="strong">TRUE</emphasis> which has 0 (zero) as its value.  This is somewhat non-intuitive and needs to be reminded here.</para> </note>
      </section>
      <section id="_typical_command_sequences_and_shell_redirection">
        <title>Typical command sequences and shell redirection</title>
        <para>Let's try to remember following shell command idioms typed in one line as a part of shell command.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>Shell command idioms</title>
          <tgroup cols="2">
            <colspec colwidth="146pt" align="left"/>
            <colspec colwidth="602pt" align="left"/>
            <thead>
              <row>
                <entry> command idiom </entry>
                <entry> description </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>command &amp;</literal> </entry>
                <entry><emphasis role="strong">background</emphasis> execution of <literal>command</literal> in the subshell </entry>
              </row>
              <row>
                <entry> <literal>command1 | command2</literal> </entry>
                <entry><emphasis role="strong">pipe</emphasis> the standard output of <literal>command1</literal> to the standard input of <literal>command2</literal> (<emphasis role="strong">concurrent</emphasis> execution) </entry>
              </row>
              <row>
                <entry> <literal>command1 2&gt;&amp;1 | command2</literal> </entry>
                <entry><emphasis role="strong">pipe</emphasis> both standard output and standard error of <literal>command1</literal> to the standard input of <literal>command2</literal> (<emphasis role="strong">concurrent</emphasis> execution) </entry>
              </row>
              <row>
                <entry> <literal>command1 ; command2</literal> </entry>
                <entry> execute <literal>command1</literal> and <literal>command2</literal> <emphasis role="strong">sequentially</emphasis> </entry>
              </row>
              <row>
                <entry> <literal>command1 &amp;&amp; command2</literal> </entry>
                <entry> execute <literal>command1</literal>; if successful, execute <literal>command2</literal> <emphasis role="strong">sequentially</emphasis> (return success if both <literal>command1</literal> <emphasis role="strong">and</emphasis> <literal>command2</literal> are successful) </entry>
              </row>
              <row>
                <entry> <literal>command1 || command2</literal> </entry>
                <entry> execute <literal>command1</literal>; if not successful, execute <literal>command2</literal> <emphasis role="strong">sequentially</emphasis> (return success if <literal>command1</literal> <emphasis role="strong">or</emphasis> <literal>command2</literal> are successful) </entry>
              </row>
              <row>
                <entry> <literal>command &gt; foo</literal> </entry>
                <entry> redirect standard output of <literal>command</literal> to a file <literal>foo</literal> (overwrite) </entry>
              </row>
              <row>
                <entry> <literal>command 2&gt; foo</literal> </entry>
                <entry> redirect standard error of <literal>command</literal> to a file <literal>foo</literal> (overwrite) </entry>
              </row>
              <row>
                <entry> <literal>command &gt;&gt; foo</literal> </entry>
                <entry> redirect standard output of <literal>command</literal> to a file <literal>foo</literal> (append) </entry>
              </row>
              <row>
                <entry> <literal>command 2&gt;&gt; foo</literal> </entry>
                <entry> redirect standard error of <literal>command</literal> to a file <literal>foo</literal> (append) </entry>
              </row>
              <row>
                <entry> <literal>command &gt; foo 2&gt;&amp;1</literal> </entry>
                <entry> redirect both standard output and standard error of <literal>command</literal> to a file <literal>foo</literal> </entry>
              </row>
              <row>
                <entry> <literal>command &lt; foo</literal> </entry>
                <entry> redirect standard input of <literal>command</literal> to a file <literal>foo</literal> </entry>
              </row>
              <row>
                <entry> <literal>command &lt;&lt; delimiter</literal> </entry>
                <entry> redirect standard input of <literal>command</literal> to the following lines until "<literal>delimiter</literal>" is met (here document) </entry>
              </row>
              <row>
                <entry> <literal>command &lt;&lt;- delimiter</literal> </entry>
                <entry> redirect standard input of <literal>command</literal> to the following lines until "<literal>delimiter</literal>" is met (here document, the leading tab characters are stripped from input lines) </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>The Debian system is a multi-tasking system. Background jobs allow users to run multiple programs in a single shell.  The management of the background process involves the shell builtins: <literal>jobs</literal>, <literal>fg</literal>, <literal>bg</literal>, and <literal>kill</literal>.  Please read sections of bash(1) under "SIGNALS", and "JOB CONTROL", and <literal>builtins</literal>(1).</para>
        <para>For example, try the following</para>
        <screen>$ &lt;/etc/motd pager</screen>
        <screen>$ pager &lt;/etc/motd</screen>
        <screen>$ pager /etc/motd</screen>
        <screen>$ cat /etc/motd | pager</screen>
        <para>Although all 4 examples of shell redirections display the same thing, the last example runs an extra <literal>cat</literal> command and wastes resources with no reason.</para>
        <para>The shell allows you to open files using the <literal>exec</literal> builtin with an arbitrary file descriptor.</para>
        <screen>$ echo Hello &gt;foo
$ exec 3&lt;foo 4&gt;bar  # open files
$ cat &lt;&amp;3 &gt;&amp;4       # redirect stdin to 3, stdout to 4
$ exec 3&lt;&amp;- 4&gt;&amp;-    # close files
$ cat bar
Hello</screen>
        <para>The file descriptor 0-2 are predefined.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>Predefined file descriptors</title>
          <tgroup cols="3">
            <colspec colwidth="48pt" align="left"/>
            <colspec colwidth="86pt" align="left"/>
            <colspec colwidth="86pt" align="left"/>
            <thead>
              <row>
                <entry> device </entry>
                <entry> description </entry>
                <entry> file descriptor </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>stdin</literal> </entry>
                <entry> standard input </entry>
                <entry> 0 </entry>
              </row>
              <row>
                <entry> <literal>stdout</literal> </entry>
                <entry> standard output </entry>
                <entry> 1 </entry>
              </row>
              <row>
                <entry> <literal>stderr</literal> </entry>
                <entry> standard error </entry>
                <entry> 2 </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
      </section>
      <section id="_command_alias">
        <title>Command alias</title>
        <para>You can set an alias for the frequently used command.</para>
        <para>For example, try the following</para>
        <screen>$ alias la='ls -la'</screen>
        <para>Now, "<literal>la</literal>" works as a short hand for "<literal>ls -la</literal>" which lists all files in the long listing format.</para>
        <para>You can list any existing aliases by <literal>alias</literal> (see <literal>bash</literal>(1) under "SHELL BUILTIN COMMANDS").</para>
        <screen>$ alias
...
alias la='ls -la'</screen>
        <para>You can identity exact path or identity of the command by <literal>type</literal> (see <literal>bash</literal>(1) under "SHELL BUILTIN COMMANDS").</para>
        <para>For example, try the following</para>
        <screen>$ type ls
ls is hashed (/bin/ls)
$ type la
la is aliased to ls -la
$ type echo
echo is a shell builtin
$ type file
file is /usr/bin/file</screen>
        <para>Here <literal>ls</literal> was recently searched while "<literal>file</literal>" was not, thus "<literal>ls</literal>" is "hashed", i.e., the shell has an internal record for the quick access to the location of the "<literal>ls</literal>" command.</para>
        <tip> <para>See <xref linkend="_colorized_commands"/>.</para> </tip>
      </section>
    </section>
    <section id="_unix_like_text_processing">
      <title>Unix-like text processing</title>
      <para>In Unix-like work environment, text processing is done by piping text through chains of standard text processing tools. This was another crucial Unix innovation.</para>
      <section id="_unix_text_tools">
        <title>Unix text tools</title>
        <para>There are few standard text processing tools which are used very often on the Unix-like system.</para>
        <itemizedlist>
          <listitem>
            <para> No regular expression is used: </para>
            <itemizedlist>
              <listitem> <para><literal>cat</literal>(1) concatenates files and outputs the whole content.  </para> </listitem>
              <listitem> <para><literal>tac</literal>(1) concatenates files and outputs in reverse.  </para> </listitem>
              <listitem> <para><literal>cut</literal>(1) selects parts of lines and outputs.  </para> </listitem>
              <listitem> <para><literal>head</literal>(1) outputs the first part of files.  </para> </listitem>
              <listitem> <para><literal>tail</literal>(1) outputs the last part of files.  </para> </listitem>
              <listitem> <para><literal>sort</literal>(1) sorts lines of text files.  </para> </listitem>
              <listitem> <para><literal>uniq</literal>(1) removes duplicate lines from a sorted file.  </para> </listitem>
              <listitem> <para><literal>tr</literal>(1) translates or deletes characters.  </para> </listitem>
              <listitem> <para><literal>diff</literal>(1) compares files line by line.  </para> </listitem>
            </itemizedlist>
          </listitem>
          <listitem>
            <para> Basic regular expression (<emphasis role="strong">BRE</emphasis>) is used as default: </para>
            <itemizedlist>
              <listitem> <para><literal>ed</literal>(1) is a primitive line editor.  </para> </listitem>
              <listitem> <para><literal>sed</literal>(1) is a stream editor.  </para> </listitem>
              <listitem> <para><literal>grep</literal>(1) matches text with patterns.  </para> </listitem>
              <listitem> <para><literal>vim</literal>(1) is a screen editor.  </para> </listitem>
              <listitem> <para><literal>emacs</literal>(1) is a screen editor. (somewhat extended <emphasis role="strong">BRE</emphasis>) </para> </listitem>
            </itemizedlist>
          </listitem>
          <listitem>
            <para> Extended regular expression (<emphasis role="strong">ERE</emphasis>) is used: </para>
            <itemizedlist>
              <listitem> <para><literal>awk</literal>(1) does simple text processing.  </para> </listitem>
              <listitem> <para><literal>egrep</literal>(1) matches text with patterns.  </para> </listitem>
              <listitem> <para><literal>tcl</literal>(3tcl) can do every conceivable text processing: See <literal>re_syntax</literal>(3). Often used with <literal>tk</literal>(3tk).  </para> </listitem>
              <listitem> <para><literal>perl</literal>(1) can do every conceivable text processing. See <literal>perlre</literal>(1).  </para> </listitem>
              <listitem> <para><literal>pcregrep</literal>(1) from the <literal>pcregrep</literal> package matches text with <ulink url="https://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions">Perl Compatible Regular Expressions (PCRE)</ulink> pattern.  </para> </listitem>
              <listitem> <para><literal>python</literal>(1) with the <literal>re</literal> module can do every conceivable text processing. See "<literal>/usr/share/doc/python/html/index.html</literal>".  </para> </listitem>
            </itemizedlist>
          </listitem>
        </itemizedlist>
        <para>If you are not sure what exactly these commands do, please use "<literal>man command</literal>" to figure it out by yourself.</para>
        <note> <para>Sort order and range expression are locale dependent.  If you wish to obtain traditional behavior for a command, use <emphasis role="strong">C</emphasis> locale or <emphasis role="strong">C.UTF-8</emphasis> locale instead of normal <emphasis role="strong">UTF-8</emphasis> ones (see <xref linkend="_the_locale"/>).</para> </note>
        <note> <para><ulink url="https://en.wikipedia.org/wiki/Perl">Perl</ulink> regular expressions (<literal>perlre</literal>(1)), <ulink url="https://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions">Perl Compatible Regular Expressions (PCRE)</ulink>, and <ulink url="https://en.wikipedia.org/wiki/Python_(programming_language)">Python</ulink> regular expressions offered by the <literal>re</literal> module have many common extensions to the normal <emphasis role="strong">ERE</emphasis>.</para> </note>
      </section>
      <section id="_regular_expressions">
        <title>Regular expressions</title>
        <para><ulink url="https://en.wikipedia.org/wiki/Regular_expression">Regular expressions</ulink> are used in many text processing tools.  They are analogous to the shell globs, but they are more complicated and powerful.</para>
        <para>The regular expression describes the matching pattern and is made up of text characters and <emphasis role="strong">metacharacters</emphasis>.</para>
        <para>A <emphasis role="strong">metacharacter</emphasis> is just a character with a special meaning.  There are 2 major styles, <emphasis role="strong">BRE</emphasis> and <emphasis role="strong">ERE</emphasis>, depending on the text tools as described above.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>Metacharacters for BRE and ERE</title>
          <tgroup cols="3">
            <colspec colwidth="135pt" align="left"/>
            <colspec colwidth="114pt" align="left"/>
            <colspec colwidth="499pt" align="left"/>
            <thead>
              <row>
                <entry> BRE </entry>
                <entry> ERE </entry>
                <entry> description of the regular expression </entry>
              </row>
            </thead>
            <tbody>
              <row>
	        <entry> <literal>\ .  [ ] ^ $ *</literal> </entry>
                <entry> <literal>\ .  [ ] ^ $ *</literal> </entry>
                <entry> common <emphasis role="strong">metacharacters</emphasis> </entry>
              </row>
              <row>
                <entry> <literal>\+ \? \( \) \{ \} \|</literal> </entry>
                <entry>   </entry>
                <entry> BRE only "<literal>\</literal>" escaped <emphasis role="strong">metacharacters</emphasis> </entry>
              </row>
              <row>
                <entry>   </entry>
                <entry> <literal>+ ? ( ) { } |</literal> </entry>
                <entry> ERE only non-"<literal>\</literal>" escaped <emphasis role="strong">metacharacters</emphasis> </entry>
              </row>
              <row>
                <entry> <literal>c</literal> </entry>
                <entry> <literal>c</literal> </entry>
                <entry> match <emphasis role="strong">non-metacharacter</emphasis> "<literal>c</literal>" </entry>
              </row>
              <row>
                <entry> <literal>\c</literal> </entry>
                <entry> <literal>\c</literal> </entry>
                <entry> match a literal character "<literal>c</literal>" even if "<literal>c</literal>" is <emphasis role="strong">metacharacter</emphasis> by itself </entry>
              </row>
              <row>
                <entry> <literal>.</literal> </entry>
                <entry> <literal>.</literal> </entry>
                <entry> match any character including newline </entry>
              </row>
              <row>
                <entry> <literal>^</literal> </entry>
                <entry> <literal>^</literal> </entry>
                <entry> position at the beginning of a string </entry>
              </row>
              <row>
                <entry> <literal>$</literal> </entry>
                <entry> <literal>$</literal> </entry>
                <entry> position at the end of a string </entry>
              </row>
              <row>
                <entry> <literal>\&lt;</literal> </entry>
                <entry> <literal>\&lt;</literal> </entry>
                <entry> position at the beginning of a word </entry>
              </row>
              <row>
                <entry> <literal>\&gt;</literal> </entry>
                <entry> <literal>\&gt;</literal> </entry>
                <entry> position at the end of a word </entry>
              </row>
              <row>
                <entry> <literal>[abc…]</literal> </entry>
                <entry> <literal>[abc…]</literal> </entry>
                <entry> match any characters in "<literal>abc…</literal>" </entry>
              </row>
              <row>
                <entry> <literal>[^abc…]</literal> </entry>
                <entry> <literal>[^abc…]</literal> </entry>
                <entry> match any characters except in "<literal>abc…</literal>" </entry>
              </row>
              <row>
                <entry> <literal>r*</literal> </entry>
                <entry> <literal>r*</literal> </entry>
                <entry> match zero or more regular expressions identified by "<literal>r</literal>" </entry>
              </row>
              <row>
                <entry> <literal>r\+</literal> </entry>
                <entry> <literal>r+</literal> </entry>
                <entry> match one or more regular expressions identified by "<literal>r</literal>" </entry>
              </row>
              <row>
                <entry> <literal>r\?</literal> </entry>
                <entry> <literal>r?</literal> </entry>
                <entry> match zero or one regular expressions identified by "<literal>r</literal>" </entry>
              </row>
              <row>
                <entry> <literal>r1\|r2</literal> </entry>
                <entry> <literal>r1|r2</literal> </entry>
                <entry> match one of the regular expressions identified by "<literal>r1</literal>" or "<literal>r2</literal>" </entry>
              </row>
              <row>
                <entry> <literal>\(r1\|r2\)</literal> </entry>
                <entry> <literal>(r1|r2)</literal> </entry>
                <entry> match one of the regular expressions identified by "<literal>r1</literal>" or "<literal>r2</literal>" and treat it as a <emphasis role="strong">bracketed</emphasis> regular expression </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>The regular expression of <emphasis role="strong"><literal>emacs</literal></emphasis> is basically <emphasis role="strong">BRE</emphasis> but has been extended to treat "<literal>+</literal>"and "<literal>?</literal>" as the <emphasis role="strong">metacharacters</emphasis> as in <emphasis role="strong">ERE</emphasis>.  Thus, there are no needs to escape them with "<literal>\</literal>" in the regular expression of <literal>emacs</literal>.</para>
        <para><literal>grep</literal>(1) can be used to perform the text search using the regular expression.</para>
        <para>For example, try the following</para>
        <screen>$ egrep 'GNU.*LICENSE|Yoyodyne' /usr/share/common-licenses/GPL
GNU GENERAL PUBLIC LICENSE
GNU GENERAL PUBLIC LICENSE
Yoyodyne, Inc., hereby disclaims all copyright interest in the program</screen>
        <tip> <para>See <xref linkend="_colorized_commands"/>.</para> </tip>
      </section>
      <section id="_replacement_expressions">
        <title>Replacement expressions</title>
        <para>For the replacement expression, some characters have special meanings.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>The replacement expression</title>
          <tgroup cols="2">
            <colspec colwidth="124pt" align="left"/>
            <colspec colwidth="423pt" align="left"/>
            <thead>
              <row>
                <entry> replacement expression </entry>
                <entry> description of the text to replace the replacement expression </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>&amp;</literal> </entry>
                <entry> what the regular expression matched (use <literal>\&amp;</literal> in <literal>emacs</literal>) </entry>
              </row>
              <row>
                <entry> <literal>\n</literal> </entry>
                <entry> what the n-th <emphasis role="strong">bracketed</emphasis> regular expression matched ("n" being number) </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>For Perl replacement string, "$&amp;" is used instead of "&amp;" and "$n" is used instead of "\n".</para>
        <para>For example, try the following</para>
        <screen>$ echo zzz1abc2efg3hij4 | \
sed -e 's/\(1[a-z]*\)[0-9]*\(.*\)$/=&amp;=/'
zzz=1abc2efg3hij4=
$ echo zzz1abc2efg3hij4 | \
sed -E -e 's/(1[a-z]*)[0-9]*(.*)$/=&amp;=/'
zzz=1abc2efg3hij4=
$ echo zzz1abc2efg3hij4 | \
perl -pe 's/(1[a-z]*)[0-9]*(.*)$/=$&amp;=/'
zzz=1abc2efg3hij4=
$ echo zzz1abc2efg3hij4 | \
sed -e 's/\(1[a-z]*\)[0-9]*\(.*\)$/\2===\1/'
zzzefg3hij4===1abc
$ echo zzz1abc2efg3hij4 | \
sed -E -e 's/(1[a-z]*)[0-9]*(.*)$/\2===\1/'
zzzefg3hij4===1abc
$ echo zzz1abc2efg3hij4 | \
perl -pe 's/(1[a-z]*)[0-9]*(.*)$/$2===$1/'
zzzefg3hij4===1abc</screen>
        <para>Here please pay extra attention to the style of the <emphasis role="strong">bracketed</emphasis> regular expression and how the matched strings are used in the text replacement process on different tools.</para>
        <para>These regular expressions can be used for cursor movements and text replacement actions in some editors too.</para>
        <para>The back slash "<literal>\</literal>" at the end of line in the shell commandline escapes newline as a white space character and continues shell command line input to the next line.</para>
        <para>Please read all the related manual pages to learn these commands.</para>
      </section>
      <section id="_global_substitution_with_regular_expressions">
        <title>Global substitution with regular expressions</title>
        <para>The <literal>ed</literal>(1) command can replace all instances of "<literal>FROM_REGEX</literal>" with "<literal>TO_TEXT</literal>" in "<literal>file</literal>".</para>
        <screen>$ ed file &lt;&lt;EOF
,s/FROM_REGEX/TO_TEXT/g
w
q
EOF</screen>
        <para>The <literal>sed</literal>(1) command can replace all instances of "<literal>FROM_REGEX</literal>" with "<literal>TO_TEXT</literal>" in "<literal>file</literal>".</para>
        <screen>$ sed -i -e 's/FROM_REGEX/TO_TEXT/g' file</screen>
        <para>The <literal>vim</literal>(1) command can replace all instances of "<literal>FROM_REGEX</literal>" with "<literal>TO_TEXT</literal>" in "<literal>file</literal>" by using <literal>ex</literal>(1) commands.</para>
        <screen>$ vim '+%s/FROM_REGEX/TO_TEXT/gc' '+update' '+q' file</screen>
        <tip> <para>The "<literal>c</literal>" flag in the above ensures interactive confirmation for each substitution.</para> </tip>
        <para>Multiple files ("<literal>file1</literal>", "<literal>file2</literal>", and "<literal>file3</literal>") can be processed with regular expressions similarly with <literal>vim</literal>(1) or <literal>perl</literal>(1).</para>
        <screen>$ vim '+argdo %s/FROM_REGEX/TO_TEXT/gce|update' '+q' file1 file2 file3</screen>
        <tip> <para>The "<literal>e</literal>" flag in the above prevents the "No match" error from breaking a mapping.</para> </tip>
        <screen>$ perl -i -p -e 's/FROM_REGEX/TO_TEXT/g;' file1 file2 file3</screen>
        <para>In the perl(1) example, "<literal>-i</literal>" is for the in-place editing of each target file, and "<literal>-p</literal>" is for the implicit loop over all given files.</para>
        <tip> <para>Use of argument "<literal>-i.bak</literal>" instead of "<literal>-i</literal>" keeps each original file by adding "<literal>.bak</literal>" to its filename.  This makes recovery from errors easier for complex substitutions.</para> </tip>
        <note> <para><literal>ed</literal>(1) and <literal>vim</literal>(1) are <emphasis role="strong">BRE</emphasis>; <literal>perl</literal>(1) is <emphasis role="strong">ERE</emphasis>.</para> </note>
      </section>
      <section id="_extracting_data_from_text_file_table">
        <title>Extracting data from text file table</title>
        <para>Let's consider a text file called "<literal>DPL</literal>" in which some pre-2004 Debian project leader's names and their initiation date are listed in a
space-separated format.</para>
        <screen>Ian     Murdock   August  1993
Bruce   Perens    April   1996
Ian     Jackson   January 1998
Wichert Akkerman  January 1999
Ben     Collins   April   2001
Bdale   Garbee    April   2002
Martin  Michlmayr March   2003</screen>
        <tip>
          <para>See <ulink url="https://www.debian.org/doc/manuals/project-history/">"A Brief History of Debian"</ulink> for the latest <ulink url="https://www.debian.org/doc/manuals/project-history/leaders">Debian leadership history</ulink>.</para>
        </tip>
        <para>Awk is frequently used to extract data from these types of files.</para>
        <para>For example, try the following</para>
        <screen>$ awk '{ print $3 }' &lt;DPL                   # month started
August
April
January
January
April
April
March
$ awk '($1=="Ian") { print }' &lt;DPL          # DPL called Ian
Ian     Murdock   August  1993
Ian     Jackson   January 1998
$ awk '($2=="Perens") { print $3,$4 }' &lt;DPL # When Perens started
April 1996</screen>
        <para>Shells such as Bash can be also used to parse this kind of file.</para>
        <para>For example, try the following</para>
        <screen>$ while read first last month year; do
    echo $month
  done &lt;DPL
... same output as the first Awk example</screen>
        <para>Here, the <literal>read</literal> builtin command uses characters in "<literal>$IFS</literal>" (internal field separators) to split lines into words.</para>
        <para>If you change "<literal>$IFS</literal>" to "<literal>:</literal>", you can parse "<literal>/etc/passwd</literal>" with shell nicely.</para>
        <screen>$ oldIFS="$IFS"   # save old value
$ IFS=':'
$ while read user password uid gid rest_of_line; do
    if [ "$user" = "bozo" ]; then
      echo "$user's ID is $uid"
    fi
  done &lt; /etc/passwd
bozo's ID is 1000
$ IFS="$oldIFS"   # restore old value</screen>
        <para>(If Awk is used to do the equivalent, use "<literal>FS=':'</literal>" to set the field separator.)</para>
        <para>IFS is also used by the shell to split results of parameter expansion, command substitution, and arithmetic expansion.  These do not occur within double or single quoted words.  The default value of IFS is <emphasis>space</emphasis>, <emphasis>tab</emphasis>, and <emphasis>newline</emphasis> combined.</para>
        <para>Be careful about using this shell IFS tricks.  Strange things may happen, when shell interprets some parts of the script as its <emphasis role="strong">input</emphasis>.</para>
        <screen>$ IFS=":,"                        # use ":" and "," as IFS
$ echo IFS=$IFS,   IFS="$IFS"     # echo is a Bash builtin
IFS=  , IFS=:,
$ date -R                         # just a command output
Sat, 23 Aug 2003 08:30:15 +0200
$ echo $(date -R)                 # sub shell --&gt; input to main shell
Sat  23 Aug 2003 08 30 36 +0200
$ unset IFS                       # reset IFS to the default
$ echo $(date -R)
Sat, 23 Aug 2003 08:30:50 +0200</screen>
      </section>
      <section id="_script_snippets_for_piping_commands">
        <title>Script snippets for piping commands</title>
        <para>The following scripts do nice things as a part of a pipe.</para>
        <table pgwide="0" frame="topbot" rowsep="1" colsep="1">
          <title>List of script snippets for piping commands</title>
          <tgroup cols="2">
            <colspec colwidth="190pt" align="left"/>
            <colspec colwidth="401pt" align="left"/>
            <thead>
              <row>
                <entry> script snippet (type in one line) </entry>
                <entry> effect of command </entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry> <literal>find /usr -print</literal> </entry>
                <entry> find all files under "<literal>/usr</literal>" </entry>
              </row>
              <row>
                <entry> <literal>seq 1 100</literal> </entry>
                <entry> print 1 to 100 </entry>
              </row>
              <row>
                <entry> <literal>| xargs -n 1 <emphasis>command</emphasis></literal> </entry>
                <entry> run command repeatedly with each item from pipe as its argument </entry>
              </row>
              <row>
                <entry> <literal>| xargs -n 1 echo</literal> </entry>
                <entry> split white-space-separated items from pipe into lines </entry>
              </row>
              <row>
                <entry> <literal>| xargs echo</literal> </entry>
                <entry> merge all lines from pipe into a line </entry>
              </row>
              <row>
                <entry> <literal>| grep -e <emphasis>regex_pattern</emphasis></literal> </entry>
                <entry> extract lines from pipe containing <emphasis>regex_pattern</emphasis> </entry>
              </row>
              <row>
                <entry> <literal>| grep -v -e <emphasis>regex_pattern</emphasis></literal> </entry>
                <entry> extract lines from pipe not containing <emphasis>regex_pattern</emphasis> </entry>
              </row>
              <row>
                <entry> <literal>| cut -d: -f3 -</literal> </entry>
                <entry> extract third field from pipe separated by "<literal>:</literal>" (passwd file etc.) </entry>
              </row>
              <row>
                <entry> <literal>| awk '{ print $3 }'</literal> </entry>
                <entry> extract third field from pipe separated by whitespaces </entry>
              </row>
              <row>
                <entry> <literal>| awk -F'\t' '{ print $3 }'</literal> </entry>
                <entry> extract third field from pipe separated by tab </entry>
              </row>
              <row>
                <entry> <literal>| col -bx</literal> </entry>
                <entry> remove backspace and expand tabs to spaces </entry>
              </row>
              <row>
                <entry> <literal>| expand -</literal> </entry>
                <entry> expand tabs </entry>
              </row>
              <row>
                <entry> <literal>| sort| uniq</literal> </entry>
                <entry> sort and remove duplicates </entry>
              </row>
              <row>
                <entry> <literal>| tr 'A-Z' 'a-z'</literal> </entry>
                <entry> convert uppercase to lowercase </entry>
              </row>
              <row>
                <entry> <literal>| tr -d '\n'</literal> </entry>
                <entry> concatenate lines into one line </entry>
              </row>
              <row>
                <entry> <literal>| tr -d '\r'</literal> </entry>
                <entry> remove CR </entry>
              </row>
              <row>
                <entry> <literal>| sed 's/^/# /'</literal> </entry>
                <entry> add "<literal>#</literal>" to the start of each line </entry>
              </row>
              <row>
                <entry> <literal>| sed 's/\.ext//g'</literal> </entry>
                <entry> remove "<literal>.ext</literal>" </entry>
              </row>
              <row>
                <entry> <literal>| sed -n -e 2p</literal> </entry>
                <entry> print the second line </entry>
              </row>
              <row>
                <entry> <literal>| head -n 2 -</literal> </entry>
                <entry> print the first 2 lines </entry>
              </row>
              <row>
                <entry> <literal>| tail -n 2 -</literal> </entry>
                <entry> print the last 2 lines </entry>
              </row>
            </tbody>
          </tgroup>
        </table>
        <para>A one-line shell script can loop over many files using <literal>find</literal>(1) and <literal>xargs</literal>(1) to perform quite complicated tasks.  See <xref linkend="_idioms_for_the_selection_of_files"/> and <xref linkend="_repeating_a_command_looping_over_files"/>.</para>
        <para>When using the shell interactive mode becomes too complicated, please consider to write a shell script (see <xref linkend="_the_shell_script"/>).</para>
      </section>
    </section>
  </chapter>