Cat, Find, Diff options Flashcards
(17 cards)
1
Q
What does cat -n do?
A
- Numbers all output lines starting from 1
- Displays line numbers before each line of content
- Useful for referencing specific lines in files or debugging
2
Q
How does cat -b differ from cat -n?
A
- Numbers only non-blank lines (-b) while -n numbers all lines
- Skips empty lines when counting and displaying line numbers
- Better for focusing on actual content lines
3
Q
What is cat -A used for?
A
- Shows all non-printing characters including tabs, line endings, and control characters
- Displays tabs as ^I and line endings as $
- Essential for debugging whitespace and formatting issues
4
Q
When would you use cat -s?
A
- Squeezes multiple consecutive blank lines into single blank line
- Reduces excessive whitespace in output
- Useful for cleaning up formatted text with too much spacing
5
Q
What does cat -T accomplish?
A
- Displays tab characters as ^I (visible tabs)
- Helps identify tab vs space issues in code and configuration files
- Subset of -A option focused specifically on tabs
6
Q
What does diff -u show?
A
- Unified diff format showing context around changes
- Displays changed lines with surrounding context for better understanding
- Standard format used by version control systems like Git
7
Q
How does diff -i affect comparison?
A
- Performs case-insensitive comparison of files
- Ignores differences between uppercase and lowercase letters
- Useful when case variations shouldn’t be considered differences
8
Q
What is diff -w used for?
A
- Ignores whitespace differences (spaces, tabs) when comparing
- Focuses on content changes rather than formatting differences
- Helpful for comparing code files with different indentation
9
Q
When would you use diff -r?
A
- Recursively compares directories and their subdirectories
- Shows differences in file contents and directory structure
- Essential for comparing entire directory trees or project folders
10
Q
What does diff -q accomplish?
A
- Quiet mode - only reports whether files differ, not the actual differences
- Returns brief message if files differ or no output if identical
- Useful in scripts when you only need to know if files match
11
Q
How does diff –side-by-side work?
A
- Displays files in two columns side by side for easy comparison
- Shows matching lines aligned and different lines highlighted
- More visual format for manual file comparison
12
Q
What does find -name do?
A
- Searches for files and directories by exact name match
- Case-sensitive pattern matching for filenames
- Example: find /home -name “*.txt” finds all .txt files
13
Q
How does find -iname differ from find -name?
A
- Case-insensitive name search
- Matches filenames regardless of upper/lowercase letters
- Example: find -iname “*.PDF” matches .pdf, .PDF, .Pdf files
14
Q
What is find -type used for?
A
- Searches for specific file types (f=file, d=directory, l=link)
- Example: find /var -type f finds only regular files
- Essential for filtering results by object type
15
Q
When would you use find -size?
A
- Searches for files based on size criteria
- Uses +/- for greater/less than: find -size +100M finds files larger than 100MB
- Useful for finding large files consuming disk space
16
Q
What does find -mtime accomplish?
A
- Searches by modification time in days
- +n means older than n days, -n means newer than n days
- Example: find -mtime -7 finds files modified in last 7 days
17
Q
How does find -exec work?
A
- Executes command on each found file
- {} represents the found filename, \; terminates the command
- Example: find -name “*.tmp” -exec rm {} \; deletes all .tmp files