Which command is suitable to list out all the directories in the working directory, in linux/unix environment? A. 𝐼𝑠 − 1|𝑔𝑟𝑒𝑝 𝑑

190. Which command is suitable to list out all the directories in the working directory, in linux/unix
environment?
A. 𝐼𝑠 − 1|𝑔𝑟𝑒𝑝 𝑑

B. 𝑔𝑟𝑒𝑝 𝑑

|𝐼𝑠 − 1
C. 𝐼𝑠 − 1|𝑔𝑟𝑒𝑝 𝑑

D. 𝐼𝑠|𝑔𝑟𝑒𝑝 𝑑𝑖�


Explanation:

To list only directories from the current working directory in a Unix/Linux shell, you can use:

bash
ls -l | grep ^d

Breakdown of the Command:

  • ls -l:

    • Lists files and directories in long format (detailed view), where each line starts with the file type (d for directory, - for file, etc.)

  • grep ^d:

    • Filters only the lines that start (^) with d, i.e., directories.

This way, only directories are listed from the output of ls -l.


Why Other Options Are Incorrect:

  • B. grep d^ | ls -l: Incorrect syntax and reversed order – grep cannot pipe into ls.

  • C. Repeats A: Appears to be a typo/duplicate.

  • D. ls | grep dir: This command assumes directory names contain “dir,” which is not general or reliable.


Conclusion:

To reliably list only directories, the command:

bash
ls -l | grep ^d

is the most suitable.

Correct Answer: A. ls -l | grep ^d

8 Comments
  • Suman bhakar
    April 15, 2025

    Best explanation

  • Khusbi yadav
    April 17, 2025

    👍

  • Yashika Rajoriya
    April 17, 2025

  • Shalu Choudhary
    April 17, 2025

    👍

    • Prami Masih
      April 22, 2025

      Done sir ji

  • SEETA CHOUDHARY
    April 22, 2025

    Done ✅

  • yogesh sharma
    April 29, 2025

    Sir ye wala upr se gya 😅

  • Komal Sharma
    May 12, 2025

    Done ✅

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest Courses