2

This has probably answered before, but I cannot find it.

How do I count the files and directories in a directory without including subdirectories? Also, hidden files should be ignored (because this folder is a git repo).

More precisely, I need an if clause, that the current folder only has one file (namely "script.sh") and no sub-folders with the exception of .git/ .

How can I do this in Bash?

EDIT: In contrast to Recursively count specific files BASH, I want to ignore the .git folder and I do not want to count files and folders in subfolders.

Community
  • 1
  • 1
Revan
  • 2,072
  • 4
  • 26
  • 42

1 Answers1

2

find should help:

if [ "$(cd /some/dir && find * -maxdepth 0 -type f)" == "script.sh" ]; then

* will list only non hidden files and maxdepth won't search subdirectories.

Joao Morais
  • 1,885
  • 13
  • 20