File Names and File Globbing Flashcards

1
Q

File names can contain almost any character except…?

A

/ (it can’t be part of a filename since it’s the character used to separate directory name components in a relative or fully-qualified name. Since many of the more “unusual” characters are shell metacharacters, they must be protected in quotes to be used in a filename.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Although filenames can contain almost any character, that doesn’t mean that they…?

A

should.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Files that start with _____ are “hidden” files.

A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The *, ?, […], and [^…] characters can be used to match filenames, through a process commonly called…?

A

“file globbing”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Many OS’s restrict the choice and number of characters that can be used in naming files, in Linux….?

A

virtually any printable character can be used in a filename, and filenames can be of almost any length.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Linux filenames can be up to _____ characters long, excluding any directory components.

A

255

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When used in a command, an absolute or relative filename, including directory components, may be up to …..?

A

4095 characters long. (This allows names of files and directories to be very descriptive.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

You should avoid using punctuation in filenames since …?

A

the uninformed use of shell meta-characters can produce disastrous results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In general, filenames should be composed of …?

A

alphabetic and numeric characters (A-Z, a-z, 0-9) and the punctuation symbols ._-+~ (dot, underscore, dash, plus, tilde). Normally, filenames should start with an alphanumeric character or a dot. While you will encounter them with some frequency, files with embedded spaces are discouraged. (but putting quotes around a file with a space in the middle, will not cause any errors)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A file name with a leading or trailing space is …?

A

legal, (but very tricky to identify in a file listing)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

File and directory names (remember directory is a type of file) that start with a dot are…?

A

“hidden” files. (Hidden files do not appear in the directory listings produced by ls unless the special command option -a (all) is used, or unless you specify the leading dot as part of the name. This makes it possible to reduce clutter and confusion by keeping certain files “out of sight, out of mind”. Except for hiding the file, the leading dot has no other significance, and hidden files and directories can be used just like any others.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Hidden files also do not appear in…?

A

a “glob”, unless the leading dot was specifically listed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Commands like cp -r and rm -r work on entire directory sub-trees, but Linux has a more…?

A

flexible way of identifying sets of files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The bash command shell treats some of its special meta-characters as…?

A

wildcard characters. (When bash reads the command line, the shell performs a process called meta-character expansion or wildcard expansion, generates a list of filenames that match the pattern described by the wildcard expression, and then it passes the generated list on to the command. This is commonly referred to as “filename globbing”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Wildcard characters….?

A

Character Effect
* matches zero or more characters (except leading dot)
? matches exactly one character (except leading dot)
[…] matches exactly one character from the list or range
[^…] matches exactly one character not from the list or range

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The bracket wildcards represent a list of…?

A

single characters. (Thus [aeiou] matches any one vowel. A contiguous range of characters may be represented using a dash, as in [a-z] for the lowercase alphabet. A leading carat (^) negates the list, so that [^aeiou] is any character except a vowel. A “real” dash or carat can be represented by escaping the characters using a backslash (). Thus, the expression [a-z] matches a, z or a dash only. Ranges and single characters can be mixed together. The pattern [A-Za-z0-9._-+~] matches any one of the “safe” filename characters.)

17
Q

Wildcard Examples…?

A

Pattern Generates the list
* all the files in the list

*.html page1.html page2.html

page.htm page1.html page2.html page3.htm page40.htm

image?.* image1.jpeg image2.jpeg

[ps]* page1.html page2.html page3.htm page40.htm script1.pl

[^ps]* image1.jpeg image2.jpeg image10.jpeg image11.jpeg

18
Q

Many commands behave differently when there are …?

A

no files listed as opposed to when one or more files are given as part of the command. (So what happens in such a command if a wildcard pattern is used, and the pattern does not match anything so that the list of files is empty? in the special case where the bash shell attempts to expand a wildcard expression and there is no match, it leaves the original expression as part of the command.)