Skip to content
Advertisement

dont understand Linux command

I’m working on existing php project and I’m totally beginner with that .

I ‘m trying to understand this line of code .

exec("/usr/local/sbin/clog '/var/log/filter.log' | grep -F '10' | /usr/bin/tail -r -n 350 | grep -ve 'CLOG.*33' | grep 'filterlog:'" , $logarr )

I’ve searched alot and I know that exec is used to run unix command .

But I don’t understand the first part /usr/local/sbin/clog ‘/var/log/filter.log’

I also dont understand | meaning here

also I don’t understand this part /usr/bin/tail -r -n 350

can someone explain ?

Advertisement

Answer

| is the pipe operator. It takes the output of the command to its left and feeds it as input to the command on the right.

/usr/local/sbin/clog is the path to a binary called clog. It can colorize log files. The binary is started with one positional parameter '/var/log/filter.log', which is the path to a log file.

/usr/bin/tail is another binary called tail, which displays the last N lines (350 lines in your example). The -r switch might indicate that this is running under BSD operating system? Here is a note from the tail documentation about the -r switch:

GNU ‘tail’ can output any amount of data (some other versions of ‘tail’ cannot). It also has no ‘-r’ option (print in reverse), since reversing a file is really a different job from printing the end of a file; BSD ‘tail’ (which is the one with ‘-r’) can only reverse files that are at most as large as its buffer, which is typically 32 KiB. A more reliable and versatile way to reverse files is the GNU ‘tac’ command.

Both programs are started by their absolute path, presumably as a protection against wrong or empty values in PATH.

9 People found this is helpful
Advertisement