ls ak{k,}
will display files beginning with ak
followed either by another k
or nothing.
$ touch ak akk akc
$ ls -l ak{k,}
-rw-rw-r-- 1 cas cas 0 Oct 27 10:30 ak
-rw-rw-r-- 1 cas cas 0 Oct 27 10:30 akk
globs aren't regexps, but there's more to them than just *
and ?
.
If you want to use regexps to find matching filenames, you can use the find
command:
$ find . -maxdepth 1 -type f -regex './ak+$'
./ak
./akk
The -maxdepth 1
option limits the search to just the current directory (no subdirectories will be searched)
If you want case-insensitive searches, use -iregex
rather than -regex
.
There are numerous methods for using the files found by find
in other commands. For example:
find . -maxdepth 1 -type f -regex './ak+$' -ls
find . -maxdepth 1 -type f -regex './ak+$' -exec ls -ld {} +
find . -maxdepth 1 -type f -regex './ak+$' -print0 | xargs -0r ls -ld
ls -ld $(find . -maxdepth 1 -type f -regex './ak+$')
The last example is prone to various failure modes, including 1. not coping with white-space etc in filenames, 2. command-line length limits. not recommended.
ak*
insed
would totally matchakc
(and also justa
).^ak+$
or^akk*$
would work.