This command works well in command prompt :
]$ ls -ltr ../cmxserver.log*|grep "`date | awk '{print $2" "$3}'`"|cut -d "/" -f2
cmxserver.log.2
cmxserver.log.1
cmxserver.log
However, using this in for loop gives error bash: syntax error near unexpected token `|'
]$for y in `ls -ltr ../cmxserver.log*|grep "`date | awk '{print $2" "$3}'`"|cut -d "/" -f2`
-bash: syntax error near unexpected token `|'
Any idea ?
Thanks
The whole line can be solved by find command:
find .. -maxdepth 1 -mtime -1 -daystart -name 'cmxserver.log*' -printf "%f\n"
.. - directory where to search-maxdepth 1 - don't go recursive to subdirectories-mtime -1 - only today's files-daystart - count the day since midnight, not last 24 hrs-name 'cmxserver.log*' - filenames-printf "%f\n" - print only basenameIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With