Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash find directories

People also ask

How do I list all directories in Bash?

Use the ls Command to List Directories in Bash. We use the ls command to list items in the current directory in Bash. However, we can use */ to print directories only since all directories finish in a / with the -d option to assure that only the directories' names are displayed rather than their contents.

How do I get list of directories?

Linux or UNIX-like system use the ls command to list files and directories. However, ls does not have an option to list only directories. You can use combination of ls command, find command, and grep command to list directory names only. You can use the find command too.

How do I find a specific directory in Linux?

The ls command is used to list files or directories in Linux and other Unix-based operating systems. Just like you navigate in your File explorer or Finder with a GUI, the ls command allows you to list all files or directories in the current directory by default, and further interact with them via the command line.


find . -mindepth 1 -maxdepth 1 -type d

In the particular case you are looking for a 1) directory which you know the 2) name, why not trying with this:

find . -name "octave" -type d

try to use

find $path -type d ?

for current directory

find . -type d


find ./path/to/directory -iname "test" -type d

I found this very useful for finding directory names using -iname for case insensitive searching. Where "test" is the search term.


Following lines may give you an idea...what you are asking for

#!/bin/bash

for FILE in `ls -l`
do
    if test -d $FILE
    then
      echo "$FILE is a subdirectory..."
    fi
done

You may have a look into bash 'for' loop.