Originally Posted by Mr. Alex
ls -lha /some/dir *5678*
Since globbing patterns are expanded by the shell before the command is executed, ls
doesn't do any of the locating work here. The only reason to use it at all is if you want the long-form output. For a simple list, echo
is all that's needed.
to output the files one per line, or with other fancy formatting.
' option has no meaning here either, since dotfiles aren't expanded by the globbing pattern by default. To get hidden files in your output, enable the dotglob
Originally Posted by kaldrouby
i would use this :
ls * | grep 5678*
defaults to all files in the current directory anyway, the "*
" is unneeded. And in order to be read properly by grep
, you'd need to use the "-1
" ("one", not "el") option to print one file per line (and even that would fail if the filenames themselves had newlines in them).
You also have the grep
pattern wrong, since it uses regular expressions, not globbing (which, incidentally you would have to quote first to protect from shell expansion anyway). You only need to use "grep 5678
But why bother with all this anyway, when globbing is easier, safer, and lighter (no external commands needed, and unusual characters can't mess it up)?