Shell Grep – How to List Filenames Without Extension Using ‘ls -1’

greplsshell

ls -1 lists my elements like so:

foo.png
bar.png
foobar.png
...

I want it listed without the .png like so:

foo
bar
foobar
...

(the dir only contains .png files)

Can somebody tell me how to use grep in this case?

Purpose:
I have a text file where all the names are listed without the extension. I want to make a script that compares the text file with the folder to see which file is missing.

Best Answer

You only need the shell for this job.

POSIXly:

for f in *.png; do
    printf '%s\n' "${f%.png}"
done

With zsh:

print -rl -- *.png(:r)
Related Question