-1

I need to display all the files with .c (C program files) in the terminal and having problems to do so.

My ideas were using find and grep and maybe gcc But none of my attempts worked. I am working on Linux. I don't know the file names. I just want to list all the files.

I tried the following:

ls *.c
find . -type f *.c

1 Answers1

3

You can use

find . -type f -name '*.c'

If you want to search in a directory other than your current directory, use

find /desired/path/to/search -type f -name '*.c'

instead.

To explain what this command does, the first argument is the path for find to search for files in. Then -type f tells find to only consider regular files. -name '*.c' tells find to search for files whose names match the expression *.c (*.c is quoted to prevent the shell expanding the *).

If you wish to search case-insensitively, replace -name '*.c' with -iname '*.c' (then files with .c and .C file extensions will both be found).

By default, find will recursively search through all subdirectories of the directory provided. If you wish to limit the search depth, use the -maxdepth option.