/[ddp]/manuals/trunk/quick-reference/asciidoc/01_tutorial.txt
ViewVC logotype

Contents of /manuals/trunk/quick-reference/asciidoc/01_tutorial.txt

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6872 - (show annotations) (download)
Sat Aug 22 05:41:18 2009 UTC (3 years, 8 months ago) by osamu
File MIME type: text/plain
File size: 106612 byte(s)
removed future tence
1 == GNU/Linux tutorials
2
3 // vim: set sts=2 expandtab:
4
5 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.
6
7 The powerful design of http://www.debian.org[Debian] http://en.wikipedia.org/wiki/GNU[GNU]/http://en.wikipedia.org/wiki/Linux[Linux] comes from the http://en.wikipedia.org/wiki/Unix[Unix] operating system, i.e., a http://en.wikipedia.org/wiki/Multi-user[multiuser], http://en.wikipedia.org/wiki/Computer_multitasking[multitasking] operating system. You must learn to take advantage of the power of these features and similarities between Unix and GNU/Linux.
8
9 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.
10
11 "http://packages.debian.org/search?keywords=rutebook[Rute User@@@sq@@@s Tutorial and Exposition]", in the Debian non-free archive as the `rutebook` package (popcon: @-@pop-rutebook@-@), provides a good online resource to the generic system administration.
12
13 NOTE: If you have been using any http://en.wikipedia.org/wiki/Unix-like[Unix-like] system for a while with command line tools, you probably know everything I explain here. Please use this as a reality check and refresher.
14
15 === Console basics
16
17 ==== The shell prompt
18
19 Upon starting the system, you are presented with the character based login screen if you did not install http://en.wikipedia.org/wiki/X_Window_System[X Window System] with the display manager such as `gdm`. Suppose your hostname is `foo`, the login prompt looks as follows.
20
21 --------------------
22 foo login:
23 --------------------
24
25 If you did install a http://en.wikipedia.org/wiki/Graphical_user_interface[GUI] environment such as http://en.wikipedia.org/wiki/GNOME[GNOME] or http://en.wikipedia.org/wiki/KDE[KDE], then you can get to a login prompt by Ctrl-Alt-F1, and you can return to the GUI environment via Alt-F7 (see <<_virtual_consoles>> below for more).
26
27 At the login prompt, you type your username, e.g. `penguin`, and press the Enter-key, then type your password and press the Enter-key again.
28
29 NOTE: 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 `adduser`(8) by root.
30
31 The system starts with the greeting message stored in "`/etc/motd`" (Message Of The Day) and presents a command prompt.
32
33 --------------------
34 Debian GNU/Linux lenny/sid foo tty1
35 foo login: penguin
36 Password:
37 Last login: Sun Apr 22 09:29:34 2007 on tty1
38 Linux snoopy 2.6.20-1-amd64 #1 SMP Sun Apr 15 20:25:49 UTC 2007 x86_64
39
40 The programs included with the Debian GNU/Linux system are free software;
41 the exact distribution terms for each program are described in the
42 individual files in /usr/share/doc/*/copyright.
43
44 Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
45 permitted by applicable law.
46 foo:~$
47 --------------------
48
49 Here, the main part of the greeting message can be customized by editing the "`/etc/motd.tail`" file. The first line is generated from the system information using "`uname -snrvm`".
50
51 Now you are in the http://en.wikipedia.org/wiki/Shell_(computing)[shell]. The shell interprets your commands.
52
53 ==== The shell prompt under X
54
55 If you installed http://en.wikipedia.org/wiki/X_Window_System[X Window System] with a display manager such as http://en.wikipedia.org/wiki/GNOME[GNOME]@@@sq@@@s `gdm` by selecting "Desktop environment" task 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 mouse and primary click.
56
57 You can gain the shell prompt under X by starting a `x-terminal-emulator` program such as `gnome-terminal`(1), `rxvt`(1) or `xterm`(1). Under the GNOME Desktop environment, clicking "Applications" -> "Accessories" -> "Terminal" does the trick.
58
59 // Please do not link with wiki anchor generation of wiki reference using it now.
60
61 You can also see the section below <<_virtual_consoles>>.
62
63 Under some other Desktop systems (like `fluxbox`), there may be no obvious starting point for the menu. If this happens, just try (right) clicking the center of the screen and hope for a menu to pop-up.
64
65 ==== The root account
66
67 // IBM Style Lists: P164
68
69 The root account is also called http://en.wikipedia.org/wiki/Superuser[superuser] or privileged user. From this account, you can perform the following system administration tasks.
70
71 - Read, write, and remove any files on the system irrespective of their file permissions
72 - Set file ownership and permissions of any files on the system
73 - Set the password of any non-privileged users on the system
74 - Login to any accounts without their passwords
75
76 This unlimited power of root account requires you to be considerate and responsible when using it.
77
78 WARNING: Never share the root password with others.
79
80 NOTE: 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@@@sq@@@s group membership (see <<_filesystem_permissions>>).
81
82 ==== The root shell prompt
83
84 Here are a few basic methods to gain the root shell prompt by using the root password.
85
86 - Type `root` at the character based login prompt.
87 - Click "Applications" -> "Accessories" -> "Root Terminal", under the GNOME Desktop environment.
88 - Type "`su -l`" from any user shell prompt.
89 * This does not preserve the environment of the current user.
90 - Type "`su`" from any user shell prompt.
91 * This preserves some of the environment of the current user.
92
93 ==== GUI system administration tools
94
95 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 X terminal emulator, such as `gnome-terminal`(1), `rxvt`(1), or `xterm`(1). See <<_the_root_shell_prompt>> and <<_running_x_clients_as_root>>.
96
97 WARNING: Never start the X display/session manager under the root account by typing in `root` to the prompt of the display manager such as `gdm`(1).
98
99 WARNING: Never run untrusted remote GUI program under X Window when critical information is displayed since it may eavesdrop your X screen.
100
101 // There is no xwindows. Please do not use such word here.
102 // In some cases, it is necessary to run gui tools as root. The trick here is to {{{su}}} in {{{gnome-terminal}}}, {{{rxvt}}}, or {{{xterm}}} without the -l option. Then start the gui application by typing its name in the terminal that you {{{su}}}'d in. This starts the gui application as root, but preserves the environment of the user you are logged in as, so that things, like X Window functionality, don't break.
103
104 ==== Virtual consoles
105
106 In the default Debian system, there are six switchable http://en.wikipedia.org/wiki/VT100[VT100-like] 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 `Left-Alt-key` and one of the `F1` -- `F6` 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.
107
108 If you are under the X Window System, you gain access to the character console 1 by pressing `Ctrl-Alt-F1` key, i.e., the `left-Ctrl-key`, the `left-Alt-key`, and the `F1-key` are pressed together. You can get back to the X Window System, normally running on the virtual console 7, by pressing `Alt-F7`.
109
110 You can alternatively change to another virtual console, e.g. to the console 1, from the commandline.
111
112 --------------------
113 # chvt 1
114 --------------------
115
116 ==== How to leave the command prompt
117
118 You type `Ctrl-D`, i.e., the `left-Ctrl-key` and the `d-key` 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, `\^D`, is also used for `Ctrl-D`. Alternately, you can type "exit".
119
120 If you are at `x-terminal-emulator`(1), you can close `x-terminal-emulator` window with this.
121
122 ==== How to shutdown the system
123
124 Just like any other modern OS where the file operation involves http://en.wikipedia.org/wiki/Cache[caching data] 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.)
125
126 You can shutdown the system under the normal multiuser mode from the commandline.
127
128 --------------------
129 # shutdown -h now
130 --------------------
131
132 You can shutdown the system under the single-user mode from the commandline.
133
134 --------------------
135 # poweroff -i -f
136 --------------------
137
138 Alternatively, you may type `Ctrl-Alt-Delete` (The `left-Ctrl-key`, the `left-Alt-Key`, and the `Delete` are pressed together) to shutdown if "`/etc/inittab`" contains "`ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -h now`" in it. See `inittab`(5) for details.
139
140 See <<_how_to_shutdown_the_remote_system_on_ssh>>.
141
142 ==== Recovering a sane console
143
144 When the screen goes berserk after doing some funny things such as "`cat <some-binary-file>`", type "`reset`" at the command prompt. You may not be able to see the command echoed as you type. You may also issue "`clear`" to clean up the screen.
145
146 ==== Additional package suggestions for the newbie
147
148 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 `mc` and `vim` with `aptitude`(8) for beginners to get started by the following.
149
150 --------------------
151 # aptitude update
152 ...
153 # aptitude install mc vim sudo
154 ...
155 --------------------
156
157 // Please do not add your favorite editor or any other software here without discussing debian-doc@lists.debian.org
158
159 If you already had these packages installed, no new packages are installed.
160
161 .List of interesting text-mode program packages
162 [grid="all"]
163 `----------`-------------`------------`--------------------------------------------------------------------------
164 package popcon size description
165 -----------------------------------------------------------------------------------------------------------------
166 `mc` @-@popcon1@-@ @-@psize1@-@ A text-mode full-screen file manager
167 `sudo` @-@popcon1@-@ @-@psize1@-@ A program to allow limited root privileges to users
168 `vim` @-@popcon1@-@ @-@psize1@-@ Unix text editor Vi IMproved, a programmers text editor (standard version)
169 `vim-tiny` @-@popcon1@-@ @-@psize1@-@ Unix text editor Vi IMproved, a programmers text editor (compact version)
170 `emacs22` @-@popcon1@-@ @-@psize1@-@ GNU project Emacs, the Lisp based extensible text editor (version 22)
171 `emacs23` @-@popcon1@-@ @-@psize1@-@ GNU project Emacs, the Lisp based extensible text editor (version 23)
172 `w3m` @-@popcon1@-@ @-@psize1@-@ Text-mode WWW browsers
173 `gpm` @-@popcon1@-@ @-@psize1@-@ The Unix style cut-and-paste on the text console (daemon)
174 -----------------------------------------------------------------------------------------------------------------
175
176 It may be a good idea to read some informative documentations.
177
178 .List of informative documentation packages
179 [grid="all"]
180 `----------------------`-------------`------------`--------------------------------------------------------------
181 package popcon size description
182 -----------------------------------------------------------------------------------------------------------------
183 `doc-debian` @-@popcon1@-@ @-@psize1@-@ Debian Project documentation, (Debian FAQ) and other documents
184 `debian-policy` @-@popcon1@-@ @-@psize1@-@ Debian Policy Manual and related documents
185 `developers-reference` @-@popcon1@-@ @-@psize1@-@ Guidelines and information for Debian developers
186 `maint-guide` @-@popcon1@-@ @-@psize1@-@ Debian New Maintainers\' Guide
187 `debian-history` @-@popcon1@-@ @-@psize1@-@ History of the Debian Project
188 `debian-faq` @-@popcon1@-@ @-@psize1@-@ Debian FAQ
189 `doc-linux-text` @-@popcon1@-@ @-@psize1@-@ Linux HOWTOs and FAQ (text)
190 `doc-linux-html` @-@popcon1@-@ @-@psize1@-@ Linux HOWTOs and FAQ (html)
191 `sysadmin-guide` @-@popcon1@-@ @-@psize1@-@ The Linux System Administrators\' Guide
192 `rutebook` @-@popcon1@-@ @-@psize1@-@ Linux: Rute User@@@sq@@@s Tutorial and Exposition (non-free)
193 -----------------------------------------------------------------------------------------------------------------
194
195 You can install some of these packages by the following.
196
197 --------------------
198 # aptitude install package_name
199 --------------------
200
201 ==== An extra user account
202
203 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. `fish` by the following.
204
205 --------------------
206 # adduser fish
207 --------------------
208
209 Answer all questions.
210
211 This creates a new account named as `fish`. After your practice, you can remove this user account and its home directory by the following.
212
213 --------------------
214 # deluser --remove-home fish
215 --------------------
216
217 ==== sudo configuration
218
219 For the typical single user workstation such as the desktop Debian system on the laptop PC, it is common to deploy simple configuration of `sudo`(8) as follows to let the non-privileged user, e.g. `penguin`, to gain administrative privilege just with his user password but without the root password.
220
221 --------------------
222 # echo "penguin ALL=(ALL) ALL" >> /etc/sudoers
223 --------------------
224
225 This trick should only be used for the single user workstation which you administer and where you are the only user.
226
227 WARNING: Do not set up accounts of regular users on multiuser workstation like this because it would be very bad for system security.
228
229 CAUTION: The password and the account of the `penguin` in the above example requires as much protection as the root password and the root account.
230
231 // The following is less abrasive than one proposed.
232 CAUTION: 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.
233
234 NOTE: For providing access privilege to limited devices and limited files, you should consider to use **group** to provide limited access instead of using the `root` privilege via `sudo`(8).
235
236 NOTE: With more thoughtful and careful configuration, `sudo`(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.
237
238 ==== Play time
239
240 Now you are ready to play with the Debian system without risks as long as you use the non-privileged user account.
241
242 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 http://www.debian.org/doc/manuals/securing-debian-howto/[Securing Debian Manual].
243
244 // titles are noun phrases
245 We learn the Debian system as a http://en.wikipedia.org/wiki/Unix-like[Unix-like] system with the following.
246
247 - <<_unix_like_filesystem>> (basic concept)
248 - <<_midnight_commander_mc>> (survival method)
249 - <<_the_basic_unix_like_work_environment>> (basic method)
250 - <<_the_simple_shell_command>> (shell mechanism)
251 - <<_unix_like_text_processing>> (text processing method)
252
253 === Unix-like filesystem
254
255 In GNU/Linux and other http://en.wikipedia.org/wiki/Unix-like[Unix-like] operating systems, http://en.wikipedia.org/wiki/Computer_file[files] are organized into http://en.wikipedia.org/wiki/Directory_(file_systems)[directories]. All files and directories are arranged in one big tree rooted at "`/`". It@@@sq@@@s called a tree because if you draw the filesystem, it looks like a tree but it is upside down.
256
257 These files and directories can be spread out over several devices. `mount`(8) serves to attach the filesystem found on some device to the big file tree. Conversely, `umount`(8) detaches it again. On recent Linux kernels, `mount`(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 "`/share/doc/linux-doc-2.6.\*/Documentation/filesystems/`".
258
259 **Directories** on Unix systems are called **folders** on some other systems. Please also note that there is no concept for **drive** such as "`A:`" on any Unix system. There is one filesystem, and everything is included. This is a huge advantage compared to Windows.
260
261 ==== Unix file basics
262
263 Here are some Unix file basics.
264
265 - Filenames are **case sensitive**. That is, "`MYFILE`" and "`MyFile`" are different files.
266 - The **root directory** means root of the filesystem referred as simply "`/`". Don\'t confuse this with the home directory for the root user: "`/root`".
267 - Every directory has a name which can contain any letters or symbols **except "`/`"**. The root directory is an exception; its name is "`/`" (pronounced "slash" or "the root directory") and it cannot be renamed.
268 - Each file or directory is designated by a **fully-qualified filename**, **absolute filename**, or **path**, giving the sequence of directories which must be passed through to reach it. The three terms are synonymous.
269 - All **fully-qualified filenames** begin with the "`/`" directory, and there@@@sq@@@s a "`/`" between each directory or file in the filename. The first "`/`" is the top level directory, and the other "`/`"@@@sq@@@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 **fully-qualified filename** as an example: "`/usr/share/keytables/us.map.gz`". However, people also refers to its basename "`us.map.gz`" alone as a filename.
270 - The root directory has a number of branches, such as "`/etc/`" and "`/usr/`". These subdirectories in turn branch into still more subdirectories, such as "`/etc/init.d/`" and "`/usr/local/`". The whole thing viewed collectively is called the **directory tree**. You can think of an absolute filename as a route from the base of the tree ("`/`") to the end of some branch (a file). You also hear people talk about the directory tree as if it were a **family** tree: thus subdirectories have **parents**, 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 "`../`" refers to the parent directory. This terminology also applies to other directory like structures, such as hierarchical data structures.
271 - There@@@sq@@@s no special directory path name component that corresponds to a physical device, such as your hard disk. This differs from http://en.wikipedia.org/wiki/RT-11[RT-11], http://en.wikipedia.org/wiki/CP/M[CP/M], http://en.wikipedia.org/wiki/OpenVMS[OpenVMS], http://en.wikipedia.org/wiki/MS-DOS[MS-DOS], http://en.wikipedia.org/wiki/AmigaOS[AmigaOS], and http://en.wikipedia.org/wiki/Microsoft_Windows[Microsoft Windows], where the path contains a device name such as "`C:\`". (However, directory entries do exist that refer to physical devices as a part of the normal filesystem. See <<_filesystem_internals>>.)
272
273 NOTE: While you **can** 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: `{ } ( ) [ ] @@@sq@@@ @@@grave@@@ @@@dq@@@ \ @@@slash@@@ > < | ; ! # @@@amp@@@ @@@hat@@@ @@@star@@@ % @ $` . If you want to separate words in a name, good choices are the period, hyphen, and underscore. You could also capitalize each word, "`LikeThis`". Experienced Linux users tend to avoid spaces in filenames.
274
275 NOTE: The word "root" can mean either "root user" or "root directory". The context of their usage should make it clear.
276
277 NOTE: The word **path** is used not only for **fully-qualified filename** as above but also for the **command search path**. The intended meaning is usually clear from the context.
278
279 The detailed best practices for the file hierarchy are described in the Filesystem Hierarchy Standard ("`/usr/share/doc/debian-policy/fhs/fhs-2.3.txt.gz`" and `hier`(7)). You should remember the following facts as the starter.
280
281 .List of usage of key directories
282 [grid="all"]
283 `-----------`-------------------------------------------------------------------------------------------
284 directory usage of the directory
285 --------------------------------------------------------------------------------------------------------
286 `/` the root directory
287 `/etc/` system wide configuration files
288 `/var/log/` system log files
289 `/home/` all the home directories for all non-privileged users
290 --------------------------------------------------------------------------------------------------------
291
292 ==== Filesystem internals
293
294 Following the **Unix tradition**, the Debian GNU/Linux system provides the http://en.wikipedia.org/wiki/File_system[filesystem] 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 "`/dev/`".
295
296 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 http://en.wikipedia.org/wiki/Inode[inode] which describes its associated attributes such as the user who owns it (owner), the group that it belongs to, the time last accessed, etc. If you are really interested, see "`/usr/include/linux/fs.h`" for the exact definition of "`struct inode`" in the Debian GNU/Linux system. 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.
297
298 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.
299
300 // I am commenting out since redundant and long, no advocacy please.
301 // Please do not deviates from focus topic. Just keep this as technical information!!!
302 // I start this section as '''Unix tradition''' : /!\ Reread that last sentence. This is the essence of an incredible amount of flexibility, power, and utility that is at the heart of Unix/Linux based systems. This type of power is not easily tapped from the Graphical User Interface, and this is why if you administer, program, or use Unix/Linux based systems, it really calls for you to learn the power of the command line and why you benefit from knowing how your system works. -- But most of tweaking requires C programing though to get really into details.
303
304 // All of your files could be on one disk --- or you could have 20 disks, some of them connected to a different computer elsewhere on the network. You can't tell just by looking at the directory tree, and nearly all commands work just the same way no matter what physical device(s) your files are really on. [This is a good thing. Trust us.] Of course, methods do exist whereby you can tell what devices map to which physical or network devices. {{{mount}}} with no arguments shows how storage is mapped to physical or network devices.
305
306 TIP: If you need to identify the correspondence between the file tree and the physical entity, execute `mount`(8) with no arguments.
307
308 ==== Filesystem permissions
309
310 http://en.wikipedia.org/wiki/File_system_permissions[Filesystem permissions] of http://en.wikipedia.org/wiki/Unix-like[Unix-like] system are defined for three categories of affected users.
311
312 - The **user** who owns the file (**u**)
313 - Other users in the **group** which the file belongs to (**g**)
314 - All **other** users (**o**) also referred to as "world" and "everyone"
315
316 For the file, each corresponding permission allows following actions.
317
318 - The **read** (**r**) permission allows owner to examine contents of the file.
319 - The **write** (**w**) permission allows owner to modify the file.
320 - The **execute** (**x**) permission allows owner to run the file as a command.
321
322 For the directory, each corresponding permission allows following actions.
323
324 - The **read** (**r**) permission allows owner to list contents of the directory.
325 - The **write** (**w**) permission allows owner to add or remove files in the directory.
326 - The **execute** (**x**) permission allows owner to access files in the directory.
327
328 Here, the **execute** 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.
329
330 `ls`(1) is used to display permission information (and more) for files and directories. When it is invoked with the "`-l`" option, it displays the following information in the order given.
331
332 - **Type of file** (first character)
333 - Access **permission** of the file (nine characters, consisting of three characters each for user, group, and other in this order)
334 - **Number of hard links** to the file
335 - Name of the **user** who owns the file
336 - Name of the **group** which the file belongs to
337 - **Size** of the file in characters (bytes)
338 - **Date and time** of the file (mtime)
339 - **Name** of the file
340
341 .List of the first character of "`ls -l`" output
342 [grid="all"]
343 `---------`---------------------
344 character meaning
345 --------------------------------
346 `-` normal file
347 `d` directory
348 `l` symlink
349 `c` character device node
350 `b` block device node
351 `p` named pipe
352 `s` socket
353 --------------------------------
354
355 `chown`(1) is used from the root account to change the owner of the file. `chgrp`(1) is used from the file@@@sq@@@s owner or root account to change the group of the file. `chmod`(1) is used from the file@@@sq@@@s owner or root account to change file and directory access permissions. Basic syntax to manipulate a `foo` file is the following.
356
357 --------------------
358 # chown <newowner> foo
359 # chgrp <newgroup> foo
360 # chmod [ugoa][+-=][rwxXst][,...] foo
361 --------------------
362
363 For example, you can make a directory tree to be owned by a user `foo` and shared by a group `bar` by the following.
364
365 --------------------
366 # cd /some/location/
367 # chown -R foo:bar .
368 # chmod -R ug+rwX,o=rX .
369 --------------------
370
371 There are three more special permission bits.
372
373 - The **set user ID** bit (**s** or **S** instead of user@@@sq@@@s **x**)
374 - The **set group ID** bit (**s** or **S** instead of group@@@sq@@@s **x**)
375 - The **sticky** bit (**t** or **T** instead of other@@@sq@@@s **x**)
376
377 Here the output of "`ls -l`" for these bits is **capitalized** if execution bits hidden by these outputs are **unset**.
378
379 Setting **set user ID** on an executable file allows a user to execute the executable file with the owner ID of the file (for example **root**). Similarly, setting **set group ID** on an executable file allows a user to execute the executable file with the group ID of the file (for example **root**). Because these settings can cause security risks, enabling them requires extra caution.
380
381 Setting **set group ID** on a directory enables the http://en.wikipedia.org/wiki/Berkeley_Software_Distribution[BSD-like] file creation scheme where all files created in the directory belong to the **group** of the directory.
382
383 Setting the **sticky bit** 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 "`/tmp`" or in group-writable directories, one must not only reset the **write** permission for the file but also set the **sticky bit** 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.
384
385 Here are a few interesting examples of file permissions.
386
387 --------------------
388 $ ls -l /etc/passwd /etc/shadow /dev/ppp /usr/sbin/exim4
389 crw------- 1 root root 108, 0 2007-04-29 07:00 /dev/ppp
390 -rw-r--r-- 1 root root 1427 2007-04-16 00:19 /etc/passwd
391 -rw-r----- 1 root shadow 943 2007-04-16 00:19 /etc/shadow
392 -rwsr-xr-x 1 root root 700056 2007-04-22 05:29 /usr/sbin/exim4
393 $ ls -ld /tmp /var/tmp /usr/local /var/mail /usr/src
394 drwxrwxrwt 10 root root 4096 2007-04-29 07:59 /tmp
395 drwxrwsr-x 10 root staff 4096 2007-03-24 18:48 /usr/local
396 drwxrwsr-x 4 root src 4096 2007-04-27 00:31 /usr/src
397 drwxrwsr-x 2 root mail 4096 2007-03-28 23:33 /var/mail
398 drwxrwxrwt 2 root root 4096 2007-04-29 07:11 /var/tmp
399 --------------------
400
401 There is an alternative numeric mode to describe file permissions with `chmod`(1). This numeric mode uses 3 to 4 digit wide octal (radix=8) numbers.
402
403 .The numeric mode for file permissions in `chmod`(1) commands
404 [grid="all"]
405 `------------------`-----------------------------------------------------------------------------------
406 digit meaning
407 -------------------------------------------------------------------------------------------------------
408 1st optional digit sum of **set user ID** (=4), **set group ID** (=2), and **sticky bit** (=1)
409 2nd digit sum of **read** (=4), **write** (=2), and **execute** (=1) permissions for **user**
410 3rd digit ditto for **group**
411 4th digit ditto for **other**
412 -------------------------------------------------------------------------------------------------------
413
414 This sounds complicated but it is actually quite simple. If you look at the first few (2-10) columns from "`ls -l`" 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.
415
416 For example, try the following
417
418 --------------------
419 $ touch foo bar
420 $ chmod u=rw,go=r foo
421 $ chmod 644 bar
422 $ ls -l foo bar
423 -rw-r--r-- 1 penguin penguin 17 2007-04-29 08:22 bar
424 -rw-r--r-- 1 penguin penguin 12 2007-04-29 08:22 foo
425 --------------------
426
427 TIP: If you need to access information displayed by "`ls -l`" in shell script, you should use pertinent commands such as `test`(1), `stat`(1) and `readlink`(1). The shell builtin such as "`[`" or "`test`" may be used too.
428
429 ==== Control of permissions for newly created files: umask
430
431 What permissions are applied to a newly created file or directory is restricted by the `umask` shell builtin command. See `dash`(1), `bash`(1), and `builtins`(7).
432
433 --------------------
434 (file permissions) = (requested file permissions) & ~(umask value)
435 --------------------
436
437 .The **umask** value examples
438 [grid="all"]
439 `------`------------------------`-----------------------------`-------------------------
440 umask file permissions created directory permissions created usage
441 ----------------------------------------------------------------------------------------
442 `0022` `-rw-r--r--` `-rwxr-xr-x` writable only by the user
443 `0002` `-rw-rw-r--` `-rwxrwxr-x` writable by the group
444 ----------------------------------------------------------------------------------------
445
446 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 is safe to set umask to `0002` 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 **`users`** group and is good idea to set umask to `0022` for security in such cases.)
447
448 ==== Permissions for groups of users (group)
449
450 In order to make group permissions to be applied to a particular user, that user needs to be made a member of the group using "`sudo vigr`".
451
452 NOTE: Alternatively, you may dynamically add users to groups during the authentication process by adding "`auth optional pam_group.so`" line to "`/etc/pam.d/common-auth`" and setting "`/etc/security/group.conf`". (See <<_authentication>>.)
453
454 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.
455
456 Some notable system-provided groups allow their members to access particular files and devices without `root` privilege.
457
458 .List of notable system-provided groups for file access
459 [grid="all"]
460 `---------`-----------------------------------------------------------------------------
461 group description for accessible files and devices
462 ----------------------------------------------------------------------------------------
463 `dialout` full and direct access to serial ports ("`/dev/ttyS[0-3]`")
464 `dip` limited access to serial ports for **Dialup IP** connection to trusted peers
465 `cdrom` CD-ROM, DVD+/-RW drives
466 `audio` audio device
467 `video` video device
468 `scanner` scanner(s)
469 `adm` system monitoring logs
470 `staff` some directories for junior administrative work: "`/usr/local`", "`/home`"
471 ----------------------------------------------------------------------------------------
472
473 TIP: You need to belong to the `dialout` group to reconfigure modem, dial anywhere, etc. But if `root` creates pre-defined configuration files for trusted peers in "`/etc/ppp/peers/`", you only need to belong to the `dip` group to create **Dialup IP** connection to those trusted peers using `pppd`(8), `pon`(1), and `poff`(1) commands.
474
475 Some notable system-provided groups allow their members to execute particular commands without `root` privilege.
476
477 .List of notable system provided groups for particular command executions
478 [grid="all"]
479 `---------`----------------------------------------------------------------------------
480 group accessible commands
481 ---------------------------------------------------------------------------------------
482 `sudo` execute `sudo` without their password
483 `lpadmin` execute commands to add, modify, and remove printers from printer databases
484 `plugdev` execute `pmount`(1) for removable devices such as USB memories
485 ---------------------------------------------------------------------------------------
486
487 For the full listing of the system provided users and groups, see the recent version of the "Users and Groups" document in "`/usr/share/doc/base-passwd/users-and-groups.html`" provided by the `base-passwd` package.
488
489 See `passwd`(5), `group`(5), `shadow`(5), `newgrp`(1), `vipw`(8), `vigr`(8), and `pam_group`(8) for management commands of the user and group system.
490
491 ==== Timestamps
492
493 There are three types of timestamps for a GNU/Linux file.
494
495 .List of types of timestamps
496 [grid="all"]
497 `---------`--------------------------------------
498 type meaning
499 -------------------------------------------------
500 **mtime** the file modification time (`ls -l`)
501 **ctime** the file status change time (`ls -lc`)
502 **atime** the last file access time (`ls -lu`)
503 -------------------------------------------------
504
505 NOTE: **ctime** is not file creation time.
506
507 - Overwriting a file changes all of the **mtime**, **ctime**, and **atime** attributes of the file.
508 - Changing ownership or permission of a file changes the **ctime** and **atime** attributes of the file.
509 - Reading a file changes the **atime** of the file.
510
511 NOTE: Even simply reading a file on the Debian system normally causes a file write operation to update **atime** information in the **inode**. Mounting a filesystem with "`noatime`" or "`relatime`" option makes the system skip this operation and results in faster file access for the read. This is often recommended for laptops, because it reduces hard drive activity and saves power. See `mount`(8).
512
513 Use `touch`(1) command to change timestamps of existing files.
514
515 For timestamps, the `ls` command outputs different strings under the modern English locale ("`en_US.UTF-8`") from under the old one ("`C`").
516
517 --------------------
518 $ LANG=en_US.UTF-8 ls -l foo
519 -rw-r--r-- 1 penguin penguin 3 2008-03-05 00:47 foo
520 $ LANG=C ls -l foo
521 -rw-r--r-- 1 penguin penguin 3 Mar 5 00:47 foo
522 --------------------
523
524 TIP: See <<_customized_display_of_time_and_date>> to customize "`ls -l`" output.
525
526 ==== Links
527
528 There are two methods of associating a file "`foo`" with a different filename "`bar`".
529
530 - http://en.wikipedia.org/wiki/Hard_link[Hard link]
531 * Duplicate name for an existing file
532 * "`ln foo bar`"
533 - http://en.wikipedia.org/wiki/Symbolic_link[Symbolic link or symlink]
534 * Special file that points to another file by name
535 * "`ln -s foo bar`"
536
537 See the following example for changes in link counts and the subtle differences in the result of the `rm` command.
538
539 --------------------
540 $ echo "Original Content" > foo
541 $ ls -li foo
542 2398521 -rw-r--r-- 1 penguin penguin 17 2007-04-29 08:15 foo
543 $ ln foo bar # hard link
544 $ ln -s foo baz # symlink
545 $ ls -li foo bar baz
546 2398521 -rw-r--r-- 2 penguin penguin 17 2007-04-29 08:15 bar
547 2398538 lrwxrwxrwx 1 penguin penguin 3 2007-04-29 08:16 baz -> foo
548 2398521 -rw-r--r-- 2 penguin penguin 17 2007-04-29 08:15 foo
549 $ rm foo
550 $ echo "New Content" > foo
551 $ ls -li foo bar baz
552 2398521 -rw-r--r-- 1 penguin penguin 17 2007-04-29 08:15 bar
553 2398538 lrwxrwxrwx 1 penguin penguin 3 2007-04-29 08:16 baz -> foo
554 2398540 -rw-r--r-- 1 penguin penguin 12 2007-04-29 08:17 foo
555 $ cat bar
556 Original Content
557 $ cat baz
558 New Content
559 --------------------
560
561 The hardlink can be made within the same filesystem and shares the same inode number which the "`-i`" option with `ls`(1) reveals.
562
563 The symlink always has nominal file access permissions of "`rwxrwxrwx`", as shown in the above example, with the effective access permissions dictated by permissions of the file that it points to.
564
565 // The trick below is not something I recommend. Administration record is another topic and basic common sense.
566 // /!\ It is important to remain cognizant of the overall structure of the filesystem, and to keep track of symbolic links [a text file named symlinks.txt in the home directory of the root user would be a REALLY good idea.]. The reason for this is that it is relatively easy to create symlink nightmares where the logical combination of the symbolic links results in loops in the filesystem [very bad] that can result in errors and behavior that are difficult to identify and isolate.
567
568 // "/!\" should be used as "Don't".
569 CAUTION: It is generally 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.
570
571 NOTE: It is generally preferable to use symbolic links rather than hardlinks unless you have a good reason for using a hardlink.
572
573 The "`.`" directory links to the directory that it appears in, thus the link count of any new directory starts at 2. The "`..`" directory links to the parent directory, thus the link count of the directory increases with the addition of new subdirectories.
574
575 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.
576
577 ==== Named pipes (FIFOs)
578
579 A http://en.wikipedia.org/wiki/Named_pipe[named pipe] is a file that acts like a pipe. You put something into the file, and it comes out the other end. Thus it@@@sq@@@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.
580
581 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 shell "`|`". 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.
582
583 For example, try the following
584
585 --------------------
586 $ cd; mkfifo mypipe
587 $ echo "hello" >mypipe & # put into background
588 [1] 8022
589 $ ls -l mypipe
590 prw-r--r-- 1 penguin penguin 0 2007-04-29 08:25 mypipe
591 $ cat mypipe
592 hello
593 [1]+ Done echo "hello" >mypipe
594 $ ls mypipe
595 mypipe
596 $ rm mypipe
597 --------------------
598
599 ==== Sockets
600
601 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 http://en.wikipedia.org/wiki/Inter-process_communication[the inter process communication (IPC)]. The exchange of information may occur over the network between different hosts. The two most common ones are http://en.wikipedia.org/wiki/Internet_socket[the Internet socket] and http://en.wikipedia.org/wiki/Unix_domain_socket[the Unix domain socket].
602
603 TIP: "`netstat -an`" provides a very useful overview of sockets that are open on a given system.
604
605 ==== Device files
606
607 http://en.wikipedia.org/wiki/Device_file[Device files] 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 "`/dev/console`".
608
609 There are 2 types of device files.
610
611 - **Character device**
612 * Accessed one character at a time
613 * 1 character = 1 byte
614 * E.g. keyboard device, serial port, ...
615 - **Block device**
616 * accessed in larger units called blocks
617 * 1 block > 1 byte
618 * E.g. hard disk, ...
619
620 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 "`/dev/lp0`" or send modem commands to the appropriate serial port "`/dev/ttyS0`". But, unless this is done carefully, it may cause a major disaster. So be cautious.
621
622 NOTE: For the normal access to a printer, use `lp`(1).
623
624 The device node number are displayed by executing `ls`(1) as the following.
625
626 --------------------
627 $ ls -l /dev/hda /dev/ttyS0 /dev/zero
628 brw-rw---- 1 root cdrom 3, 0 2007-04-29 07:00 /dev/hda
629 crw-rw---- 1 root dialout 4, 64 2007-04-29 07:00 /dev/ttyS0
630 crw-rw-rw- 1 root root 1, 5 2007-04-29 07:00 /dev/zero
631 --------------------
632
633 - "`/dev/hda`" has the major device number 3 and the minor device number 0. This is read/write accessible by the user who belongs to `disk` group.
634 - "`/dev/ttyS0`" has the major device number 4 and the minor device number 64. This is read/write accessible by the user who belongs to `dialout` group.
635 - "`/dev/zero`" has the major device number 1 and the minor device number 5. This is read/write accessible by anyone.
636
637 In the Linux 2.6 system, the filesystem under "`/dev/`" is automatically populated by the `udev`(7) mechanism.
638
639 ==== Special device files
640
641 There are some special device files.
642
643 .List of special device files
644 [grid="all"]
645 `--------------`------`-------------------------------------------------------------------------------------------------
646 device file action description of response
647 ------------------------------------------------------------------------------------------------------------------------
648 `/dev/null` read return "end-of-file (EOF) character"
649 `/dev/null` write return nothing (a bottomless data dump pit)
650 `/dev/zero` read return "the `\0` (NUL) character" (not the same as the number zero ASCII)
651 `/dev/random` read return random characters from a true random number generator, delivering real entropy (slow)
652 `/dev/urandom` read return random characters from a cryptographically secure pseudorandom number generator
653 `/dev/full` write return the disk-full (ENOSPC) error
654 ------------------------------------------------------------------------------------------------------------------------
655
656 These are frequently used in conjunction with the shell redirection (see <<_typical_command_sequences_and_shell_redirection>>).
657
658 // Let's not talk usage and script issues here. Then syslog needs to be mentioned too. KISS.
659
660 ==== procfs and sysfs
661
662 The http://en.wikipedia.org/wiki/Procfs[procfs] and http://en.wikipedia.org/wiki/Sysfs[sysfs] mounted on "`/proc`" and "`/sys`" 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.
663
664 The directory "`/proc`" 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 `ps`(1), get their information from this directory structure.
665
666 The directories under "`/proc/sys/`" contain interface to change certain kernel parameters at run time. (You may do the same through specialized `sysctl`(8) command or its preload/configuration file "`/etc/sysctrl.conf`".)
667
668 NOTE: The Linux kernel may complain "Too many open files". You can fix this by increasing "`file-max`" value to a larger value from the root shell, e.g., "`echo "65536" > /proc/sys/fs/file-max`" (This was needed on older kernels).
669
670 People frequently panic when they notice one file in particular - "`/proc/kcore`" - which is generally huge. This is (more or less) a copy of the content of your computer@@@sq@@@s memory. It@@@sq@@@s used to debug the kernel. It is a virtual file that points to computer memory, so don\'t worry about its size.
671
672 // No repeated advocacy please. /!\ Everything in Unix/Linux is a file, or is abstracted to a file. This is one of the essential concepts to the understanding of Unix/Linux. Knowledge is power.
673
674 The directory under "`/sys`" contains exported kernel data structures, their attributes, and their linkages between them. It also contains interface to change certain kernel parameters at run time.
675
676 See "`proc.txt(.gz)`", "`sysfs.txt(.gz)`" and other related documents in the Linux kernel documentation ("`/usr/share/doc/linux-doc-2.6.\*/Documentation/filesystems/\*`") provided by the `linux-doc-2.6.\*` package.
677
678 === Midnight Commander (MC)
679
680 http://en.wikipedia.org/wiki/Midnight_Commander[Midnight Commander (MC)] 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.
681
682 You may need to install the Midnight Commander package which is titled "`mc`" by the following.
683
684 ----
685 $ sudo aptitude install mc
686 ----
687
688 Use the `mc`(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.
689
690 - "`/etc`" and its subdirectories
691 - "`/var/log`" and its subdirectories
692 - "`/usr/share/doc`" and its subdirectories
693 - "`/sbin`" and "`/bin`"
694
695 ==== Customization of MC
696
697 In order to make MC to change working directory upon exit and `cd` to the directory, I suggest to modify "`\~/.bashrc`" to include a script provided by the `mc` package.
698
699 ----
700 . /usr/share/mc/bin/mc.sh
701 ----
702
703 See `mc`(1) (under the "`-P`" option) for the reason. (If you do not understand what exactly I am talking here, you can do this later.)
704
705 ==== Starting MC
706
707 MC can be started by the following.
708
709 --------------------
710 $ mc
711 --------------------
712
713 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.
714
715 NOTE: In some consoles such as `gnome-terminal`(1), key strokes of function-keys may be stolen by the console program. You can disable these features by "Edit" -> "Keyboard Shortcuts" for `gnome-terminal`.
716
717 If you encounter character encoding problem which displays garbage characters, adding "`-a`" to MC@@@sq@@@s command line may help prevent problems.
718
719 If this doesn\'t clear up your display problems with MC, see <<_the_terminal_configuration>>.
720
721 ==== File manager in MC
722
723 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 `gpm`(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.)
724
725 .The key bindings of MC
726 [grid="all"]
727 `--------------------`-----------------------------------------------------
728 key key binding
729 ---------------------------------------------------------------------------
730 `F1` help menu
731 `F3` internal file viewer
732 `F4` internal editor
733 `F9` activate pull down menu
734 `F10` exit Midnight Commander
735 `Tab` move between two windows
736 `Insert` or `Ctrl-T` mark file for a multiple-file operation such as copy
737 `Del` delete file (be careful---set MC to safe delete mode)
738 Cursor keys self-explanatory
739 ---------------------------------------------------------------------------
740
741 ==== Command-line tricks in MC
742
743 - `cd` command changes the directory shown on the selected screen.
744 - `Ctrl-Enter` or `Alt-Enter` copies a filename to the command line. Use this with `cp`(1) and `mv`(1) commands together with command-line editing.
745 - `Alt-Tab` shows shell filename expansion choices.
746 - One can specify the starting directory for both windows as arguments to MC; for example, "`mc /etc /root`".
747 - `Esc` \+ `n-key` -> `Fn` (i.e., `Esc` \+ `1` -> `F1`, etc.; `Esc` \+ `0` -> `F10`)
748 - Pressing `Esc` before the key has the same effect as pressing the `Alt` and the key together.; i.e., type `Esc` \+ `c` for `Alt-C`. `Esc` is called meta-key and sometimes noted as "`M-`".
749
750 ==== The internal editor in MC
751
752 The internal editor has an interesting cut-and-paste scheme. Pressing `F3` marks the start of a selection, a second `F3` 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. `F2` saves the file. `F10` gets you out. Most cursor keys work intuitively.
753
754 This editor can be directly started on a file using one of the following commands.
755
756 --------------------
757 $ mc -e filename_to_edit
758 --------------------
759
760 --------------------
761 $ mcedit filename_to_edit
762 --------------------
763
764 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<n> 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.
765
766 This internal editor can be replaced with any external editor of choice.
767
768 Also, many programs use the environment variables "`$EDITOR`" or "`$VISUAL`" to decide which editor to use. If you are uncomfortable with `vim`(1) or `nano`(1) initially, you may set these to "`mcedit`" by adding the following lines to "`\~/.bashrc`".
769
770 --------------------
771 export EDITOR=mcedit
772 export VISUAL=mcedit
773 --------------------
774
775 I do recommend setting these to "`vim`" if possible.
776
777 If you are uncomfortable with `vim`(1), you can keep using `mcedit`(1) for most system maintenance tasks.
778
779 // Since mcedit is UTF-8 capable soon, I removed following (2008-March):
780 //Since {{{mcedit}}} is 8-bit clean and dumb (it does not care about the text encoding), it sometimes has advantages when editing unknown encoding files. {{{mcedit}}} cannot display [http://en.wikipedia.org/wiki/UTF-8 UTF-8] files with Asian characters correctly. (At least it was so, as of 2007, lenny/testing.)
781
782 ==== The internal viewer in MC
783
784 MC is a very smart viewer. This is a great tool for searching words in documents. I always use this for files in the "`/usr/share/doc`" 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.
785
786 --------------------
787 $ mc -v path/to/filename_to_view
788 --------------------
789
790 --------------------
791 $ mcview path/to/filename_to_view
792 --------------------
793
794 ==== Auto-start features of MC
795
796 Press Enter on a file, and the appropriate program handles the content of the file (see <<_customizing_program_to_be_started>>). This is a very convenient MC feature.
797
798 .The reaction to the enter key in MC
799 [grid="all"]
800 `---------------------------------`--------------------------------------
801 file type reaction to enter key
802 -------------------------------------------------------------------------
803 executable file execute command
804 man file pipe content to viewer software
805 html file pipe content to web browser
806 "`\*.tar.gz`" and "`\*.deb`" file browse its contents as if subdirectory
807 -------------------------------------------------------------------------
808
809 In order to allow these viewer and virtual file features to function, viewable files should not be set as executable. Change their status using `chmod`(1) or via the MC file menu.
810
811 ==== FTP virtual filesystem of MC
812
813 MC can be used to access files over the Internet using FTP. Go to the menu by pressing `F9`, then type "`p`" to activate the FTP virtual filesystem. Enter a URL in the form "`username:passwd@hostname.domainname`", which retrieves a remote directory that appears like a local one.
814
815 Try "[http.us.debian.org/debian]" as the URL and browse the Debian archive.
816
817 === The basic Unix-like work environment
818
819 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.
820
821 ==== The login shell
822
823 You can select your login shell with `chsh`(1).
824
825 [[list-of-shell-programs]]
826 .List of shell programs
827 [grid="all"]
828 `-------`-------------`------------`-----------`------------------------------------------------------------------------------------------
829 package popcon size POSIX shell description
830 ------------------------------------------------------------------------------------------------------------------------------------------
831 `bash` @-@popcon1@-@ @-@psize1@-@ Yes http://en.wikipedia.org/wiki/Bash[Bash]: the GNU Bourne Again SHell (de facto standard)
832 `tcsh` @-@popcon1@-@ @-@psize1@-@ No http://en.wikipedia.org/wiki/Tcsh[TENEX C Shell]: an enhanced version of http://en.wikipedia.org/wiki/C_shell[Berkeley csh]
833 `dash` @-@popcon1@-@ @-@psize1@-@ Yes Debian http://en.wikipedia.org/wiki/Almquist_shell[Almquist Shell], good for shell script
834 `zsh` @-@popcon1@-@ @-@psize1@-@ Yes http://en.wikipedia.org/wiki/Z_shell[Z shell]: the standard shell with many enhancements
835 `pdksh` @-@popcon1@-@ @-@psize1@-@ Yes public domain version of the http://en.wikipedia.org/wiki/Korn_shell[Korn shell]
836 `csh` @-@popcon1@-@ @-@psize1@-@ No http://en.wikipedia.org/wiki/OpenBSD[OpenBSD] C Shell, a version of http://en.wikipedia.org/wiki/C_shell[Berkeley csh]
837 `sash` @-@popcon1@-@ @-@psize1@-@ Yes http://en.wikipedia.org/wiki/Stand-alone_shell[Stand-alone shell] with builtin commands (Not meant for standard "`/bin/sh`")
838 `ksh` @-@popcon1@-@ @-@psize1@-@ Yes the real, AT&T version of the http://en.wikipedia.org/wiki/Korn_shell[Korn shell]
839 `rc` @-@popcon1@-@ @-@psize1@-@ No implementation of the http://en.wikipedia.org/wiki/Plan_9_from_Bell_Labs[AT&T Plan 9] http://en.wikipedia.org/wiki/Rc[rc shell]
840 `posh` @-@popcon1@-@ @-@psize1@-@ Yes Policy-compliant Ordinary SHell (`pdksh` derivative)
841 ------------------------------------------------------------------------------------------------------------------------------------------
842
843 // Removed from archive
844 // || {{{es}}} || ? || - || No || An extensible shell based on the AT&T Plan 9 [http://en.wikipedia.org/wiki/Rc rc shell]. ||
845
846 In this tutorial chapter, the interactive shell always means `bash`.
847
848 ==== Customizing bash
849
850 You can customize `bash`(1) behavior by "`\~/.bashrc`".
851
852 For example, try the following.
853
854 --------------------
855 # CD upon exiting MC
856 . /usr/share/mc/bin/mc.sh
857
858 # set CDPATH to good one
859 CDPATH=.:/usr/share/doc:~/Desktop/src:~/Desktop:~
860 export CDPATH
861
862 PATH="${PATH}":/usr/sbin:/sbin
863 # set PATH so it includes user's private bin if it exists
864 if [ -d ~/bin ] ; then
865 PATH=~/bin:"${PATH}"
866 fi
867 export PATH
868
869 EDITOR=vim
870 export EDITOR
871 --------------------
872
873 TIP: You can find more `bash` customization tips, such as <<_colorized_commands>>, in <<_system_tips>>.
874
875 ==== Special key strokes
876
877 In the http://en.wikipedia.org/wiki/Unix-like[Unix-like] environment, there are few key strokes which have special meanings. Please note that on a normal Linux character console, only the left-hand `Ctrl` and `Alt` keys work as expected. Here are few notable key strokes to remember.
878
879 .List of key bindings for bash
880 [grid="all"]
881 `------------------------------------------`----------------------------------------------------------------
882 key description of key binding
883 ------------------------------------------------------------------------------------------------------------
884 `Ctrl-U` erase line before cursor
885 `Ctrl-H` erase a character before cursor
886 `Ctrl-D` terminate input (exit shell if you are using shell)
887 `Ctrl-C` terminate a running program
888 `Ctrl-Z` temporarily stop program by moving it to the background job
889 `Ctrl-S` halt output to screen
890 `Ctrl-Q` reactivate output to screen
891 `Ctrl-Alt-Del` reboot/halt the system, see `inittab`(5)
892 `Left-Alt-key` (optionally, `Windows-key`) meta-key for Emacs and the similar UI
893 `Up-arrow` start command history search under `bash`
894 `Ctrl-R` start incremental command history search under `bash`
895 `Tab` complete input of the filename to the command line under `bash`
896 `Ctrl-V` `Tab` input `Tab` without expansion to the command line under `bash`
897 ------------------------------------------------------------------------------------------------------------
898
899 TIP: The terminal feature of `Ctrl-S` can be disabled using `stty`(1).
900
901 ==== Unix style mouse operations
902
903 Unix style mouse operations are based on the 3 button mouse system.
904
905 .List of Unix style mouse operations
906 [grid="all"]
907 `-------------------------`------------------------------------------------------
908 action response
909 ---------------------------------------------------------------------------------
910 Left-click-and-drag mouse select and copy to the clipboard
911 Left-click select the start of selection
912 Right-click select the end of selection and copy to the clipboard
913 Middle-click paste clipboard at the cursor
914 ---------------------------------------------------------------------------------
915
916 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. In order to use a mouse in Linux character consoles, you need to have `gpm`(8) running as daemon.
917
918 ==== The pager
919
920 `less`(1) is the enhanced pager (file content browser). Hit "`h`" for help. It can do much more than `more`(1) and can be supercharged by executing "`eval $(lesspipe)`" or "`eval $(lessfile)`" in the shell startup script. See more in "`/usr/share/doc/lessf/LESSOPEN`". The "`-R`" option allows raw character output and enables ANSI color escape sequences. See `less`(1).
921
922 ==== The text editor
923
924 You should become proficient in one of variants of http://en.wikipedia.org/wiki/Vim_(text_editor)[Vim] or http://en.wikipedia.org/wiki/Emacs[Emacs] programs which are popular in the Unix-like system.
925
926 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 `vi` or new `nvi` are programs you find everywhere. I chose Vim instead for newbie since it offers you help through `F1` key while it is similar enough and more powerful.)
927
928 If you chose either http://en.wikipedia.org/wiki/Emacs[Emacs] or http://en.wikipedia.org/wiki/XEmacs[XEmacs] 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.
929
930 All these programs usually come with tutoring program for you to learn them by practice. Start Vim by typing "`vim`" and press F1-key. You should at least read the first 35 lines. Then do the online training course by moving cursor to "`|tutor|`" and pressing `Ctrl-]`.
931
932 NOTE: Good editors, such as Vim and Emacs, can be used to handle UTF-8 and other exotic encoding texts correctly with proper option in the x-terminal-emulator on X under UTF-8 locale with proper font settings. Please refer to their documentation on multibyte text.
933
934 ==== Setting a default text editor
935
936 Debian comes with a number of different editors. We recommend to install the `vim` package, as mentioned above.
937
938 Debian provides unified access to the system default editor via command "`/usr/bin/editor`" so other programs (e.g., `reportbug`(1)) can invoke it. You can change it by the following.
939
940 --------------------
941 $ sudo update-alternatives --config editor
942 --------------------
943
944 The choice "`/usr/bin/vim.basic`" over "`/usr/bin/vim.tiny`" is my recommendation for newbies since it supports syntax highlighting.
945
946 TIP: Many programs use the environment variables "`$EDITOR`" or "`$VISUAL`" to decide which editor to use (see <<_the_internal_editor_in_mc>> and <<_customizing_program_to_be_started>>). For the consistency on Debian system, set these to "`/usr/bin/editor`". (Historically, "`$EDITOR`" was "`ed`" and "`$VISUAL`" was "`vi`".)
947
948 ==== Customizing vim
949
950 You can customize `vim`(1) behavior by "`\~/.vimrc`".
951
952 For example, try the following
953
954 --------------------
955 " -------------------------------
956 " Local configuration
957 "
958 set nocompatible
959 set nopaste
960 set pastetoggle=<f2>
961 syn on
962 if $USER == "root"
963 set nomodeline
964 set noswapfile
965 else
966 set modeline
967 set swapfile
968 endif
969 " filler to avoid the line above being recognized as a modeline
970 " filler
971 " filler
972 --------------------
973
974 ==== Recording the shell activities
975
976 The output of the shell command may roll off your screen and may be lost forever. It is 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.
977
978 The basic method of recording the shell activity is to run it under `script`(1).
979
980 For example, try the following
981
982 --------------------
983 $ script
984 Script started, file is typescript
985 --------------------
986
987 Do whatever shell commands under `script`.
988
989 Press `Ctrl-D` to exit `script`.
990
991 --------------------
992 $ vim typescript
993 --------------------
994
995 See <<_recording_the_shell_activities_cleanly>> .
996
997 ==== Basic Unix commands
998
999 Let@@@sq@@@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 `alias` is used in the shell, its corresponding command outputs are different. These examples are not meant to be executed in this order.
1000
1001 Try all following commands from the non-privileged user account.
1002
1003 .List of basic Unix commands
1004 [grid="all"]
1005 `--------------------------------`--------------------------------------------------------------------------------------------------------
1006 command description
1007 ------------------------------------------------------------------------------------------------------------------------------------------
1008 `pwd` display name of current/working directory
1009 `whoami` display current user name
1010 `id` display current user identity (name, uid, gid, and associated groups)
1011 `file <foo>` display a type of file for the file "`<foo>`"
1012 `type -p <commandname>` display a file location of command "`<commandname>`"
1013 `which <commandname>` , ,
1014 `type <commandname>` display information on command "`<commandname>`"
1015 `apropos <key-word>` find commands related to "`<key-word>`"
1016 `man -k <key-word>` , ,
1017 `whatis <commandname>` display one line explanation on command "`<commandname>`"
1018 `man -a <commandname>` display explanation on command "`<commandname>`" (Unix style)
1019 `info <commandname>` display rather long explanation on command "`<commandname>`" (GNU style)
1020 `ls` list contents of directory (non-dot files and directories)
1021 `ls -a` list contents of directory (all files and directories)
1022 `ls -A` list contents of directory (almost all files and directories, i.e., skip "`..`" and "`.`")
1023 `ls -la` list all contents of directory with detail information
1024 `ls -lai` list all contents of directory with inode number and detail information
1025 `ls -d` list all directories under the current directory
1026 `tree` display file tree contents
1027 `lsof <foo>` list open status of file "`<foo>`"
1028 `lsof -p <pid>` list files opened by the process ID: "`<pid>`"
1029 `mkdir <foo>` make a new directory "`<foo>`" in the current directory
1030 `rmdir <foo>` remove a directory "`<foo>`" in the current directory
1031 `cd <foo>` change directory to the directory "`<foo>`" in the current directory or in the directory listed in the variable "`$CDPATH`"
1032 `cd /` change directory to the root directory
1033 `cd` change directory to the current user@@@sq@@@s home directory
1034 `cd /<foo>` change directory to the absolute path directory "`/<foo>`"
1035 `cd ..` change directory to the parent directory
1036 `cd \~<foo>` change directory to the home directory of the user "`<foo>`"
1037 `cd -` change directory to the previous directory
1038 `</etc/motd pager` display contents of "`/etc/motd`" using the default pager
1039 `touch <junkfile>` create a empty file "`<junkfile>`"
1040 `cp <foo> <bar>` copy a existing file "`<foo>`" to a new file "`<bar>`"
1041 `rm <junkfile>` remove a file "`<junkfile>`"
1042 `mv <foo> <bar>` rename an existing file "`<foo>`" to a new name "`<bar>`" ("`<bar>`" must not exist)
1043 `mv <foo> <bar>` move an existing file "`<foo>`" to a new location "`<bar>/<foo>`" (the directory "`<bar>`" must exist)
1044 `mv <foo> <bar>/<baz>` move an existing file "`<foo>`" to a new location with a new name "`<bar>/<baz>`" (the directory "`<bar>`" must exist but the directory "`<bar>/<baz>`" must not exist)
1045 `chmod 600 <foo>` make an existing file "`<foo>`" to be non-readable and non-writable by the other people (non-executable for all)
1046 `chmod 644 <foo>` make an existing file "`<foo>`" to be readable but non-writable by the other people (non-executable for all)
1047 `chmod 755 <foo>` make an existing file "`<foo>`" to be readable but non-writable by the other people (executable for all)
1048 `find . -name <pattern>` find matching filenames using shell "`<pattern>`" (slower)
1049 `locate -d . <pattern>` find matching filenames using shell "`<pattern>`" (quicker using regularly generated database)
1050 `grep -e "<pattern>" \*.html` find a "<pattern>" in all files ending with "`.html`" in current directory and display them all
1051 `top` display process information using full screen, type "`q`" to quit
1052 `ps aux | pager` display information on all the running processes using BSD style output
1053 `ps -ef | pager` display information on all the running processes using Unix system-V style output
1054 `ps aux | grep -e "[e]xim4\*"` display all processes running "`exim`" and "`exim4`"
1055 `ps axf | pager` display information on all the running processes with ASCII art output
1056 `kill <1234>` kill a process identified by the process ID: "<1234>"
1057 `gzip <foo>` compress "`<foo>`" to create "`<foo>.gz`" using the Lempel-Ziv coding (LZ77)
1058 `gunzip <foo>.gz` decompress "`<foo>.gz`" to create "`<foo>`"
1059 `bzip2 <foo>` compress "`<foo>`" to create "`<foo>.bz2`" using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding (better compression than `gzip`)
1060 `bunzip2 <foo>.bz2` decompress "`<foo>.bz2`" to create "`<foo>`"
1061 `tar -xvf <foo>.tar` extract files from "`<foo>.tar`" archive
1062 `tar -xvzf <foo>.tar.gz` extract files from gzipped "`<foo>.tar.gz`" archive
1063 `tar -xvf -j <foo>.tar.bz2` extract files from "`<foo>.tar.bz2`" archive
1064 `tar -cvf <foo>.tar <bar>/` archive contents of folder "`<bar>/`" in "`<foo>.tar`" archive
1065 `tar -cvzf <foo>.tar.gz <bar>/` archive contents of folder "`<bar>/`" in compressed "`<foo>.tar.gz`" archive
1066 `tar -cvjf <foo>.tar.bz2 <bar>/` archive contents of folder "`<bar>/`" in "`<foo>.tar.bz2`" archive
1067 `zcat README.gz | pager` display contents of compressed "`README.gz`" using the default pager
1068 `zcat README.gz > foo` create a file "`foo`" with the decompressed content of "`README.gz`"
1069 `zcat README.gz >> foo` append the decompressed content of "`README.gz`" to the end of the file "`foo`" (if it does not exist, create it first)
1070 ------------------------------------------------------------------------------------------------------------------------------------------
1071
1072 NOTE: Unix has a tradition to hide filenames which start with "`.`". They are traditionally files that contain configuration information and user preferences.
1073
1074 NOTE: For `cd` command, see `builtins`(7).
1075
1076 NOTE: The default pager of the bare bone Debian system is `more`(1) which cannot scroll back. By installing the `less` package using command line "`aptitude install less`", `less`(1) becomes default pager and you can scroll back with cursor keys.
1077
1078 NOTE: The "`[`" and "`]`" in the regular expression of the "`ps aux | grep -e "[e]xim4\*"`" command above enable `grep` to avoid matching itself. The "`4\*`" in the regular expression means 0 or more repeats of character "`4`" thus enables `grep` to match both "`exim`" and "`exim4`". Although "`\*`" is used in the shell filename glob and the regular expression, their meanings are different. Learn the regular expression from `grep`(1).
1079
1080 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.
1081
1082 For example, try the following
1083
1084 --------------------
1085 $ man man
1086 $ man bash
1087 $ man builtins
1088 $ man grep
1089 $ man ls
1090 --------------------
1091
1092 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.
1093
1094 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).
1095
1096 --------------------
1097 $ <commandname> --help
1098 $ <commandname> -h
1099 --------------------
1100
1101 === The simple shell command
1102
1103 Now you have some feel on how to use the Debian system. Let@@@sq@@@s look deep into the mechanism of the command execution in the Debian system. Here, I have simplified reality for the newbie. See `bash`(1) for the exact explanation.
1104
1105 A simple command is a sequence of components.
1106
1107 1. Variable assignments (optional)
1108 2. Command name
1109 3. Arguments (optional)
1110 4. Redirections (optional: `>` , `>>` , `<` , `<<` , etc.)
1111 5. Control operator (optional: `&&` , `||` , <newline> , `;` , `&` , `(` , `)` )
1112
1113 ==== Command execution and environment variable
1114
1115 Values of some http://en.wikipedia.org/wiki/Environment_variable[environment variables] change the behavior of some Unix commands.
1116
1117 Default values of environment variables are initially set by the PAM system and then some of them may be reset by some application programs.
1118
1119 - The display manager such as `gdm` resets environment variables.
1120 - The shell in its start up codes resets environment variables in "`\~/bash_profile`" and "`\~/.bashrc`".
1121
1122 ==== "`$LANG`" variable
1123
1124 The full locale value given to "`$LANG`" variable consists of 3 parts: "`xx_YY.ZZZZ`".
1125
1126 .3 parts of locale value
1127 [grid="all"]
1128 `------------`--------------------------------------------------------------------------------------------
1129 locale value meaning
1130 ----------------------------------------------------------------------------------------------------------
1131 `xx` http://en.wikipedia.org/wiki/ISO_639[ISO 639 language codes (lower case) such as "en"]
1132 `YY` http://en.wikipedia.org/wiki/ISO_3166-3[ISO 3166 country codes (upper case) such as "US"]
1133 `ZZZZ` http://en.wikipedia.org/wiki/Codeset[codeset, always set to "UTF-8"]
1134 ----------------------------------------------------------------------------------------------------------
1135
1136 For language codes and country codes, see pertinent description in the "`info gettext`".
1137
1138 For the codeset on the modern Debian system, you should always set it to **`UTF-8`** unless you specifically want to use the historic one with good reason and background knowledge.
1139
1140 For fine details of the locale configuration, see <<_the_locale>>.
1141
1142 NOTE: The "`LANG=en_US`" is not "`LANG=C`" nor "`LANG=en_US.UTF-8`". It is "`LANG=en_US.ISO-8859-1`" (see <<_basics_of_encoding>>).
1143
1144 .List of locale recommendations
1145 [grid="all"]
1146 `---------------------`-------------------------
1147 locale recommendation Language (area)
1148 ------------------------------------------------
1149 `en_US.UTF-8` English(USA)
1150 `en_GB.UTF-8` English(Great_Britain)
1151 `fr_FR.UTF-8` French(France)
1152 `de_DE.UTF-8` German(Germany)
1153 `it_IT.UTF-8` Italian(Italy)
1154 `es_ES.UTF-8` Spanish(Spain)
1155 `ca_ES.UTF-8` Catalan(Spain)
1156 `sv_SE.UTF-8` Swedish(Sweden)
1157 `pt_BR.UTF-8` Portuguese(Brazil)
1158 `ru_RU.UTF-8` Russian(Russia)
1159 `zh_CN.UTF-8` Chinese(P.R._of_China)
1160 `zh_TW.UTF-8` Chinese(Taiwan_R.O.C.)
1161 `ja_JP.UTF-8` Japanese(Japan)
1162 `ko_KR.UTF-8` Korean(Republic_of_Korea)
1163 `vi_VN.UTF-8` Vietnamese(Vietnam)
1164 ------------------------------------------------
1165
1166 Typical command execution uses a shell line sequence as the following.
1167
1168 --------------------
1169 $ date
1170 Sun Jun 3 10:27:39 JST 2007
1171 $ LANG=fr_FR.UTF-8 date
1172 dimanche 3 juin 2007, 10:27:33 (UTC+0900)
1173 --------------------
1174
1175 Here, the program `date`(1) is executed with different values of the environment variable "`$LANG`".
1176
1177 - For the first command, "`$LANG`" is set to the system default http://en.wikipedia.org/wiki/Locale[locale] value "`en_US.UTF-8`".
1178 - For the second command, "`$LANG`" is set to the French UTF-8 http://en.wikipedia.org/wiki/Locale[locale] value "`fr_FR.UTF-8`".
1179
1180 Most command executions usually do not have preceding environment variable definition. For the above example, you can alternatively execute as the following.
1181
1182 --------------------
1183 $ LANG=fr_FR.UTF-8
1184 $ date
1185 dimanche 3 juin 2007, 10:27:33 (UTC+0900)
1186 --------------------
1187
1188 As you can see here, the output of command is affected by the environment variable to produce French output. If you want the environment variable to be inherited to subprocesses (e.g., when calling shell script), you need to **export** it instead by the following.
1189
1190 --------------------
1191 $ export LANG
1192 --------------------
1193
1194 TIP: When filing a bug report, running and checking the command under "`LANG=en_US.UTF-8`" is good idea if you use non-English environment.
1195
1196 See `locale`(5) and `locale`(7) for "`$LANG`" and related environment variables.
1197
1198 NOTE: I recommend you to configure the system environment just by the "`$LANG`" variable and to stay away from "`$LC_\*`" variables unless it is absolutely needed.
1199
1200 ==== "`$PATH`" variable
1201
1202 When you type a command into the shell, the shell searches the command in the list of directories contained in the "`$PATH`" environment variable. The value of the "`$PATH`" environment variable is also called the shell@@@sq@@@s search path.
1203
1204 In the default Debian installation, the "`$PATH`" environment variable of user accounts may not include "`/sbin`" and "`/usr/sbin`". For example, the `ifconfig` command needs to be issued with full path as "`/sbin/ifconfig`". (Similar `ip` command is located in "`/bin`".)
1205
1206 You can change the "`$PATH`" environment variable of Bash shell by "`\~/.bash_profile`" or "`\~/.bashrc`" files.
1207
1208 ==== "`$HOME`" variable
1209
1210 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 "`$HOME`".
1211
1212 .List of "`$HOME`" values
1213 [grid="all"]
1214 `---------------------`-------------------------------------------------
1215 value of "`$HOME`" program execution situation
1216 ------------------------------------------------------------------------
1217 `/` program run by the init process (daemon)
1218 `/root` program run from the normal root shell
1219 `/home/<normal_user>` program run from the normal user shell
1220 `/home/<normal_user>` program run from the normal user GUI desktop menu
1221 `/home/<normal_user>` program run as root with "`sudo program`"
1222 `/root` program run as root with "`sudo -H program`"
1223 ------------------------------------------------------------------------
1224
1225 TIP: Shell expands "`\~/`" to current user’s home directory, i.e., "`$HOME/`". Shell expands "`\~foo/`" to `foo`@@@sq@@@s home directory, i.e., "`/home/foo/`".
1226
1227 ==== Command line options
1228
1229 Some commands take arguments. Arguments starting with "`-`" or "`--`" are called options and control the behavior of the command.
1230
1231 --------------------
1232 $ date
1233 Mon Oct 27 23:02:09 CET 2003
1234 $ date -R
1235 Mon, 27 Oct 2003 23:02:40 +0100
1236 --------------------
1237
1238 Here the command-line argument "`-R`" changes `date`(1) behavior to output http://tools.ietf.org/html/rfc2822[RFC2822] compliant date string.
1239
1240 ==== Shell glob
1241
1242 Often you want a command to work with a group of files without typing all of them. The filename expansion pattern using the shell **glob**, (sometimes referred as **wildcards**), facilitate this need.
1243
1244 .Shell glob patterns
1245 [grid="all"]
1246 `------------------`----------------------------------------------------------------------------------------------------
1247 shell glob pattern description of match rule
1248 ------------------------------------------------------------------------------------------------------------------------
1249 `\*` filename (segment) not started with "`.`"
1250 `.\*` filename (segment) started with "`.`"
1251 `?` exactly one character
1252 `[...]` exactly one character with any character enclosed in brackets
1253 `[a-z]` exactly one character with any character between "`a`" and "`z`"
1254 `[\^...]` exactly one character other than any character enclosed in brackets (excluding "`\^`")
1255 ------------------------------------------------------------------------------------------------------------------------
1256
1257 For example, try the following
1258
1259 --------------------
1260 $ mkdir junk; cd junk; touch 1.txt 2.txt 3.c 4.h .5.txt ..6.txt
1261 $ echo *.txt
1262 1.txt 2.txt
1263 $ echo *
1264 1.txt 2.txt 3.c 4.h
1265 $ echo *.[hc]
1266 3.c 4.h
1267 $ echo .*
1268 . .. .5.txt ..6.txt
1269 $ echo .*[^.]*
1270 .5.txt ..6.txt
1271 $ echo [^1-3]*
1272 4.h
1273 $ cd ..; rm -rf junk
1274 --------------------
1275
1276 See `glob`(7).
1277
1278 NOTE: Unlike normal filename expansion by the shell, the shell pattern "`\*`" tested in `find`(1) with "`-name`" test etc., matches the initial "`.`" of the filename. (New http://en.wikipedia.org/wiki/POSIX[POSIX] feature)
1279
1280 NOTE: BASH can be tweaked to change its glob behavior with its shopt builtin options such as "`dotglob`", "`noglob`", "`nocaseglob`", "`nullglob`", "`nocaseglob`", "`extglob`", etc. See `bash`(1).
1281
1282 ==== Return value of the command
1283
1284 Each command returns its exit status (variable: "`$?`") as the return value.
1285
1286 .Command exit codes
1287 [grid="all"]
1288 `-------------------`--------------------`--------------------
1289 command exit status numeric return value logical return value
1290 --------------------------------------------------------------
1291 success zero, 0 **TRUE**
1292 error non-zero, -1 **FALSE**
1293 --------------------------------------------------------------
1294
1295 For example, try the following.
1296
1297 --------------------
1298 $ [ 1 = 1 ] ; echo $?
1299 0
1300 $ [ 1 = 2 ] ; echo $?
1301 1
1302 --------------------
1303
1304 NOTE: Please note that, in the logical context for the shell, **success** is treated as the logical **TRUE** which has 0 (zero) as its value. This is somewhat non-intuitive and needs to be reminded here.
1305
1306 ==== Typical command sequences and shell redirection
1307
1308 Let@@@sq@@@s try to remember following shell command idioms typed in one line as a part of shell command.
1309
1310 .Shell command idioms
1311 [grid="all"]
1312 `--------------------------`--------------------------------------------------------------------------------------------------------------
1313 command idiom description
1314 ------------------------------------------------------------------------------------------------------------------------------------------
1315 `command &` **background** execution of `command` in the subshell
1316 `command1 | command2` **pipe** the standard output of `command1` to the standard input of `command2` (**concurrent** execution)
1317 `command1 2>&1 | command2` **pipe** both standard output and standard error of `command1` to the standard input of `command2` (**concurrent** execution)
1318 `command1 ; command2` execute `command1` and `command2` **sequentially**
1319 `command1 && command2` execute `command1`; if successful, execute `command2` **sequentially** (return success if both `command1` **and** `command2` are successful)
1320 `command1 || command2` execute `command1`; if not successful, execute `command2` **sequentially** (return success if `command1` **or** `command2` are successful)
1321 `command > foo` redirect standard output of `command` to a file `foo` (overwrite)
1322 `command 2> foo` redirect standard error of `command` to a file `foo` (overwrite)
1323 `command >> foo` redirect standard output of `command` to a file `foo` (append)
1324 `command 2>> foo` redirect standard error of `command` to a file `foo` (append)
1325 `command > foo 2>&1` redirect both standard output and standard error of `command` to a file "`foo`"
1326 `command < foo` redirect standard input of `command` to a file `foo`
1327 `command << delimiter` redirect standard input of `command` to the following lines until "`delimiter`" is met (here document)
1328 `command <\<- delimiter` redirect standard input of `command` to the following lines until "`delimiter`" is met (here document, the leading tab characters are stripped from input lines)
1329 ------------------------------------------------------------------------------------------------------------------------------------------
1330
1331 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: `jobs`, `fg`, `bg`, and `kill`. Please read sections of bash(1) under "SIGNALS", and "JOB CONTROL", and `builtins`(1).
1332
1333 For example, try the following
1334
1335 --------------------
1336 $ </etc/motd pager
1337 --------------------
1338
1339 --------------------
1340 $ pager </etc/motd
1341 --------------------
1342
1343 --------------------
1344 $ pager /etc/motd
1345 --------------------
1346
1347 --------------------
1348 $ cat /etc/motd | pager
1349 --------------------
1350
1351 Although all 4 examples of shell redirections display the same thing, the last example runs an extra `cat` command and wastes resources with no reason.
1352
1353 The shell allows you to open files using the `exec` builtin with an arbitrary file descriptor.
1354
1355 --------------------
1356 $ echo Hello >foo
1357 $ exec 3<foo 4>bar # open files
1358 $ cat <&3 >&4 # redirect stdin to 3, stdout to 4
1359 $ exec 3<&- 4>&- # close files
1360 $ cat bar
1361 Hello
1362 --------------------
1363
1364 Here, "`__n__<&-`" and "`__n__>&-`" mean to close the file descriptor "`__n__`".
1365
1366 The file descriptor 0-2 are predefined.
1367
1368 .Predefined file descriptors
1369 [grid="all"]
1370 `--------`---------------`---------------
1371 device description file descriptor
1372 -----------------------------------------
1373 `stdin` standard input 0
1374 `stdout` standard output 1
1375 `stderr` standard error 2
1376 -----------------------------------------
1377
1378 ==== Command alias
1379
1380 You can set an alias for the frequently used command.
1381
1382 For example, try the following
1383
1384 --------------------
1385 $ alias la='ls -la'
1386 --------------------
1387
1388 Now, "`la`" works as a short hand for "`ls -la`" which lists all files in the long listing format.
1389
1390 You can list any existing aliases by `alias` (see `bash`(1) under "SHELL BUILTIN COMMANDS").
1391
1392 --------------------
1393 $ alias
1394 ...
1395 alias la='ls -la'
1396 --------------------
1397
1398 You can identity exact path or identity of the command by `type` (see `bash`(1) under "SHELL BUILTIN COMMANDS").
1399
1400 For example, try the following
1401
1402 --------------------
1403 $ type ls
1404 ls is hashed (/bin/ls)
1405 $ type la
1406 la is aliased to ls -la
1407 $ type echo
1408 echo is a shell builtin
1409 $ type file
1410 file is /usr/bin/file
1411 --------------------
1412
1413 Here `ls` was recently searched while "`file`" was not, thus "`ls`" is "hashed", i.e., the shell has an internal record for the quick access to the location of the "`ls`" command.
1414
1415 TIP: See <<_colorized_commands>>.
1416
1417 === Unix-like text processing
1418
1419 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.
1420
1421 ==== Unix text tools
1422
1423 There are few standard text processing tools which are used very often on the Unix-like system.
1424
1425 - No regular expression is used:
1426 * `cat`(1) concatenates files and outputs the whole content.
1427 * `tac`(1) concatenates files and outputs in reverse.
1428 * `cut`(1) selects parts of lines and outputs.
1429 * `head`(1) outputs the first part of files.
1430 * `tail`(1) outputs the last part of files.
1431 * `sort`(1) sorts lines of text files.
1432 * `uniq`(1) removes duplicate lines from a sorted file.
1433 * `tr`(1) translates or deletes characters.
1434 * `diff`(1) compares files line by line.
1435 - Basic regular expression (**BRE**) is used:
1436 * `grep`(1) matches text with patterns.
1437 * `ed`(1) is a primitive line editor.
1438 * `sed`(1) is a stream editor.
1439 * `vim`(1) is a screen editor.
1440 * `emacs`(1) is a screen editor. (somewhat extended **BRE**)
1441 - Extended regular expression (**ERE**) is used:
1442 * `egrep`(1) matches text with patterns.
1443 * `awk`(1) does simple text processing.
1444 * `tcl`(3tcl) can do every conceivable text processing: `re_syntax`(3). Often used with `tk`(3tk).
1445 * `perl`(1) can do every conceivable text processing. `perlre`(1).
1446 * `pcregrep`(1) from the `pcregrep` package matches text with http://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions[Perl Compatible Regular Expressions (PCRE)] pattern.
1447 * `python`(1) with the `re` module can do every conceivable text processing. See "`/usr/share/doc/python/html/index.html`".
1448
1449 If you are not sure what exactly these commands do, please use "`man command`" to figure it out by yourself.
1450
1451 NOTE: Sort order and range expression are locale dependent. If you wish to obtain traditional behavior for a command, use **C** locale instead of **UTF-8** ones by prepnding command with "`LANG=C`" (see <<_literal_lang_literal_variable>> and <<_the_locale>>).
1452
1453 NOTE: http://en.wikipedia.org/wiki/Perl[Perl] regular expressions (`perlre`(1)), http://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions[Perl Compatible Regular Expressions (PCRE)], and http://en.wikipedia.org/wiki/Python_(programming_language)[Python] regular expressions offered by the `re` module have many common extensions to the normal **ERE**.
1454
1455 ==== Regular expressions
1456
1457 http://en.wikipedia.org/wiki/Regular_expression[Regular expressions] are used in many text processing tools. They are analogous to the shell globs, but they are more complicated and powerful.
1458
1459 The regular expression describes the matching pattern and is made up of text characters and **metacharacters**.
1460
1461 The **metacharacter** is just a character with a special meaning. There are 2 major styles, **BRE** and **ERE**, depending on the text tools as described above.
1462
1463 .Metacharacters for BRE and ERE
1464 [grid="all"]
1465 `------------------------`--------------------`-------------------------------------------------------------------------------------------
1466 BRE ERE description of the regular expression
1467 ------------------------------------------------------------------------------------------------------------------------------------------
1468 ` \ . [ ] \^ $ \* ` `\ . [ ] \^ $ \*` common **metacharacters**
1469 `\\+ \? \( \) \\{ \\} \|` {nbsp} BRE only "`\`" escaped **metacharacters**
1470 {nbsp} `\+ ? ( ) { } |` ERE only non-"`\`" escaped **metacharacters**
1471 `c` `c` match **non-metacharacter** "`c`"
1472 `\c` `\c` match a literal character "`c`" even if "`c`" is **metacharacter** by itself
1473 `.` `.` match any character including newline
1474 `\^` `\^` position at the beginning of a string
1475 `$` `$` position at the end of a string
1476 `\<` `\<` position at the beginning of a word
1477 `\>` `\>` position at the end of a word
1478 `\[abc...\]` `[abc...]` match any characters in "`abc...`"
1479 `\[\^abc...\]` `[\^abc...]` match any characters except in "`abc...`"
1480 `r\*` `r\*` match zero or more regular expressions identified by "`r`"
1481 `r\\+` `r\+` match one or more regular expressions identified by "`r`"
1482 `r\?` `r?` match zero or one regular expressions identified by "`r`"
1483 `r1\|r2` `r1|r2` match one of the regular expressions identified by "`r1`" or "`r2`"
1484 `\(r1\|r2\)` `(r1|r2)` match one of the regular expressions identified by "`r1`" or "`r2`" and treat it as a **bracketed** regular expression
1485 ------------------------------------------------------------------------------------------------------------------------------------------
1486
1487 The regular expression of **`emacs`** is basically **BRE** but has been extended to treat "`\+`"and "`?`" as the **metacharacters** as in **ERE**. Thus, there are no needs to escape them with "`\`" in the regular expression of `emacs`.
1488
1489 `grep`(1) can be used to perform the text search using the regular expression.
1490
1491 For example, try the following
1492
1493 --------------------
1494 $ egrep 'GNU.*LICENSE|Yoyodyne' /usr/share/common-licenses/GPL
1495 GNU GENERAL PUBLIC LICENSE
1496 GNU GENERAL PUBLIC LICENSE
1497 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
1498 --------------------
1499
1500 TIP: See <<_colorized_commands>>.
1501
1502 ==== Replacement expressions
1503
1504 For the replacement expression, some characters have special meanings.
1505
1506 .The replacement expression
1507 [grid="all"]
1508 `----------------------`-----------------------------------------------------------------------------
1509 replacement expression description of the text to replace the replacement expression
1510 -----------------------------------------------------------------------------------------------------
1511 `&` what the regular expression matched (use `\&` in `emacs`)
1512 `\n` what the n-th **bracketed** regular expression matched ("n" being number)
1513 -----------------------------------------------------------------------------------------------------
1514
1515 For Perl replacement string, "`$n`" is used instead of "`\n`" and "`&`" has no special meaning.
1516
1517 For example, try the following
1518
1519 --------------------
1520 $ echo zzz1abc2efg3hij4 | \
1521 sed -e 's/\(1[a-z]*\)[0-9]*\(.*\)$/=&=/'
1522 zzz=1abc2efg3hij4=
1523 $ echo zzz1abc2efg3hij4 | \
1524 sed -e 's/\(1[a-z]*\)[0-9]*\(.*\)$/\2===\1/'
1525 zzzefg3hij4===1abc
1526 $ echo zzz1abc2efg3hij4 | \
1527 perl -pe 's/(1[a-z]*)[0-9]*(.*)$/$2===$1/'
1528 zzzefg3hij4===1abc
1529 $ echo zzz1abc2efg3hij4 | \
1530 perl -pe 's/(1[a-z]*)[0-9]*(.*)$/=&=/'
1531 zzz=&=
1532 --------------------
1533
1534 Here please pay extra attention to the style of the **bracketed** regular expression and how the matched strings are used in the text replacement process on different tools.
1535
1536 These regular expressions can be used for cursor movements and text replacement actions in some editors too.
1537
1538 The back slash "`\`" 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.
1539
1540 Please read all the related manual pages to learn these commands.
1541
1542 ==== Global substitution with regular expressions
1543
1544 The `ed`(1) command can replace all instances of "`FROM_REGEX`" with "`TO_TEXT`" in "`file`".
1545
1546 --------------------
1547 $ ed file <<EOF
1548 ,s/FROM_REGEX/TO_TEXT/g
1549 w
1550 q
1551 EOF
1552 --------------------
1553
1554 The `sed`(1) command can replace all instances of "`FROM_REGEX`" with "`TO_TEXT`" in "`file`".
1555
1556 --------------------
1557 $ sed file 's/FROM_REGEX/TO_TEXT/g' | sponge file
1558 --------------------
1559
1560 TIP: The `sponge`(8) command is a non-standard Unix tool offered by the `moreutils` package. This is quite useful when you wish to overwrite original file.
1561
1562 The `vim`(1) command can replace all instances of "`FROM_REGEX`" with "`TO_TEXT`" in "`file`" by using `ex`(1) commands.
1563
1564 --------------------
1565 $ vim '+%s/FROM_REGEX/TO_TEXT/gc' '+w' '+q' file
1566 --------------------
1567
1568 TIP: The "`c`" flag in the above ensures interactive confirmation for each substitution.
1569
1570 Multiple files ("`file1`", "`file2`", and "`file3`") can be processed with regular expressions similarly with `vim`(1) or `perl`(1).
1571
1572 --------------------
1573 $ vim '+argdo %s/FROM_REGEX/TO_TEXT/ge|update' '+q' file1 file2 file3
1574 --------------------
1575
1576 TIP: The "`e`" flag in the above prevents the "No match" error from breaking a mapping.
1577
1578 --------------------
1579 $ perl -i -p -e 's/FROM_REGEX/TO_TEXT/g;' file1 file2 file3
1580 --------------------
1581
1582 In the perl(1) example, "`-i`" is for in-place editing, "`-p`" is for implicit loop over files.
1583
1584 TIP: Use of argument "`-i.bak`" instead of "`-i`" keeps each original file by adding "`.bak`" to its filename. This makes recovery from errors easier for complex substitutions.
1585
1586 NOTE: `ed`(1) and `vim`(1) are **BRE**; `perl`(1) is **ERE**.
1587
1588 //|| The comparison of commands used for in-place editing. || || || || ||
1589 //|| '''command''' || '''regex''' || '''script''' || '''binary size''' || '''library size''' ||
1590 //|| {{{ed}}}(1) || BRE || read from "{{{stdin}}}" || about 50KB || about 1300KB (only {{{libc}}}) ||
1591 //|| {{{vim}}}(1) || BRE || can be as a part of the argument || about 1900KB || about 7300KB total ||
1592 //|| {{{perl}}}(1) || ERE || can be as a part of the argument || about 7KB || about 3500KB total ||
1593
1594 // Here is how I got these numbers
1595 // for i in ed vim perl; do echo "$i: binary size ================================================ $(stat -c '%s' $(readlink -e $(type -p $i)))"; ldd $(type -p $i) ; echo "size all libs ======================================== $(($(ldd -v $(type -p $i)|sed -n 's/[^\/]*\(\/.*\):/\1/p'|xargs -n1 readlink -e |xargs -n1 stat -c '%s +' ;echo -$(type -p $i| xargs -n1 readlink -e |xargs -n1 stat -c '%s') )))" ;done
1596 // vim was vim.nox
1597
1598 ==== Extracting data from text file table
1599
1600 Let@@@sq@@@s consider a text file called "`DPL`" in which some pre-2004 Debian project leader@@@sq@@@s names and their initiation days are listed in a
1601 space-separated format.
1602
1603 --------------------
1604 Ian Murdock August 1993
1605 Bruce Perens April 1996
1606 Ian Jackson January 1998
1607 Wichert Akkerman January 1999
1608 Ben Collins April 2001
1609 Bdale Garbee April 2002
1610 Martin Michlmayr March 2003
1611 --------------------
1612
1613 // Purpose of this is not to document DPL history here. So I picked old ones only.
1614 // Do not add updates for above which gain nothing but clutter table.
1615 // Pointer to History is just below.
1616
1617 TIP: See http://www.debian.org/doc/manuals/project-history/index.en.html["A Brief History of Debian"] for the latest http://www.debian.org/doc/manuals/project-history/ch-leaders.en.html[Debian leadership history].
1618
1619 Awk is frequently used to extract data from these types of files.
1620
1621 For example, try the following
1622
1623 --------------------
1624 $ awk '{ print $3 }' <DPL # month started
1625 August
1626 April
1627 January
1628 January
1629 April
1630 April
1631 March
1632 $ awk '($1=="Ian") { print }' <DPL # DPL called Ian
1633 Ian Murdock August 1993
1634 Ian Jackson January 1998
1635 $ awk '($2=="Perens") { print $3,$4 }' <DPL # When Perens started
1636 April 1996
1637 --------------------
1638
1639 Shells such as Bash can be also used to parse this kind of file.
1640
1641 For example, try the following
1642
1643 --------------------
1644 $ while read first last month year; do
1645 echo $month
1646 done <DPL
1647 ... same output as the first Awk example
1648 --------------------
1649
1650 Here, the `read` builtin command uses characters in "`$IFS`" (internal field separators) to split lines into words.
1651
1652 If you change "`$IFS`" to "`:`", you can parse "`/etc/passwd`" with shell nicely.
1653
1654 --------------------
1655 $ oldIFS="$IFS" # save old value
1656 $ IFS=':'
1657 $ while read user password uid gid rest_of_line; do
1658 if [ "$user" = "bozo" ]; then
1659 echo "$user's ID is $uid"
1660 fi
1661 done < /etc/passwd
1662 bozo's ID is 1000
1663 $ IFS="$oldIFS" # restore old value
1664 --------------------
1665
1666 (If Awk is used to do the equivalent, use "`FS=\':\'`" to set the field separator.)
1667
1668 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 <space>, <tab>, and <newline> combined.
1669
1670 Be careful about using this shell IFS tricks. Strange things may happen, when shell interprets some parts of the script as its **input**.
1671
1672 --------------------
1673 $ IFS=":," # use ":" and "," as IFS
1674 $ echo IFS=$IFS, IFS="$IFS" # echo is a Bash builtin
1675 IFS= , IFS=:,
1676 $ date -R # just a command output
1677 Sat, 23 Aug 2003 08:30:15 +0200
1678 $ echo $(date -R) # sub shell --> input to main shell
1679 Sat 23 Aug 2003 08 30 36 +0200
1680 $ unset IFS # reset IFS to the default
1681 $ echo $(date -R)
1682 Sat, 23 Aug 2003 08:30:50 +0200
1683 --------------------
1684
1685 ==== Script snippets for piping commands
1686
1687 The following scripts do nice things as a part of a pipe.
1688
1689 .List of script snippets for piping commands
1690 [grid="all"]
1691 `----------------------------------`-------------------------------------------------------------------------
1692 script snippet (type in one line) effect of command
1693 -------------------------------------------------------------------------------------------------------------
1694 `find /usr -print` find all files under "`/usr`"
1695 `seq 1 100` print 1 to 100
1696 ` | xargs -n 1 <command>` run command repeatedly with each item from pipe as its argument
1697 ` | xargs -n 1 echo` split white-space-separated items from pipe into lines
1698 ` | xargs echo` merge all lines from pipe into a line
1699 ` | grep -e <regex_pattern>` extract lines from pipe containing <regex_pattern>
1700 ` | grep -v -e <regex_pattern>` extract lines from pipe not containing <regex_pattern>
1701 ` | cut -d: -f3 -` extract third field from pipe separated by "`:`" (passwd file etc.)
1702 ` | awk \'{ print $3 }\'` extract third field from pipe separated by whitespaces
1703 ` | awk -F\'\t\' \'{ print $3 }\'` extract third field from pipe separated by tab
1704 ` | col -bx` remove backspace and expand tabs to spaces
1705 ` | expand -` expand tabs
1706 ` | sort| uniq` sort and remove duplicates
1707 ` | tr \'A-Z\' \'a-z\'` convert uppercase to lowercase
1708 ` | tr -d \'\n\'` concatenate lines into one line
1709 ` | tr -d \'\r\'` remove CR
1710 ` | sed @@@sq@@@s/\^/# /\'` add "`#`" to the start of each line
1711 ` | sed @@@sq@@@s/\.ext//g\'` remove "`.ext`"
1712 ` | sed -n -e 2p` print the second line
1713 ` | head -n 2 -` print the first 2 lines
1714 ` | tail -n 2 -` print the last 2 lines
1715 -------------------------------------------------------------------------------------------------------------
1716
1717 One-line shell script can loop over many files using `find`(1) and `xargs`(1) to perform quite complicated tasks. See <<_idioms_for_the_selection_of_files>> and <<_repeating_a_command_looping_over_files>>.
1718
1719 When using the shell interactive mode becomes too complicated, please consider to write a shell script (see <<_the_shell_script>>).
1720
1721

  ViewVC Help
Powered by ViewVC 1.1.5