アンカーはgrepでのみ機能しますか、それとも他のコマンドで使用できますか?
例:
ls -l ^cat
承認された回答:
^
などの正規表現アンカー および$
実装するツールによってのみ解析されます 正規表現。 ls
はそのようなツールではないので、いいえ、使用できません。ただし、シェルから呼び出されたバイナリはシェルグロブを使用できます。これは、それほど強力ではありませんが、ワイルドカードベースの検索メカニズムです。
たとえば、名前がcatで始まるすべてのファイルのリストの場合:
$ ls cat* # lists all files with names which start with 'cat'
$ ls *dog # lists all files with names which end with 'dog'
$ ls d*y # Lists all files which names which start with 'd' and end
with 'y', e. g. 'donkey'
$ ls p?g # Lists all files which start with 'p', have one additional
character, and end with 'g', e. g. 'pig' and 'pug'
グロブの目的で、*
「0文字以上」を意味します。 ?
「正確に1文字」を意味します。