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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With