You can get the numbers by the following command:
echo * | grep -o '[[:digit:]]*'
You can replace echo *
by ls
if you like.
If you just want to use awk
, then you can do the following:
\ls | awk 'match($0, /[[:digit:]]+/) {print substr($0, RSTART, RLENGTH)}'
\ls
will list all the files in your directory but awk
will print only the first set of numbers. If you have files with multiple numeric strings (such as 2043x924_fjnndkk.jpg
), it will only output 2043
.
Use \ls
if your ls
is aliased to something; otherwise, a plain ls
will suffice. In my case, I have aliased ls
to ls -s
(among other options) and so, always get the size printed which interferes with this command.