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