Examining Files Flashcards

1
Q

The “file” command displays a..?

A

file’s type.

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

The “cat” command displays a…?

A

file’s contents.

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

The “more” and “less” commands “page” through….?

A

a file, one screen at a time.

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

The “head” and “tail” commands display…?

A

the first or last few lines of a file.

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

In the X graphical environment, “nautilus” can be used to…?

A

examine text files.

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

The contents of any given file might be…?

A

ASCII (plain text, HTML, shell script, program source code, etc.) or binary (complied executable, compressed archive, audio, etc.).

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

It is a good idea to check the file type before using commands that work on ASCII because…?

A

Attempting to use them with binary files can lead to problems ranging from the mildly irritating (screens full of strange characters flashing by) to the more significant (locking the terminal display). This is because binary files can contain arbitrary binary codes, and some of these codes have special meaning when being (mis)interpreted as ASCII text.

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

file [OPTIONS][FILE….]…?

A

Tests FILE(s) to determine the file type, and displays results to standard output.

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

cat [OPTIONS] [FILE…]…?

A

Concatenate FILE(s) to standard output.

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

cat command switches…?

A

Switch Effect

  • A Show all characters, including control characters and non-printing characters
  • s “ Squeeze” multiple adjacent blank lines into a single blank line
  • n Number lines of output
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

the cat command, when used for viewing files, simply displays…?

A

the contents all at once (Large files scroll by to quickly to read, making cat most suitable for files with less than a screen of text.)

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

Both more and less are designed for viewing text files on screen. Their use is quite similar except that…?

A

the modern less command has a few extra features, such as responding correctly to [PgUp], [PgDn] and navigation arrow keystrokes correctly. After all, less is more. (It is especially important to be familiar with less because other tools (such as man) use it behind the scenes to provide paging capabilities.)

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

more [OPTIONS] [FILE…] …?

A

Displays FILE(s) to standard output one screen full at a time under keyboard control.

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

“more” command switches…?

A

Option Action

  • c Clear screen and redraw, instead of scrolling
  • s “Squeeze” multiple adjacent blank lines into a single blank line
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

less [OPTIONS] [FILE…] …?

A

Displays FILE(s) to standard output one screen full at a time under keyboard control.

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

“less” command switches…?

A

Option Action

  • c Clear screen and redraw, instead of scrolling
  • r Display raw control characters
  • s “Squeeze” multiple adjacent blank lines into a single blank line
17
Q

less (more) navigation commands…?

A
Command	more?	Action
	Yes	move ahead one full screen
[PgDn]	No	move ahead one full screen
b	Yes	move back one full screen
[PgUp]	No	move back one full screen
[DnArrow]	No	move ahead one line
[UpArrow]	No	move back one line
/text	Yes	search forward for text
?text	No	search backward for text
n	Yes	repeat last search
N	No	repeat last search, but in opposite direction
q	Yes	quit
h	Yes	help (which introduces many new commands)
18
Q

One feature of the less pager relies on…?

A

a standard Unix concept called pipes.

19
Q

Pipes act like redirection, in that the output of a command is redirected…?

A

somewhere other than a terminal. With redirection (using >), the output gets redirected to a specified file. When piping, the output of one command gets redirected into the input of another command. The bash shell uses the | character (usually found above the RETURN key) on construct pipes.

20
Q

When running a command that produces a lot of output, the output of the command can be piped into…?

A

less. (Rather than getting dumped into a terminal, the output can be browsed like a file, paging down, paging up, and searching. When finished, quit less, and the output disappears.)

21
Q

The _____ command allows you to see the first few lines of the file.

A

Head.

22
Q

head [OPTIONS] [FILE…] …?

A

Print the first 10 lines of each FILE to standard output.

23
Q

“head” command switches…?

A

Switch Effect

  • num, -n num Print first num lines (default is 10).
  • q Suppress headers giving file names
24
Q

If given more than one filename as arguments, head displays…?

A

the first few lines of each file individually, separated by a header displaying the filename.

25
Q

tail [OPTIONS] [FILE…] …?

A

Complementing head, the tail command prints the last 10 lines of each FILE to standard output.

26
Q

“tail” command switches.

A

Switch Effect

  • num, -n num Print last num lines (default is 10).
  • q Suppress headers giving file names
  • f Keep file open, and print new lines as appended
27
Q

The tail command has another, very useful, option: the -f (follow) option. With this option, tail will display…?

A

the last lines of the file, and then “waits” and continues to display any new lines as they are added to the file. This is often used to monitor system log files in real time. Once started with the option, the command prompt does not return. Instead the tail -f stays active and will continue to display new lines as they occur until CTRL+C is pressed.

28
Q

What type of file is /usr/bin/run-parts?

A

A Bash (Bourne-Again) shell script

29
Q

What type of file is /dev/log?

A

A socket.

30
Q

What command woudl act the same as cp a.txt b.txt assuming the file b.txt does not exist?

A

cat a.txt > b.txt