Bash Listing Files in a Directory

From NovaOrdis Knowledge Base
Revision as of 20:16, 20 September 2019 by Ovidiu (Talk | contribs)

Jump to: navigation, search

Internal

Overview

To list files:

local dir=...

for f in ${dir}/*; do
  [[ -f ${f} ]] && echo -n "$(basename ${f}) "
done

To list directories, replace -f with -d.