0

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
  • I tried this and nothing happened do I need to write something else instead of 'name' thank you – Love101 kisses Dec 30 '20 at 14:40
  • find will only find files from . on, so depending on what folder you are in you might not find anything. Try it as find / -type f -name *.c or change the / to the start of whatever folder you think they are all in like ~ or /usr or /var, etc. – Terrance Dec 30 '20 at 14:45
  • PROBLEM SOLVED Apparently there are no C program files! When I created one ls *.c worked even steeldriver answer thank you – Love101 kisses Dec 30 '20 at 14:48

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.

Shane Bishop
  • 186
  • 5