Now that you are working in cshell then you would know that aliases are supposed to be defined in one line only. hence the alias that is shown overshooting the normal line length. That is cshell for you.
alias latest_log 'find "$LOG/tr/`date +%Y%m%d`" -name "xtest*" -printf "%Ts\t%p\0" | sort -z -k 1,1nr -k 2 | head -z -n 1 | cut -z -f2 | xargs -0 less -F'
Breaking it into chunks to show what it is doing:
find
command prints , null-separated filenames with the numeric timestamp alongwith the filename. Note that, the quotes in the date
command have been taken away for date
can run very well without them , plus having them would have made the quoting needlessly wieldy for the alias.
- The null (
\0
) separated duos (timestamp TAB filename) are then sorted starting from the first field in the reverse numeric fashion and ending in the second field. The -z
option in sort
command is to separate the input chunks around the null character rather than the default newline.
- Once sorted in the proper order, we take out the topmost chunk, which would hold the filename with the latest timestamp by means of the
head -z -n 1
command.
- Then the
cut
command takes over and strips the timestamp since it's job is done now and it is no longer needed. We use the -z
option to tackle the null separated input to cut
. The -f2
option shall throw the filename + \0
to the next pipeline.
xargs -0
would be reading the filename separated by null and pass the filename to less -F
on it's commandline.
csh
. Are you using thecsh
shell?$ echo $0 -csh
so YES I am.