Cheatsheet

Find a file

By filename

find . -name *.cpp

By filename, ignore case

find . -iname *.cpp

Only folders

find . -type d -name *.cpp

Together with grep

find . -type f -exec grep "pattern" '{}' \; -print

This goes through every object in the current directory tree (.) that’s a file (-type f) and then runs grep ”pattern” for every file that matches, then prints them on the screen (-print). The curly braces ({}) are a placeholder for those results matched by the Linux find command. The {} go inside single quotes (‘) so that grep isn’t given a misshapen file name. The -exec command is ended with a semicolon (;), which also needs an escape (;) so that it doesn’t end up being interpreted by the shell.

Find string in a file

grep -rnw '.' -e 'pattern'

Filter files before

grep --include=\*.{cpp,hpp} -rnw '.' -e "pattern"

Check linkage between libraries

ldd <path_to_library_or_executable>
readelf -d <path_to_so_file>
objdump -p <path_to_so_file>