Examining Files Flashcards
The “file” command displays a..?
file’s type.
The “cat” command displays a…?
file’s contents.
The “more” and “less” commands “page” through….?
a file, one screen at a time.
The “head” and “tail” commands display…?
the first or last few lines of a file.
In the X graphical environment, “nautilus” can be used to…?
examine text files.
The contents of any given file might be…?
ASCII (plain text, HTML, shell script, program source code, etc.) or binary (complied executable, compressed archive, audio, etc.).
It is a good idea to check the file type before using commands that work on ASCII because…?
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.
file [OPTIONS][FILE….]…?
Tests FILE(s) to determine the file type, and displays results to standard output.
cat [OPTIONS] [FILE…]…?
Concatenate FILE(s) to standard output.
cat command switches…?
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
the cat command, when used for viewing files, simply displays…?
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.)
Both more and less are designed for viewing text files on screen. Their use is quite similar except that…?
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.)
more [OPTIONS] [FILE…] …?
Displays FILE(s) to standard output one screen full at a time under keyboard control.
“more” command switches…?
Option Action
- c Clear screen and redraw, instead of scrolling
- s “Squeeze” multiple adjacent blank lines into a single blank line
less [OPTIONS] [FILE…] …?
Displays FILE(s) to standard output one screen full at a time under keyboard control.
“less” command switches…?
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
less (more) navigation commands…?
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)
One feature of the less pager relies on…?
a standard Unix concept called pipes.
Pipes act like redirection, in that the output of a command is redirected…?
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.
When running a command that produces a lot of output, the output of the command can be piped into…?
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.)
The _____ command allows you to see the first few lines of the file.
Head.
head [OPTIONS] [FILE…] …?
Print the first 10 lines of each FILE to standard output.
“head” command switches…?
Switch Effect
- num, -n num Print first num lines (default is 10).
- q Suppress headers giving file names
If given more than one filename as arguments, head displays…?
the first few lines of each file individually, separated by a header displaying the filename.
tail [OPTIONS] [FILE…] …?
Complementing head, the tail command prints the last 10 lines of each FILE to standard output.
“tail” command switches.
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
The tail command has another, very useful, option: the -f (follow) option. With this option, tail will display…?
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.
What type of file is /usr/bin/run-parts?
A Bash (Bourne-Again) shell script
What type of file is /dev/log?
A socket.
What command woudl act the same as cp a.txt b.txt assuming the file b.txt does not exist?
cat a.txt > b.txt