Introduction to UNIX Part 4

Wildcards, conventions, and manuals

Summary

Command Action
* match any number of characters
? match one character
man command read the online manual page for a command
whatis command brief description of a command
apropos keyword match commands with keyword in their man pages

Wildcards

The * wildcard

The character * is called a wildcard, and will match against zero or more characters (a-z, 0-9, symbols, etc) in a file or directory name. For example, in your unixstuff directory, type:

1% ls list*

This will list all files in the current directory which start with ’list' Now try typing:

1% ls *list

This will list all files in the current directory which end with ’list'

The ? wildcard

The character ? would match exactly one character (as opposed to the * from above, which matches zero or more). This means that ?ouse would match files like douse and louse, but not arouse. Try typing

1% ls ?list

Filename conventions

We should note here that a directory is merely a special type of file. So the rules and conventions for naming files apply also to directories.

In naming files, characters with special meanings such as / \ * & %, should be avoided. Also, avoid using spaces within names. The safest way to name a file is to use only alphanumeric characters, that is, letters and numbers, together with _ (underscore) and . (dot).

Good filenames Bad filenames
project.txt project
my_program.c my program.c
bob_and_tom.doc bob & tom.doc

File names conventionally start with a lower-case letter, and may end with a dot followed by an extension (a group of not more than three (3) letters indicating the contents of the file). For example, all files consisting of C code may be named with the ending .c, for example, prog1.c . Then in order to list all files containing C code in your home directory, you need only type ls *.c in that directory. Some other common examples of extensions are:

Extension Mapping
.pl Perl code
.py Python code
.rb Ruby code
.txt Plain text file
.jpg JPEG graphic
.pdf PDF document (Adobe)
.mp3 MPEG 3 format audio file

Getting Help

Man Pages

There are manuals which provide detailed information about most UNIX commands. The man (manual) pages tell you which options a particular command can take, and how each option augments the behaviour of the particular command. Type man command to read the man page for a particular command.

For example, to find out more about the wc(1) - word count command, type

1% man wc

You should see something that looks similar to this:

 1WC(1)                     BSD General Commands Manual                    WC(1)
 2
 3NAME
 4     wc -- word, line, character, and byte count
 5
 6SYNOPSIS
 7     wc [-clmw] [file ...]
 8
 9DESCRIPTION
10     The wc utility displays the number of lines, words, and bytes contained
11     in each input file, or standard input (if no file is specified) to the
12     standard output.  A line is defined as a string of characters delimited
13     by a <newline> character.  Characters beyond the final <newline> charac-
14     ter will not be included in the line count.
15
16     A word is defined as a string of characters delimited by white space
17     characters.  White space characters are the set of characters for which
18     the iswspace(3) function returns true.  If more than one input file is
19     specified, a line of cumulative counts for all the files is displayed on
20     a separate line after the output for the last file.
21
22     The following options are available:
23
24     -c      The number of bytes in each input file is written to the standard
25:

You may have noticed on the top line of the wc(1) man page, it lists the name of the command, followed by parentheses and a number. This number specifies which section of the manual the page belongs to. There are 8 sections of the manual

Section Description
1 General commands
2 System calls
3 Library functions, covering in particular the C standard library
4 Special files (usually devices, those found in /dev) and drivers
5 File formats and conventions
6 Games and screensavers
7 Miscellanea
8 System administration commands and daemons

Most of the time, simply typing man command will get you the information you are looking for. In some cases, there are overlapping entries and you will need to specify the section you wish to search. More information on this can be found (of course) in the man(1) man page.

whatis

whatis searches a set of database files containing short descriptions of system commands for keywords and displays the result on the standard output. Only complete word matches are displayed.

1% whatis wc

Alternatively, Apropos

1% apropos keyword

will give you the commands with keyword in their manual page header. For example, try typing

1% apropos copy

Copyright

Comments