Skip to main content

There is no option in ls to filter on filename but in most of the shells there are globbing extension man bash /Pattern Matching

ksh

ls -lrtd -- *@(day|night)*

zsh

setopt extendedglob
ls -lrtd -- *(day|night)*

or:

setopt kshglob
ls -lrtd -- *@(day|night)*

bash

shopt -s extglob
ls -lrtd -- *@(day|night)*

In any of these three shells you can do this, but note that if one of the cases doesn't match any file, that pattern will be left unexpanded (e.g. *day* night1.txt othernight.txt if there is no file name containing day; see man bash /EXPANSION or /Brace Expansion specifically):

ls -lrtd -- *{day,night}*

In any shells you can do:

ls -lrtd -- *day* *night*

In zsh, if there's either no day or night file, the last two commands will fail; set the nonomatch or csh_null_glob option, or add (N) after each pattern to avoid this.

There is no option in ls to filter on filename but in most of the shells there are globbing extension man bash /Pattern Matching

ksh

ls -lrtd -- *@(day|night)*

zsh

setopt extendedglob
ls -lrtd -- *(day|night)*

or:

setopt kshglob
ls -lrtd -- *@(day|night)*

bash

shopt -s extglob
ls -lrtd -- *@(day|night)*

In any of these three shells you can do this, but note that if one of the cases doesn't match any file, that pattern will be left unexpanded (e.g. *day* night1.txt othernight.txt if there is no file name containing day):

ls -lrtd -- *{day,night}*

In any shells you can do:

ls -lrtd -- *day* *night*

In zsh, if there's either no day or night file, the last two commands will fail; set the nonomatch or csh_null_glob option, or add (N) after each pattern to avoid this.

There is no option in ls to filter on filename but in most of the shells there are globbing extension man bash /Pattern Matching

ksh

ls -lrtd -- *@(day|night)*

zsh

setopt extendedglob
ls -lrtd -- *(day|night)*

or:

setopt kshglob
ls -lrtd -- *@(day|night)*

bash

shopt -s extglob
ls -lrtd -- *@(day|night)*

In any of these three shells you can do this, but note that if one of the cases doesn't match any file, that pattern will be left unexpanded (e.g. *day* night1.txt othernight.txt if there is no file name containing day; see man bash /EXPANSION or /Brace Expansion specifically):

ls -lrtd -- *{day,night}*

In any shells you can do:

ls -lrtd -- *day* *night*

In zsh, if there's either no day or night file, the last two commands will fail; set the nonomatch or csh_null_glob option, or add (N) after each pattern to avoid this.

suggest (N) in zsh; mention the brace solution
Source Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k

There is no option in ls to filter on filename but in most of the shells there are globbing extension man bash /Pattern Matching

ksh

ls -lrtd -- *@(day|night)*

zsh

setopt extendedglob
ls -lrtd -- *(day|night)*

or:

setopt kshglob
ls -lrtd -- *@(day|night)*

bash

shopt -s extglob
ls -lrtd -- *@(day|night)*

In allany of these three shells you can do this, but note that if one of the cases doesn't match any file, that pattern will be left unexpanded (e.g. *day* night1.txt othernight.txt if there is no file name containing day):

ls -lrtd -- *{day,night}*

In any shells you can do:

ls -lrtd -- *day* *night*

though inIn zsh, if there's either no day or night file, the whole commandlast two commands will fail (seefail; set the nonomatch andor csh_null_glob options)option, or add (N) after each pattern to avoid this.

There is no option in ls to filter on filename but in most of the shells there are globbing extension man bash /Pattern Matching

ksh

ls -lrtd -- *@(day|night)*

zsh

setopt extendedglob
ls -lrtd -- *(day|night)*

or:

setopt kshglob
ls -lrtd -- *@(day|night)*

bash

shopt -s extglob
ls -lrtd -- *@(day|night)*

In all shells, you can do:

ls -lrtd -- *day* *night*

though in zsh if there's either no day or night file, the whole command will fail (see the nonomatch and csh_null_glob options).

There is no option in ls to filter on filename but in most of the shells there are globbing extension man bash /Pattern Matching

ksh

ls -lrtd -- *@(day|night)*

zsh

setopt extendedglob
ls -lrtd -- *(day|night)*

or:

setopt kshglob
ls -lrtd -- *@(day|night)*

bash

shopt -s extglob
ls -lrtd -- *@(day|night)*

In any of these three shells you can do this, but note that if one of the cases doesn't match any file, that pattern will be left unexpanded (e.g. *day* night1.txt othernight.txt if there is no file name containing day):

ls -lrtd -- *{day,night}*

In any shells you can do:

ls -lrtd -- *day* *night*

In zsh, if there's either no day or night file, the last two commands will fail; set the nonomatch or csh_null_glob option, or add (N) after each pattern to avoid this.

added 343 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

There is no option in ls to filter on filename but in most of the shells there are globbing extension man bash /Pattern Matching

ksh

ls -lrtd -- *@(day|night)*

zsh

setopt extendedglob
ls -lrtd -- *(day|night)*

or:

setopt kshglob
ls -lrtd -- *@(day|night)*

bash

shopt -s extglob
ls -lrtd -- *@(day|night)*

In all shells, you can do:

ls -lrtd -- *day* *night*

though in zsh if there's either no day or night file, the whole command will fail (see the nonomatch and csh_null_glob options).

There is no option in ls to filter on filename but in most of the shells there are globbing extension man bash /Pattern Matching

ksh

ls *@(day|night)*

bash

shopt -s extglob
ls *@(day|night)*

There is no option in ls to filter on filename but in most of the shells there are globbing extension man bash /Pattern Matching

ksh

ls -lrtd -- *@(day|night)*

zsh

setopt extendedglob
ls -lrtd -- *(day|night)*

or:

setopt kshglob
ls -lrtd -- *@(day|night)*

bash

shopt -s extglob
ls -lrtd -- *@(day|night)*

In all shells, you can do:

ls -lrtd -- *day* *night*

though in zsh if there's either no day or night file, the whole command will fail (see the nonomatch and csh_null_glob options).

Source Link
Loading