section 7 - IO redirection, piping, regex, archiving, searching, extraction Flashcards
xargs
enables a user to generate command line options from files, or another program’s output. Useful if you want to use same command on a list of files.
What does the following re-director operation do?
>
Creates a new file containing standard output.
If the specified file already exists, it is overwritten with whatever the program exports.
Can be useful when there are too many errors shown on screen, allows you to only see the standard output.
What does the following re-director operation do?
»
Appends the existing output to an existing file.
Does not overwrite an existing file, only adds to the bottom of the file.
What does the following re-director operation do?
2>
Creates a new file containing any standard errors.
If the specified file already exists, it is overwritten with whatever errors the program exports.
What does the following re-director operation do?
2»
Appends standard error to an existing file.
Does not overwrite existing files, only appends.
What does the following re-director operation do?
<
Sends the content of a specified file as INPUT back into the
standard input.
What does the following re-director operation do?
«
Accepts text on the following lines as standard input.
Basically allows typed commands to be used for input rather than just reading from a file.
What does the following re-director operation do?
<>
Specified file can be used for standard input and standard output; allows the program to actively read and write to the same file as needed.
grep
searches for a pattern that defines a set of strings
&>
Creates a new file that contains both the standard output and standard error.
Will overwrite specified file if it already exists.
How would you do a search for the keyword “apple” in the /etc directory, while also discarding any standard errors that would appear on screen?
grep apple /etc/* 2> /dev/null
the /dev/null file acts as a trash bin and discards any output
tar
Archives multiple files into a single archive file, the original files remain on the disk.
tarball
compressed tar archive to save space. Can be archived with tar then compressed with a zip program:
gzp + tar = .tgz
bzip2 + tar = .tbz/.tb2/.tbz2
xz + tar = .txz
zip
gzip (.gz) gunzip
bzip2 (.bz2) bunzip2
xz (.xz) unxz
used to compress individual files, must be uncompressed first before a program can read it.
regular expression grep
grep -E