Linux – show a recursive list of files modified since i last logged in

findlinux

I am trying to figure out how to use find to show a list of all files in my current directory and lower that have been modified since my current terminal session was started.

Obviously a recursive find is to be used, but how do i delineate the results to just show files that are modified since i logged in? do i check them against some other file that is always modified on login? Is there a built in way?

say some thing like:
find . -newer 'xxxx' where xxxx is some file that gets modified at the start of a terminal session. But what file would work for that?

Best Answer

There's no specific file you can use for this, but it's easy to add your own.

In your .profile or .bash_profile or whatever you could do something like

TIMEFILE=$HOME/.lastlogin
[[ ! -f $TIMEFILE ]] && touch $TIMEFILE
find $HOME -newer $TIMEFILE
touch $TIMEFILE

The [[ line is there to prevent find from complaining if the file doesn't exist.

Edit: Ah, sorry, I may have slightly misunderstood your question. You may want to run the command at any time, so in this case you could just have this in your .bash_profile

touch $HOME/.lastlogin

And now from the command line

find $HOME -newer $HOME/.lastlogin

You can reset the timer at any time by touching the file again.

Related Question