0

When trying to find certain files with certain extension for example .*c

If I input the code below

find folder1 -type f -name '*c'

the result comes up like

folder1/filename1.c

folder1/filename2.c

If I only want the file names, not including the directory to the file like below, how would i have to change the code?

filename1.c

filename2.c
Tuto
  • 114
  • 6

2 Answers2

2

From man find under the -printf option you'll see:

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

To use it:

find folder1 -type f -name '*.c' -printf '%f\n'

P.S. Careful with the pattern. You want *.c, not .*c or *c.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
0

You can pipe it to an awk command like this

find folder1 -type f -name '*.c' | awk -F '/' '{ print $NF }'
H Dox
  • 655
  • 5
  • 9