Bash pattern to match all files but directories

bashdirectoryfilenameswildcards

In bash, how do I specify a pattern that matches everything but subdirectories in current directory. Given that the pattern */ matches all the subdirectories, I tried (with extglob turned on):

$ echo !(*/)

But it didn't work.

Best Answer

find . -maxdepth 1 ! -type d

Details:

  • -maxdepth 1 restricts the search to the current directory

  • ! -type d eliminates directories