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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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