Home >> List Directory Only in Bash

Tag: linux

List Directory Only in Bash

To list directory only in Bash using ls use:

ls -d */

from bash help:

-d, –directory will list directories themselves, not their contents

and */ means match all files and sub directories.

so to list all sub directories under /dir/subdir/, you can use:

ls -d /dir/subdir/*/

Similarly, to list all directories including hidden one use:

ls -d .*/ */

Password Protect Directory With .htaccess

To create authentication using htaccess do the following:

  1. Open up console and type htpasswd -c .htpasswd username to create .htpasswd file.
    or alternatively you can search for .htpasswd generator online
  2. Put the newly created .htpasswd file somewhere hidden.
  3. Create .htaccess file with the following content:
    AuthType Basic
    AuthName "Any title you want"
    AuthUserFile /path/to/.htpasswd
    require valid-user
  4. Put the .htaccess file inside the directory you want to password protect