-2

I have a directory with many c programs and some other files.

After performing gcc -o output_name filename.c on c files i have respective output files in the same folder.

What terminal command and how should i use it to display only these output files.

Thanks and regards!

2 Answers 2

3

As you were told in your other question, gcc -o output_name filename.c produces output_name which has no extension. Why should it? You didn't tell it to. Next time, run the command giving the output file name an extension. Something like .bin or .exe or .myexecutableprogram or whatever. File name extensions are arbitrary in Linux.

Since you have now already done this, you might be able to use a few tricks to get what you want:

  1. List all executable files in the current directory. Since gcc will automatically set its output file to be executable, if you don't have any other executables in that directory, this might be enough:

    find . -maxdepth 1 -type f -executable 
    
  2. Search through your history for gcc commands, extract the output name and list all matching files:

    ls $(history | grep -Po "gcc -o\s*\K.*?\s")
    

    Note that this assumes your output file names contain no spaces or newlines and that you've never used variables as file names (for example for file in *c; do gcc -o $file.exe $file or similar commands.)

1

with ls command we have option like hide

--hide=PATTERN
          do not list implied entries matching shell  PATTERN  (overridden
          by -a or -A)

So it will hide all matched and show what not matched.

For example as in your case

ls --hide='*.c'

As you said your directory contains C Programs and its output files , the above command will exclude all .c files and show what else.

Hope that helps.

5
  • thank you, but i was looking for a command to display only these output files. Answer you sugested is not useful if there are other files in directory.
    – srk_cb
    May 10, 2015 at 5:10
  • do they have any extensions or any name specific ?
    – Raja G
    May 10, 2015 at 5:22
  • @srkcb89 Based on your superficial question his answer is completely correct. Concretises your question, if you want concrete answers.
    – A.B.
    May 10, 2015 at 7:08
  • @Raja maybe with find and -executable
    – A.B.
    May 10, 2015 at 7:09
  • @A.B sorry for the confusion in my question. i edited it now, can you please provide me an answer. thank you
    – srk_cb
    May 10, 2015 at 7:28

Not the answer you're looking for? Browse other questions tagged .