find

Find may be used to find files or directories in the file system. find is by default recursive. To avoid recursion you may specify maxdepth option. The following example list only the directories the current folder.

find . -maxdepth 1 -type d

When using complicated expressions in find it is important to escape special characters with backslash (\). See for instance the following "not equal to" expression.

find . \! \( -name *.jpg \)

Sometimes you want to pass the result of find to another command like grep. To do this you can use xargs to pass the result of one command to the next.

find . -name "*.foo" | xargs grep bar

If you want to move a files by find in a folder structure to another it gets a bit more complicated.

find from/project/ -name "*.[hc]" | sed 's/from.project//g' | tr '\n' '\0' | xargs -n1 -0 -I{} cp "./from/project{}" "./to/project{}"

References