Back to Blog
Ls grep file extension6/26/2023 ![]() You can use ls -t without -l, so there's no need to parse the output of ls -l with awk or cut just to get the filename.I think this meets your requirements, and addresses concerns raised by others as follows: However, if you are passing a wildcard, you are correct that your shell will expand that wildcard in lexical order (which is basically what ls defaults to, as you noted).Īfter looking at the other suggestions, I offer the following: file=`ls -t -quoting-style=shell "dir" | xargs grep -l "regex" | head -n 1` If you are passing them explicitly, it will print the output in the same order as the list of files you pass it. In your first example, grep should not be re-sorting the filenames you pass to it.
0 Comments
Read More
Leave a Reply. |