For me, it is the switches and arguments. I hate pure memorization, and recoil at remembering even the most basic ones.
Fortunately for people like me, there is help. Man pages, short for manual pages, are documentation for many of the terminal commands available.
Help Is Only a ‘man’ Away
Use the terminal command ‘man’, with the command you want to learn about as an argument, to access that command’s man page.
For example, for the ‘ls’ command, I would type: ‘man ls’ into the terminal.
Man pages are usually lengthy and don’t fit on one “page” of the terminal window. The first part of the man page appears upon execution of the command. To see the rest of the man page, you must advance the output using the Enter key or the space bar. The Enter key advances the output by a single line, the space bar by an entire “page.”
To close a man page, press the ‘q’ key.
Here is a copy of the entire output of ‘man ls’.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
LS(1) User Commands LS(1)
NAME
ls – list directory contents
SYNOPSIS
ls [OPTION]… [FILE]…
DESCRIPTION
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuSUX nor –sort.
Mandatory arguments to long options are mandatory for short options
too.
-a, –all
do not hide entries starting with .
-A, –almost-all
do not list implied . and ..
–author
print the author of each file
-b, –escape
print octal escapes for nongraphic characters
–block-size=SIZE
use SIZE-byte blocks
-B, –ignore-backups
do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last modification of
file status information) with -l: show ctime and sort by name
otherwise: sort by ctime
-C list entries by columns
–color[=WHEN]
control whether color is used to distinguish file types. WHEN
may be ‘never’, ‘always’, or ‘auto’
-d, –directory
list directory entries instead of contents, and do not derefer-
ence symbolic links
-D, –dired
generate output designed for Emacs’ dired mode
-f do not sort, enable -aU, disable -lst
-F, –classify
append indicator (one of */=@|) to entries
–format=WORD
across -x, commas -m, horizontal -x, long -l, single-column -1,
verbose -l, vertical -C
–full-time
like -l –time-style=full-iso
-g like -l, but do not list owner
-G, –no-group
inhibit display of group information
-h, –human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
–si likewise, but use powers of 1000 not 1024
-H, –dereference-command-line
follow symbolic links listed on the command line
–dereference-command-line-symlink-to-dir
follow each command line symbolic link
that points to a directory
–indicator-style=WORD append indicator with style WORD to entry names:
none (default), classify (-F), file-type (-p)
-i, –inode
print index number of each file
-I, –ignore=PATTERN
do not list implied entries matching shell PATTERN
-k like –block-size=1K
-l use a long listing format
-L, –dereference
when showing file information for a symbolic link, show informa-
tion for the file the link references rather than for the link
itself
-m fill width with a comma separated list of entries
-n, –numeric-uid-gid
like -l, but list numeric UIDs and GIDs
-N, –literal
print raw entry names (don’t treat e.g. control characters spe-
cially)
-o like -l, but do not list group information
-p, –file-type
append indicator (one of /=@|) to entries
-q, –hide-control-chars
print ? instead of non graphic characters
–show-control-chars
show non graphic characters as-is (default unless program is
‘ls’ and output is a terminal)
-Q, –quote-name
enclose entry names in double quotes
–quoting-style=WORD
use quoting style WORD for entry names: literal, locale, shell,
shell-always, c, escape
-r, –reverse
reverse order while sorting
-R, –recursive
list subdirectories recursively
-s, –size
print size of each file, in blocks
-S sort by file size
–sort=WORD
extension -X, none -U, size -S, time -t, version -v
status -c, time -t, atime -u, access -u, use -u
–time=WORD
show time as WORD instead of modification time: atime, access,
use, ctime or status; use specified time as sort key if
–sort=time
–time-style=STYLE
show times using style STYLE: full-iso, long-iso, iso, locale,
+FORMAT
FORMAT is interpreted like ‘date’; if FORMAT is FORMAT1
FORMAT2, FORMAT1 applies to non-recent files and FORMAT2 to
recent files; if STYLE is prefixed with ‘posix-’, STYLE takes
effect only outside the POSIX locale
-t sort by modification time
-T, –tabsize=COLS
assume tab stops at each COLS instead of 8
-u with -lt: sort by, and show, access time with -l: show access
time and sort by name otherwise: sort by access time
-U do not sort; list entries in directory order
-v sort by version
-w, –width=COLS
assume screen width instead of current value
-x list entries by lines instead of by columns
-X sort alphabetically by entry extension
-1 list one file per line
SELinux options:
–lcontext
Display security context. Enable -l. Lines will probably be
too wide for most displays.
-Z, –context
Display security context so it fits on most displays. Displays
only mode, user, group, security context and file name.
–scontext
Display only security context and file name.
–help display this help and exit
–version
output version information and exit
SIZE may be (or may be an integer optionally followed by) one of fol-
lowing: kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T,
P, E, Z, Y.
By default, color is not used to distinguish types of files. That is
equivalent to using –color=none. Using the –color option without the
optional WHEN argument is equivalent to using –color=always. With
–color=auto, color codes are output only if standard output is con-
nected to a terminal (tty).
AUTHOR
Written by Richard Stallman and David MacKenzie.
REPORTING BUGS
Report bugs to <[email protected]>.
COPYRIGHT
Copyright © 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
SEE ALSO
The full documentation for ls is maintained as a Texinfo manual. If
the info and ls programs are properly installed at your site, the com-
mand
info coreutils ls
should give you access to the complete manual.
ls (coreutils) 5.2.1 March 2004 LS(1)
|
Deciphering a “man page”
Unfortunately, not all man pages conform to the same style guidelines. There is no central authority producing man pages, it is up to each command’s developer(s) to create and style them. However, most are very similar to the example above. So let’s use that man page to find out how to deal with arguments and switches.
Arguments & Order of Operations
Often times, what you will want to know is what arguments you need, and what order they go in. For that, you want to look under the synopsis section.
1
2
3
|
SYNOPSIS
ls [OPTION]… [FILE]…
|
The synopsis lists all the possible arguments for a command, as well as the order to place them in. In the case of ‘ls’, our argument is “FILE”. “OPTION” is where you place switches.
In a man page’s synopsis, when something is in square brackets, it means that it is an optional addition. Since both “FILE” and “OPTION” are in square brackets, the ‘ls’ command does not need any switches or arguments to work; adding them is optional.
When the argument or switch is followed by ellipses (“…”), it means that you can put more than one. In other words, ‘ls -l -a /home/john /home/bob’ is perfectly acceptable. We have more than one switch, and more than one argument even though the man page only shows a place for one. Ellipses means multiple are accepted.
Now let’s look at the SYNOPSIS of another command, ‘cp’.
1
2
3
4
5
|
SYNOPSIS
cp [OPTION]… SOURCE DEST
cp [OPTION]… SOURCE… DIRECTORY
cp [OPTION]… –target-directory=DIRECTORY SOURCE…
|
As shown by the three entries under synopsis, ‘cp’ has more than one possible arrangement of arguments. The first one you are familiar with if you’ve read our guide to the terminal. The brackets and ellipses surrounding OPTION tell us that we can use multiple switches, but none are needed. There are then two arguments, SOURCE and DEST. SOURCE is the source file or directory, DEST is the destination file or directory.
But if we look at the second entry, there are some changes. First, SOURCE now has ellipses indicating that multiple sources are acceptable. Second, DEST has changed to DIRECTORY indicating that we can no longer specify a specific file as the destination, it must be a directory. ‘cp file1.txt file2.txt file3.txt /home/john/myfiles/’ is a valid example of this. We have 3 source files all going to the myfiles directory.
And the third entry gives us yet another option. The third choice can still use multiple switches; however, one switch is required. This long-form switch, ‘target-directory’, indicates the destination for what you are copying. Then you must have one or more source files. An example of this form is ‘cp –target-directory=/home/john/myfiles/ file4.txt file5.txt file6.txt. ‘. This copies those three files to the myfiles directory.
Rebellion!
Despite what the man pages say, switches do not need to go before arguments. You can move the switches to the end, or, if you have multiple switches, mix them in with the arguments. Occasionally, rearranging them helps with readability, particularly for long commands. However, this is optional.
It’s Raining Switches
Now let’s talk about finding available switches. If you scroll down a man page, there is usually a list of switches for the command. I am going to extract a small segment of the ‘ls’ command’s list here so we can talk about it. You can see the whole list up above.
1
2
3
4
5
6
|
-I, –ignore=PATTERN
do not list implied entries matching shell PATTERN
-k like –block-size=1K
-l use a long listing format
|
Let’s begin by looking at the most complex entry, ‘-I, –ignore=PATTERN’. This switch can be expressed two ways, either the short form of ‘-I’, or the long form of ‘–ignore’. Both do the same thing, you can choose your favorite.
This entry indicates that the switch requires an argument with the “=PATTERN.” Recall that with short switches, the argument is provided with a space, then the argument. And the long-form switch is an equal sign and then the argument. When a switch has both a short-form and a long-form, the man page shows the argument on the long-form only. If there is only a short-form switch, the argument is shown with the proper space, then argument notation. It would look like this:
1
2
|
-I PATTERN
do not list implied entries matching shell PATTERN
|
After each switch and their arguments, there is a short description of what the switch does. Sometimes these descriptions are helpful, sometimes they aren’t. If they aren’t helping, you can either experiment with the switch until you find what works, or ask Google for help.
man page Limitations
There are some Linux users who believe man pages are fantastic just as they are. I am not one of them. They are difficult to browse and searching, while possible, is limited. If you actually wish to read a man page, as opposed to quickly skimming to refresh your memory, I recommend using the Internet.
There are many websites with copies of most man pages. An appropriately phrased Google search will yield pages of results. Or, you can simply visit http://linux.die.net/man/ and use their search feature.
Whether you are a veteran of the terminal, or a newcomer, you will probably need to consult man pages on occasion. They aren’t perfect, and you need a bit of skill to get the most out of them, but they are quickly and easily accessible. So add the ‘man’ command to your terminal toolbox, and try it out by running the command ‘man man’ in your terminal!
If you have any other tips for browsing man pages, or have questions, make sure to leave a comment!