Find examples


From man find:

The find utility recursively descends the directory tree for each path listed, evaluating an expression … in terms of each file in the tree.

Examples

Given the following directory tree:

$ tree
.
├── file1.txt
├── file2.txt
├── folder
│   └── file3
└── tmp
    └── file4

To list all files and directories in your current working directory:

$ find .
.
./file1.txt
./file2.txt
./folder
./folder/file3
./tmp
./tmp/file4

To list only files:

$ find . -type f
./file1.txt
./file2.txt
./folder/file3
./tmp/file4

To list only directories:

$ find . -type d
.
./folder
./tmp

To list all files with extension .txt:

$ find . -type f -name '*.txt'
./file1.txt
./file2.txt

To list all files in folder:

$ find folder -type -f
folder/file3

To list all files except those in tmp:

$ find . -type f ! -path './tmp/*'
./file1.txt
./file2.txt
./folder/file3

To list all files except those in folder and tmp:

$ find . -type f ! -path './tmp/*' ! -path './folder/*'
./file1.txt
./file2.txt