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

Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
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?
linux find
add a comment |Â
up vote
3
down vote
favorite
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?
linux find
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
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?
linux find
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?
linux find
edited Jun 28 at 1:33
asked Jun 28 at 1:26
DanMan3395
717
717
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
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.
ok so each time my shell is invoked it makes a new file and then uses it as the time baseline?
â DanMan3395
Jun 28 at 2:13
It's important to do thefindbefore thetouch. So you use the previous timestamp file (ie your previous login) for the comparison, then update the timestamp when it completes. Or if you just want to run the command at any time, thetouchcommand in your.bash_profileis sufficient, and you can run thefindcommand at any time.
â Stephen Harris
Jun 28 at 2:16
Ah, I may have slightly misunderstood your question, so I added some additional discussion to the answer.
â Stephen Harris
Jun 28 at 2:24
This makes sense thank you. Just curious, is there some other, built in way to search for files modified since login? My original assumption was find but i want to make sure i am not overthinking something simple.
â DanMan3395
Jun 28 at 2:28
add a comment |Â
up vote
0
down vote
In Bash you could calculate the time that has passed since you logged in, with last.
TIMEDIFF=$(( ( $(date --date="$(last -1 | head -n 1 | tr -s " " | cut -d" " -f3-6)" +%s) - $(date +%s) ) / 60 ))
Note that this will yield a negative number. (That's useful for the next step.)
Then you add the time difference with the -mmin parameter to the find command:
find . -mmin $TIMEDIFF
Of course you can also make it a one-liner.
This doesn't work for me as the find just shows everything that exists. I also get weird results from the code in that variable: TIMEDIFF=$(( ( $(date --date="$(last -1 | head -n 1 | tr -s " " | cut -d" " -f3-6)" +%s) - $(date +%s) ) / 60 )) date: invalid date âÂÂ134.29.149.192 Wed Jun 27âÂÂ
â DanMan3395
Jun 28 at 2:11
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
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.
ok so each time my shell is invoked it makes a new file and then uses it as the time baseline?
â DanMan3395
Jun 28 at 2:13
It's important to do thefindbefore thetouch. So you use the previous timestamp file (ie your previous login) for the comparison, then update the timestamp when it completes. Or if you just want to run the command at any time, thetouchcommand in your.bash_profileis sufficient, and you can run thefindcommand at any time.
â Stephen Harris
Jun 28 at 2:16
Ah, I may have slightly misunderstood your question, so I added some additional discussion to the answer.
â Stephen Harris
Jun 28 at 2:24
This makes sense thank you. Just curious, is there some other, built in way to search for files modified since login? My original assumption was find but i want to make sure i am not overthinking something simple.
â DanMan3395
Jun 28 at 2:28
add a comment |Â
up vote
2
down vote
accepted
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.
ok so each time my shell is invoked it makes a new file and then uses it as the time baseline?
â DanMan3395
Jun 28 at 2:13
It's important to do thefindbefore thetouch. So you use the previous timestamp file (ie your previous login) for the comparison, then update the timestamp when it completes. Or if you just want to run the command at any time, thetouchcommand in your.bash_profileis sufficient, and you can run thefindcommand at any time.
â Stephen Harris
Jun 28 at 2:16
Ah, I may have slightly misunderstood your question, so I added some additional discussion to the answer.
â Stephen Harris
Jun 28 at 2:24
This makes sense thank you. Just curious, is there some other, built in way to search for files modified since login? My original assumption was find but i want to make sure i am not overthinking something simple.
â DanMan3395
Jun 28 at 2:28
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
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.
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.
edited Jun 28 at 2:23
answered Jun 28 at 2:05
Stephen Harris
21.1k23771
21.1k23771
ok so each time my shell is invoked it makes a new file and then uses it as the time baseline?
â DanMan3395
Jun 28 at 2:13
It's important to do thefindbefore thetouch. So you use the previous timestamp file (ie your previous login) for the comparison, then update the timestamp when it completes. Or if you just want to run the command at any time, thetouchcommand in your.bash_profileis sufficient, and you can run thefindcommand at any time.
â Stephen Harris
Jun 28 at 2:16
Ah, I may have slightly misunderstood your question, so I added some additional discussion to the answer.
â Stephen Harris
Jun 28 at 2:24
This makes sense thank you. Just curious, is there some other, built in way to search for files modified since login? My original assumption was find but i want to make sure i am not overthinking something simple.
â DanMan3395
Jun 28 at 2:28
add a comment |Â
ok so each time my shell is invoked it makes a new file and then uses it as the time baseline?
â DanMan3395
Jun 28 at 2:13
It's important to do thefindbefore thetouch. So you use the previous timestamp file (ie your previous login) for the comparison, then update the timestamp when it completes. Or if you just want to run the command at any time, thetouchcommand in your.bash_profileis sufficient, and you can run thefindcommand at any time.
â Stephen Harris
Jun 28 at 2:16
Ah, I may have slightly misunderstood your question, so I added some additional discussion to the answer.
â Stephen Harris
Jun 28 at 2:24
This makes sense thank you. Just curious, is there some other, built in way to search for files modified since login? My original assumption was find but i want to make sure i am not overthinking something simple.
â DanMan3395
Jun 28 at 2:28
ok so each time my shell is invoked it makes a new file and then uses it as the time baseline?
â DanMan3395
Jun 28 at 2:13
ok so each time my shell is invoked it makes a new file and then uses it as the time baseline?
â DanMan3395
Jun 28 at 2:13
It's important to do the
find before the touch. So you use the previous timestamp file (ie your previous login) for the comparison, then update the timestamp when it completes. Or if you just want to run the command at any time, the touch command in your .bash_profile is sufficient, and you can run the find command at any time.â Stephen Harris
Jun 28 at 2:16
It's important to do the
find before the touch. So you use the previous timestamp file (ie your previous login) for the comparison, then update the timestamp when it completes. Or if you just want to run the command at any time, the touch command in your .bash_profile is sufficient, and you can run the find command at any time.â Stephen Harris
Jun 28 at 2:16
Ah, I may have slightly misunderstood your question, so I added some additional discussion to the answer.
â Stephen Harris
Jun 28 at 2:24
Ah, I may have slightly misunderstood your question, so I added some additional discussion to the answer.
â Stephen Harris
Jun 28 at 2:24
This makes sense thank you. Just curious, is there some other, built in way to search for files modified since login? My original assumption was find but i want to make sure i am not overthinking something simple.
â DanMan3395
Jun 28 at 2:28
This makes sense thank you. Just curious, is there some other, built in way to search for files modified since login? My original assumption was find but i want to make sure i am not overthinking something simple.
â DanMan3395
Jun 28 at 2:28
add a comment |Â
up vote
0
down vote
In Bash you could calculate the time that has passed since you logged in, with last.
TIMEDIFF=$(( ( $(date --date="$(last -1 | head -n 1 | tr -s " " | cut -d" " -f3-6)" +%s) - $(date +%s) ) / 60 ))
Note that this will yield a negative number. (That's useful for the next step.)
Then you add the time difference with the -mmin parameter to the find command:
find . -mmin $TIMEDIFF
Of course you can also make it a one-liner.
This doesn't work for me as the find just shows everything that exists. I also get weird results from the code in that variable: TIMEDIFF=$(( ( $(date --date="$(last -1 | head -n 1 | tr -s " " | cut -d" " -f3-6)" +%s) - $(date +%s) ) / 60 )) date: invalid date âÂÂ134.29.149.192 Wed Jun 27âÂÂ
â DanMan3395
Jun 28 at 2:11
add a comment |Â
up vote
0
down vote
In Bash you could calculate the time that has passed since you logged in, with last.
TIMEDIFF=$(( ( $(date --date="$(last -1 | head -n 1 | tr -s " " | cut -d" " -f3-6)" +%s) - $(date +%s) ) / 60 ))
Note that this will yield a negative number. (That's useful for the next step.)
Then you add the time difference with the -mmin parameter to the find command:
find . -mmin $TIMEDIFF
Of course you can also make it a one-liner.
This doesn't work for me as the find just shows everything that exists. I also get weird results from the code in that variable: TIMEDIFF=$(( ( $(date --date="$(last -1 | head -n 1 | tr -s " " | cut -d" " -f3-6)" +%s) - $(date +%s) ) / 60 )) date: invalid date âÂÂ134.29.149.192 Wed Jun 27âÂÂ
â DanMan3395
Jun 28 at 2:11
add a comment |Â
up vote
0
down vote
up vote
0
down vote
In Bash you could calculate the time that has passed since you logged in, with last.
TIMEDIFF=$(( ( $(date --date="$(last -1 | head -n 1 | tr -s " " | cut -d" " -f3-6)" +%s) - $(date +%s) ) / 60 ))
Note that this will yield a negative number. (That's useful for the next step.)
Then you add the time difference with the -mmin parameter to the find command:
find . -mmin $TIMEDIFF
Of course you can also make it a one-liner.
In Bash you could calculate the time that has passed since you logged in, with last.
TIMEDIFF=$(( ( $(date --date="$(last -1 | head -n 1 | tr -s " " | cut -d" " -f3-6)" +%s) - $(date +%s) ) / 60 ))
Note that this will yield a negative number. (That's useful for the next step.)
Then you add the time difference with the -mmin parameter to the find command:
find . -mmin $TIMEDIFF
Of course you can also make it a one-liner.
answered Jun 28 at 2:04
Lukas
1
1
This doesn't work for me as the find just shows everything that exists. I also get weird results from the code in that variable: TIMEDIFF=$(( ( $(date --date="$(last -1 | head -n 1 | tr -s " " | cut -d" " -f3-6)" +%s) - $(date +%s) ) / 60 )) date: invalid date âÂÂ134.29.149.192 Wed Jun 27âÂÂ
â DanMan3395
Jun 28 at 2:11
add a comment |Â
This doesn't work for me as the find just shows everything that exists. I also get weird results from the code in that variable: TIMEDIFF=$(( ( $(date --date="$(last -1 | head -n 1 | tr -s " " | cut -d" " -f3-6)" +%s) - $(date +%s) ) / 60 )) date: invalid date âÂÂ134.29.149.192 Wed Jun 27âÂÂ
â DanMan3395
Jun 28 at 2:11
This doesn't work for me as the find just shows everything that exists. I also get weird results from the code in that variable: TIMEDIFF=$(( ( $(date --date="$(last -1 | head -n 1 | tr -s " " | cut -d" " -f3-6)" +%s) - $(date +%s) ) / 60 )) date: invalid date âÂÂ134.29.149.192 Wed Jun 27âÂÂ
â DanMan3395
Jun 28 at 2:11
This doesn't work for me as the find just shows everything that exists. I also get weird results from the code in that variable: TIMEDIFF=$(( ( $(date --date="$(last -1 | head -n 1 | tr -s " " | cut -d" " -f3-6)" +%s) - $(date +%s) ) / 60 )) date: invalid date âÂÂ134.29.149.192 Wed Jun 27âÂÂ
â DanMan3395
Jun 28 at 2:11
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f452332%2fshow-a-recursive-list-of-files-modified-since-i-last-logged-in%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password