'ls -1' : how to list filenames without extension
ls -1 | sed -e 's/\.png$//'
The sed
command removes (that is, it replaces with the empty string) any string .png
found at the end of a filename.
The .
is escaped as \.
so that it is interpreted by sed
as a literal .
character rather than the regexp .
(which means match any character). The $
is the end-of-line anchor, so it doesn't match .png
in the middle of a filename.
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)
If you just want to use bash:
for i in *; do echo "${i%.png}"; done
You should reach for grep
when trying to find matches, not for removing/substituting for that sed
is more appropriate:
find . -maxdepth 1 -name "*.png" | sed 's/\.png$//'
Once you decide you need to create some subdirectories to bring order in your PNG files you can easily change that to:
find . -name "*.png" | sed 's/\.png$//'