Write a Linux command line to give the names of the sub-directories in just the current working directory (no recursion).
Also, I've decided to reclaim my weekends, so these daily Linux challenges will henceforth be a Mon-Fri affair. I'll check in with the answer to this question on Monday. Everybody enjoy your weekends!
#Linux #DFIR #CommandLine #Trivia
Chiasm likes this.
Hal Pomeranz reshared this.
Füsilier Breitlinger
in reply to Hal Pomeranz • • •echo */
.But if you want hidden directories, too, then something like
find . -maxdepth 1 -type d
.silverwizard
in reply to Hal Pomeranz • •find . -maxdepth 1 -type d
Or on my machines:
lsdirs
Chiasm likes this.
Füsilier Breitlinger
in reply to Hal Pomeranz • • •Alternative solutions:
tree -daL 1
perl -wle 'opendir my $dh, "." or die $!; for (sort readdir $dh) { print if -d }'
ghc -e 'import System.Directory' -e 'import Control.Monad' -e 'listDirectory "." >>= filterM doesDirectoryExist >>= mapM_ putStrLn'
Beej 💾
in reply to Hal Pomeranz • • •find . -maxdepth 1 -type d
ls -l | grep ^d
James Blanding
in reply to Hal Pomeranz • • •Scott Senffner
in reply to Hal Pomeranz • • •smoot
in reply to Hal Pomeranz • • •smoot
in reply to Hal Pomeranz • • •Hal Pomeranz
in reply to Hal Pomeranz • • •Last Friday's daily Linux command line trivia asked for a command line to print out the names of the subdirectories of the current directory, but NOT to recurse and show all subdirectories below this point. There are lots of ways to accomplish this, and I was curious to see if I would learn any new ones. Turns out I did.
First, there's a classic solution using the "find" command (props to @barubary for being the first to mention it):
find . -maxdepth 1 -type d
Here we're using the "maxdepth" control to only show directories ("-type d") in the current directory.
There are also solutions using "ls". @beejjorgensen checked in with one of my favorites:
ls -lA | grep ^d
In the detailed listing format ("ls -l"), the file type is the first character on the line. Directories are denote with a "d".
@llutz checked in with another "ls" solution that I hadn't considered before:
ls -d .*/ */
@barubary points out that "echo" would work here too, instead of "ls -d". The trailing "/" after the wildcards matches only directories. Don't forget ".*/" to match hidden directories!
@barubary suggested a solution using the "tree" command. Strictly speaking, the "tree" package is not part of the core Linux OS, so it falls outside the rules I've set for myself. But here's the solution:
tree -daL 1
This means show all files ("-a") including hidden files, but display directories only ("-d"). "-L 1" is like the "-maxdepth" control on "find"-- only display output from the current directory.
#Linux #DFIR #CommandLine #Trivia
Hal Pomeranz reshared this.
James Blanding
in reply to Hal Pomeranz • • •