Alias to open latest log file in Bash shell

Here’s a simple bash alias to open last modified log file in logs directory. It will be opened in less pager on last line:

alias log='less +G $(ls -ctr1 $APP_HOME/logs/*.log | tail -1)'


You can put it somewhere in ~/.bashrc or ~/.bash_profile and declare $APP_HOME somewhere above this line. You might also need to change /logs/*.log path.

Save file. Run source ~/.bashrc, and you’ll see last modified log anytime you call log command.

You can also substitute less +G with tail -f and open log in follow mode (it will automatically show anything new written to file)

File last access time in Java on Linux

Some time ago a friend of mine needed to retrieve last access time of file in his Java code on Linux. Then he used this info to check if some cache files can be removed. I’ve wrote simple JNI based library to do this. It’s very simple but maybe someone can reuse it. So here it is (You need Java 1.4 or newer to use):

Jar with classes: jAccessTimeJ.jar
Native library (32bit): libjAccessTimeC.so

(Sorry no 64bit binary yet. I don’t have 64 bit Linux host right now. Please send it to me if you compile it from sources)

To run:
java -Djava.library.path=./ -cp jAccessTimeJ.jar com.wordpress.jdevel.utils.JAccessTimeUnix /path/to/file

Remember to put .so file in current directory.
Or you could put .so file somewhere on LD_LIBRARY_PATH and then omit -Djava.library.path=./ switch.

To use it from you Java code:

private void testLastAccess() {
    File f = new File("/boot/vmlinuz");
    Date date = JAccessTimeUnix.getLastAccessTime(f);
    System.out.println(date);
}

You can get source from here:
Java-last-access-time-linux

%d bloggers like this: