Can someone explain the syntax of the following commands? II know what they do but was having a hard time getting the syntax,

find / -type f -exec grep -H 'text-to-find-here' {} \;
cat access.log | cut -d '"' -f3 | cut -d ' ' -f2 | sort | uniq -c | sort -r
sudo cat error_log.20150205 | grep mpmstat | grep -v "," | cut -d: -f4- | grep -v ":"   | sed -e's/rdy//g' |  sed -e 's/bsy\|wr\|ka\|log\|dns\|cls\|rd/,/g
  • As someone detailled your commands, job's done. But should you be on your own, you can also give http://explainshell.com a try. It is great for beginners. – Uriel Mar 13 '15 at 21:24
  • Hi and welcome to the site. While this time someone has taken the time to answer all three of your questions (you might want to accept the answer, by the way), you should avoid asking more than a single question at a time. Next time, ask a separate question for each of the commands. – terdon Mar 14 '15 at 0:06

     / → Search from root
     -type f → only select file (f)
     -exec ....{} \; → execute the command inserting the found (file) names for {} one by one      grep -H 'test-to-find → execute this grep on every file found by find

cat access.log | → output file to stdout and pipe into next command
     cut -d '"' -f3 | → split lines on " and output only field 3, pipe into next command
     cut -d ' ' -f2 | → cut field 3 based on spaces and take second field, pipe into next
     sort | uniq | sort -r → sort the output, remove duplicates, sort in reverse order (-r)
(this last one can be done with some sort versions with sort -ur in one command, and the first one is a superfluous cat as you can write < access.log cut -d '"' | .... )

sudo cat error_log.20150205 | → execute cat with root permission (access rights on the file?)
     grep mpmstat | → only select lines with the word mpmstat
     grep -v "," | → deselect (-v) any line with a comma
     cut -d: -f4- | → split into fields based on ':' as delimiter, take fields nr 4 and up.
     grep -v ":" | → suppress lines with ':' (unlikely there as this was the split character before)
     sed -e's/rdy//g' | → replace s the sequence rdy with nothing all over (g) each line
     sed -e 's/bsy\|wr\|ka\|log\|dns\|cls\|rd/,/g → replace various alternatives (bsy,wr, etc, separated by\|`) by a comma

  • Cool. You might have summed it up like: badly written – mikeserv Mar 13 '15 at 20:12
  • @mikeserv If I had read ahead beyond the first one more closely (the first on is IMO not that bad), I might have skipped the whole. – Anthon Mar 13 '15 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.