user997112
user997112

Reputation: 30615

Bash Get all files containing file extension, recursively

Using Bash how would I get all file names (not paths) of files containing ".cpp", given a root folder to recursively-check?

Upvotes: 1

Views: 620

Answers (2)

mario
mario

Reputation: 11098

You can use for that purpose -printf option of find command with the following parameter:

%f File's name with any leading directories removed (only the last element).

so the full command may look like this:

find / -type f -name "*.cpp" -printf "%f\n"

Upvotes: 1

Sean Bright
Sean Bright

Reputation: 120644

Just use find:

find /root/folder/to/check -name '*.cpp' -printf "%P\n"

Upvotes: 2

Related Questions