List files not matching given string in filename

With GNU ls (the version on non-embedded Linux and Cygwin, sometimes also found elsewhere), you can exclude some files when listing a directory.

ls -I 'temp_log.*' -lrt

(note the long form of -I is --ignore='temp_log.*')

With zsh, you can let the shell do the filtering. Pass -d to ls so as to avoid listing the contents of matched directories.

setopt extended_glob          # put this in your .zshrc
ls -dltr ^temp_log.*

With ksh, bash or zsh, you can use the ksh filtering syntax. In zsh, run setopt ksh_glob first. In bash, run shopt -s extglob first.

ls -dltr !(temp_log.*)

You can use grep with the option -v.

ls -lrt | grep -v <exclude-filename-part>

You can use find for this:

find . \! -name 'temp_log*'

This will just print the names, you can add -ls to make a ls -l style output with timestamp and permissions, or use -exec ls {} + to actually pass to ls with whatever options you want for columns, sorting, etc.

I wrote this assuming this was just files in a directory. If the directory contains other directories, you may want to avoid recursively listing them

find . \! -name 'temp_log*' -maxdepth 1

And if you use ls you'll want to pass the -d option to stop it from listing inside the directories: -exec ls -d {} +

Tags:

Filter

Ls