Bird
0
0

What will this PowerShell on Linux script output?

medium📝 Command Output Q5 of 15
PowerShell - Cross-Platform PowerShell
What will this PowerShell on Linux script output?
$files = Get-ChildItem -Path /tmp
$files.Count
ANumber of files and directories in /tmp
BList of file names in /tmp
CError because Count property is invalid
DEmpty output if /tmp is empty
Step-by-Step Solution
Solution:
  1. Step 1: Assign directory contents to variable

    Get-ChildItem lists files and directories in /tmp; stored in $files as an array of objects.
  2. Step 2: Use Count property to get number of items

    $files.Count returns the number of objects in the array, i.e., total files and directories.
  3. Final Answer:

    Number of files and directories in /tmp -> Option A
  4. Quick Check:

    Count property = number of items [OK]
Quick Trick: Use .Count to get number of items in a collection [OK]
Common Mistakes:
  • Expecting file names instead of count
  • Thinking Count is invalid on Linux
  • Ignoring that Count returns zero if directory empty

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes