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