You'll still need grep, and this may or may not solve the problem, but it's worth a mention. compgen -G "*" should provide the same output as a plain ls (but note that ls * is a different thing entirely). This handles filenames with whitespace, including newlines. â (this can depend on your version of find though, check the "STANDARDS CONFORMANCE" section of your man page)Īs a possible alternative with no external programs required, bash has compgen which, among other things, expands globs, equivalent to an ls with no options: compgen -P "someprefix>" -S " you can probably just use one of -name/ -regex instead of both (e.g.MYPATTERN is a proper POSIX ERE (default type is Emacs, see here), but it must match the entire filename (including the.You can use any shell-style glob, but note that "*" will match a leading "." in a name â unlike bash, so * means anything that doesn't have a leading "." -maxdepth 1 and -name * make name matching work the same as a plain ls (or ls.( find is not a good way to arbitrarily modify the output of other commands, of course!) ls may output results in a single line, and this could make your grep -c give an incorrect result. Do some tests, and you will see it easily. Try /foo/bar/.\.txt also ls lists files and directories under your current directory. regextype posix-extended -regex "MYPATTERN" \ grep accepts regular expressions, not glob. In this case GNU find lets you do all these things in one go, eliminating pipes and potentially troublesome parsing of ls: find.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |