I know you can use the find
command for this simple job, but I got an assignment not to use find
or ls
and do the job. How can I do th
Try using
tree -d
The du
command will list subdirectories recursively.
I'm not sure if empty directories get a mention, though
Based on this answer; use shell options for the desired globbing behaviour:
**
with globstar
(Bash 4.0 or newer)dotglob
**/*/
if there is no match with nullglob
and then use printf with the %q formatting directive to quote directory names with special characters in them:
shopt -s globstar dotglob nullglob
printf '%q\n' **/*/
so if you have directories like has space
or even containing a newline, you'd get output like
$ printf '%q\n' **/*/
$'has\nnewline/'
has\ space/
with one directory per line.
Technically, neither find nor ls are used by find2perl|perl or File::Find directly.
$ find2perl -type d | perl $ perl -MFile::Find -e'find(sub{-d&&print"$File::Find::name\n"},".")'