when I use this to look to see if there is a particular file in a directory, ls
piped to grep
does not work
casper@fooserver:/home/log$ ls -ltr | grep *FOO-VOL2*
But when I use ls
with the file globbing I get results:
casper@fooserver:/home/log$ ls -ltr *FOO-VOL2*
-rw-rw-rw- 1 casper casper 11489 Sep 24 18:00 FOO-VOL2.20140924.log.gz
-rw-rw-rw- 1 casper casper 11885 Sep 25 18:00 FOO-VOL2.20140925.log.gz
-rw-rw-rw- 1 casper casper 0 Sep 26 08:00 FOO-VOL2.sessiondump.log
-rw-rw-rw- 1 casper casper 60906 Sep 26 18:00 FOO-VOL2.20140926.log
-rw-rw-rw- 1 casper casper 58503 Sep 29 09:00 FOO-VOL2.20140929.log
-rw-rw-rw- 1 casper casper 8259128 Sep 29 09:00 FOO-VOL2.sys.log
What is the difference - the grep to pipe should work.
*FOO-VOL2*
contains a newline; the output ofls
will span multiple lines, andgrep
(assuming a correct regex) will only show the line that containsFOO-VOL2
.