Bash Listing Files in a Directory and Testing whether Specific Files Exist in Directories

From NovaOrdis Knowledge Base
Revision as of 20:16, 20 September 2019 by Ovidiu (talk | contribs)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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.