Shell returns all files when regex doesn't match any file in directory? -
i use below command in shell file , works fine in directories regex matches. problem is, lists files when there no match regex. knows why has behaviour?
there anyway avoid it?
find . -type f -mtime +365 | egrep '.*xxx.yyy*.*'|grep -v "[^.]/" | xargs ls -lrt | tr -s " " | cut -d" " -f6-9
thanks time. note: m using script splunk forwarder on solaris 8.
if input of xargs
empty, execute ls -lrt
in current folder.
try xargs -i "{}" ls -lrt "{}"
instead. forces xargs
put input arguments place in command executes. if doesn't have input, can't , skip running command @ all.
if have gnu xargs
, can use switch --no-run-if-empty
instead.
if doesn't work, try move grep
ing find
, can use -ls
display list of files. avoid running ls
command if no file matches.
Comments
Post a Comment