Flashcard 1: find
What is the find command used for and what is its basic syntax?
- Purpose: The
findcommand is a command-line utility used to search for files within a directory hierarchy. - Syntax:
find PATH [FLAG] [EXPRESSION]. - Functionality: It searches for files based on expressions, which can include tests like name (
-name), type (-type), or regular expressions. It can then perform various actions (-exec,-delete, etc.) on the search results. If no action is specified, it defaults to printing the file path.
Flashcard 2: grep
What does grep stand for, what is its primary function, and what are some key options?
- Stands for: Global Regular Expression Print.
- Primary Function:
grepis a text-search utility that scans files or input streams for lines containing a match to a given pattern. - Key Options:
-i: Ignores case during the search.-v: Inverts the match, selecting non-matching lines.-r: Searches recursively through directories.-c: Counts the number of matching lines instead of showing them.-E: Enables extended regular expressions, allowing for operators like|for “OR” conditions.
Flashcard 3: awk
What is awk, and what key features distinguish it from grep?
- Definition:
awkis a powerful pattern-scanning and processing language designed for advanced text manipulation. - Key Distinguishing Features:
- Field-Based Processing:
awkexcels at handling text in columns (fields). It can easily split lines based on a delimiter (like a comma or space) and process individual fields. - Scripting Language: It is a full programming language with variables, arithmetic operations, and conditional logic (
if-else), making it suitable for generating reports and complex data transformations. - BEGIN/END Blocks:
awkscripts can include aBEGINblock to execute code before processing any lines and anENDblock to execute code after all lines have been processed.
- Field-Based Processing:
Flashcard 4: sed
What does sed stand for, and what are its primary use cases?
- Stands for: Stream Editor.
- Primary Use Cases:
sedis used to perform basic text transformations on an input stream or file, line by line. It is ideal for:- Substitution: The
scommand is used to find and replace text (e.g.,s/old/new/gto replace all occurrences). - Deletion: The
dcommand deletes entire lines that match a pattern or line number. - Insertion/Appending: The
iandacommands insert text before or append text after a specified line, respectively.
- Substitution: The
Flashcard 5: diff
What is the diff command used for? What types of content can it compare?
- Purpose:
diffis a utility that compares two sources of text and shows the differences between them. - Content It Can Compare:
- Files: It compares two files line-by-line to identify which lines need to be added, removed, or changed to make the files identical.
- Directories/Folders: It can recursively compare the contents of two directories. It will report which files are unique to each directory and run a file comparison on any files that share the same name.
Flashcard 6: column
What is the function of the column command? Provide a common use case.
Back:
- Function: The
columncommand formats input text from a file or stream into well-aligned, multi-column layouts. - Common Use Case: It is frequently used to create “pretty-printed” tables from data that uses delimiters (like commas in a CSV or colons in
/etc/passwd). - Example: To format the colon-delimited /etc/passwd file into a clean table, you would use:
column -t -s ":" /etc/passwd. The-tflag creates a table, and-sspecifies the delimiter.
Flashcard 7: Efficient Tool Selection
For the following tasks, which tool (find, grep, awk, sed) is most efficient?
- Searching a file hierarchy for files modified in the last 24 hours.
find: Best for searching for files based on metadata like modification time, name, or type. - Extracting just the lines containing the word “
Error” from a log file.grep: Perfect for simple line extraction based on a pattern. - Changing every instance of “
cat” to “dog” in a text file.sed: Its primary strength is stream editing, making it ideal for find-and-replace operations. - Calculating the average value of the 3rd column in a data file and printing only the result.
awk: The only one of the four with built-in arithmetic and columnar processing capabilities, making it the right choice for calculations on structured text data.
Flashcard 8: Practical Skills Overview
Match the task to the primary tool (find, grep, awk, sed, diff, column).
- Text manipulation & substitution
- Text formatting into tables
- Character/word extraction from a line
- File searching in a hierarchy
- Comparing folder contents
- Column extraction from a file
Back:
- Text manipulation & substitution:
sed - Text formatting into tables:
column - Character/word extraction from a line:
greporawk - File searching in a hierarchy:
find - Comparing folder contents:
diff - Column extraction from a file:
awk