Recursively find ONLY the latest logs in all sub-folders and save to file
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
I am working on a RHEL7 box. I need to recursively find all the LATEST (and only the latest) .log files in each sub-folder below a certain hierarchy and list their full paths in a file 'all_logs.txt'.
My find command looks like this and works to return full paths to ~6000 records:
cd $SEARCHDIR
find . -iname computer_import_*.log > all_logs.txt
The problem here is that this find command is finding ALL computer_import_.log where I just need the latest computer_import_.log file in each sub-folder searched.
awk sed grep find
add a comment |
up vote
-1
down vote
favorite
I am working on a RHEL7 box. I need to recursively find all the LATEST (and only the latest) .log files in each sub-folder below a certain hierarchy and list their full paths in a file 'all_logs.txt'.
My find command looks like this and works to return full paths to ~6000 records:
cd $SEARCHDIR
find . -iname computer_import_*.log > all_logs.txt
The problem here is that this find command is finding ALL computer_import_.log where I just need the latest computer_import_.log file in each sub-folder searched.
awk sed grep find
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am working on a RHEL7 box. I need to recursively find all the LATEST (and only the latest) .log files in each sub-folder below a certain hierarchy and list their full paths in a file 'all_logs.txt'.
My find command looks like this and works to return full paths to ~6000 records:
cd $SEARCHDIR
find . -iname computer_import_*.log > all_logs.txt
The problem here is that this find command is finding ALL computer_import_.log where I just need the latest computer_import_.log file in each sub-folder searched.
awk sed grep find
I am working on a RHEL7 box. I need to recursively find all the LATEST (and only the latest) .log files in each sub-folder below a certain hierarchy and list their full paths in a file 'all_logs.txt'.
My find command looks like this and works to return full paths to ~6000 records:
cd $SEARCHDIR
find . -iname computer_import_*.log > all_logs.txt
The problem here is that this find command is finding ALL computer_import_.log where I just need the latest computer_import_.log file in each sub-folder searched.
awk sed grep find
awk sed grep find
edited 2 days ago
Rui F Ribeiro
38.2k1475123
38.2k1475123
asked 2 days ago
SSDdude
726
726
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
I tried with below command and it worked fine
find . -type f -iname "computer_import_*.log" -daystart -mtime -1 > all_logs.txt
I should have been more clear sorry... it does work and returns ~70 records and they all look like the latest. The problem is there should be ~400 records returned by the command. My speculation is that this is because I could easily have the latest record be from last year. Perhaps its working for you because you don't have records that old? Thx very new at this!
– SSDdude
2 days ago
Will check and update
– Praveen Kumar BS
2 days ago
add a comment |
up vote
0
down vote
find $SEARCHDIR -type f -iname "computer_import_*.log" -mtime -10 > all_logs.txt
This will find all files that match the -iname
argument, restricted to being modified within 10-days of the run. See the find
manpages for more details.
Note that the -iname
argument is quoted so that find
interprets the argument rather than the shell before find
runs.
If you want to see what's returned based on these criteria do, for example:
find $SEARCHDIR -type f -iname "computer_import_*.log" -mtime -10 -exec ls -ld +
This will perform an ls
on each file returned, thus showing the last modification date. Change the value of -mtime <+-N>
to your taste. A value of -90
would return files modified in the last 90 days. A positive value of +90
would return files modified over 90 days ago.
** ALTERNATIVE INTERPRETATION **
Given the requirement to find only the most recent file in any and all sub-directories, do something like this:
find $SEARCHDIR -type d > /var/tmp/mydirs
while read -r line
do
ls -alt "$line" | grep -Ev "^(d|total)" | head -1 >> /var/tmp/mylogs
done < /var/tmp/mydirs
The ls
orders the contents of a directory as newest to oldest modification date. The grep
eliminates directory entries and total size lines. head
snips the first file (if any) from the directory being examined.
Thx, but this wont work because I could have the latest log be 3mo old or more.
– SSDdude
2 days ago
All I appreciate all the feedback but still no luck. It is sounding to me that there is no real good way to search sub-dirs. and extract ONLY the SINGE absolute latest log file in said directory. None of these answers do that. Thx.
– SSDdude
2 days ago
See the alternative interpretation update.
– JRFerguson
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I tried with below command and it worked fine
find . -type f -iname "computer_import_*.log" -daystart -mtime -1 > all_logs.txt
I should have been more clear sorry... it does work and returns ~70 records and they all look like the latest. The problem is there should be ~400 records returned by the command. My speculation is that this is because I could easily have the latest record be from last year. Perhaps its working for you because you don't have records that old? Thx very new at this!
– SSDdude
2 days ago
Will check and update
– Praveen Kumar BS
2 days ago
add a comment |
up vote
0
down vote
I tried with below command and it worked fine
find . -type f -iname "computer_import_*.log" -daystart -mtime -1 > all_logs.txt
I should have been more clear sorry... it does work and returns ~70 records and they all look like the latest. The problem is there should be ~400 records returned by the command. My speculation is that this is because I could easily have the latest record be from last year. Perhaps its working for you because you don't have records that old? Thx very new at this!
– SSDdude
2 days ago
Will check and update
– Praveen Kumar BS
2 days ago
add a comment |
up vote
0
down vote
up vote
0
down vote
I tried with below command and it worked fine
find . -type f -iname "computer_import_*.log" -daystart -mtime -1 > all_logs.txt
I tried with below command and it worked fine
find . -type f -iname "computer_import_*.log" -daystart -mtime -1 > all_logs.txt
answered 2 days ago
Praveen Kumar BS
1,055138
1,055138
I should have been more clear sorry... it does work and returns ~70 records and they all look like the latest. The problem is there should be ~400 records returned by the command. My speculation is that this is because I could easily have the latest record be from last year. Perhaps its working for you because you don't have records that old? Thx very new at this!
– SSDdude
2 days ago
Will check and update
– Praveen Kumar BS
2 days ago
add a comment |
I should have been more clear sorry... it does work and returns ~70 records and they all look like the latest. The problem is there should be ~400 records returned by the command. My speculation is that this is because I could easily have the latest record be from last year. Perhaps its working for you because you don't have records that old? Thx very new at this!
– SSDdude
2 days ago
Will check and update
– Praveen Kumar BS
2 days ago
I should have been more clear sorry... it does work and returns ~70 records and they all look like the latest. The problem is there should be ~400 records returned by the command. My speculation is that this is because I could easily have the latest record be from last year. Perhaps its working for you because you don't have records that old? Thx very new at this!
– SSDdude
2 days ago
I should have been more clear sorry... it does work and returns ~70 records and they all look like the latest. The problem is there should be ~400 records returned by the command. My speculation is that this is because I could easily have the latest record be from last year. Perhaps its working for you because you don't have records that old? Thx very new at this!
– SSDdude
2 days ago
Will check and update
– Praveen Kumar BS
2 days ago
Will check and update
– Praveen Kumar BS
2 days ago
add a comment |
up vote
0
down vote
find $SEARCHDIR -type f -iname "computer_import_*.log" -mtime -10 > all_logs.txt
This will find all files that match the -iname
argument, restricted to being modified within 10-days of the run. See the find
manpages for more details.
Note that the -iname
argument is quoted so that find
interprets the argument rather than the shell before find
runs.
If you want to see what's returned based on these criteria do, for example:
find $SEARCHDIR -type f -iname "computer_import_*.log" -mtime -10 -exec ls -ld +
This will perform an ls
on each file returned, thus showing the last modification date. Change the value of -mtime <+-N>
to your taste. A value of -90
would return files modified in the last 90 days. A positive value of +90
would return files modified over 90 days ago.
** ALTERNATIVE INTERPRETATION **
Given the requirement to find only the most recent file in any and all sub-directories, do something like this:
find $SEARCHDIR -type d > /var/tmp/mydirs
while read -r line
do
ls -alt "$line" | grep -Ev "^(d|total)" | head -1 >> /var/tmp/mylogs
done < /var/tmp/mydirs
The ls
orders the contents of a directory as newest to oldest modification date. The grep
eliminates directory entries and total size lines. head
snips the first file (if any) from the directory being examined.
Thx, but this wont work because I could have the latest log be 3mo old or more.
– SSDdude
2 days ago
All I appreciate all the feedback but still no luck. It is sounding to me that there is no real good way to search sub-dirs. and extract ONLY the SINGE absolute latest log file in said directory. None of these answers do that. Thx.
– SSDdude
2 days ago
See the alternative interpretation update.
– JRFerguson
2 days ago
add a comment |
up vote
0
down vote
find $SEARCHDIR -type f -iname "computer_import_*.log" -mtime -10 > all_logs.txt
This will find all files that match the -iname
argument, restricted to being modified within 10-days of the run. See the find
manpages for more details.
Note that the -iname
argument is quoted so that find
interprets the argument rather than the shell before find
runs.
If you want to see what's returned based on these criteria do, for example:
find $SEARCHDIR -type f -iname "computer_import_*.log" -mtime -10 -exec ls -ld +
This will perform an ls
on each file returned, thus showing the last modification date. Change the value of -mtime <+-N>
to your taste. A value of -90
would return files modified in the last 90 days. A positive value of +90
would return files modified over 90 days ago.
** ALTERNATIVE INTERPRETATION **
Given the requirement to find only the most recent file in any and all sub-directories, do something like this:
find $SEARCHDIR -type d > /var/tmp/mydirs
while read -r line
do
ls -alt "$line" | grep -Ev "^(d|total)" | head -1 >> /var/tmp/mylogs
done < /var/tmp/mydirs
The ls
orders the contents of a directory as newest to oldest modification date. The grep
eliminates directory entries and total size lines. head
snips the first file (if any) from the directory being examined.
Thx, but this wont work because I could have the latest log be 3mo old or more.
– SSDdude
2 days ago
All I appreciate all the feedback but still no luck. It is sounding to me that there is no real good way to search sub-dirs. and extract ONLY the SINGE absolute latest log file in said directory. None of these answers do that. Thx.
– SSDdude
2 days ago
See the alternative interpretation update.
– JRFerguson
2 days ago
add a comment |
up vote
0
down vote
up vote
0
down vote
find $SEARCHDIR -type f -iname "computer_import_*.log" -mtime -10 > all_logs.txt
This will find all files that match the -iname
argument, restricted to being modified within 10-days of the run. See the find
manpages for more details.
Note that the -iname
argument is quoted so that find
interprets the argument rather than the shell before find
runs.
If you want to see what's returned based on these criteria do, for example:
find $SEARCHDIR -type f -iname "computer_import_*.log" -mtime -10 -exec ls -ld +
This will perform an ls
on each file returned, thus showing the last modification date. Change the value of -mtime <+-N>
to your taste. A value of -90
would return files modified in the last 90 days. A positive value of +90
would return files modified over 90 days ago.
** ALTERNATIVE INTERPRETATION **
Given the requirement to find only the most recent file in any and all sub-directories, do something like this:
find $SEARCHDIR -type d > /var/tmp/mydirs
while read -r line
do
ls -alt "$line" | grep -Ev "^(d|total)" | head -1 >> /var/tmp/mylogs
done < /var/tmp/mydirs
The ls
orders the contents of a directory as newest to oldest modification date. The grep
eliminates directory entries and total size lines. head
snips the first file (if any) from the directory being examined.
find $SEARCHDIR -type f -iname "computer_import_*.log" -mtime -10 > all_logs.txt
This will find all files that match the -iname
argument, restricted to being modified within 10-days of the run. See the find
manpages for more details.
Note that the -iname
argument is quoted so that find
interprets the argument rather than the shell before find
runs.
If you want to see what's returned based on these criteria do, for example:
find $SEARCHDIR -type f -iname "computer_import_*.log" -mtime -10 -exec ls -ld +
This will perform an ls
on each file returned, thus showing the last modification date. Change the value of -mtime <+-N>
to your taste. A value of -90
would return files modified in the last 90 days. A positive value of +90
would return files modified over 90 days ago.
** ALTERNATIVE INTERPRETATION **
Given the requirement to find only the most recent file in any and all sub-directories, do something like this:
find $SEARCHDIR -type d > /var/tmp/mydirs
while read -r line
do
ls -alt "$line" | grep -Ev "^(d|total)" | head -1 >> /var/tmp/mylogs
done < /var/tmp/mydirs
The ls
orders the contents of a directory as newest to oldest modification date. The grep
eliminates directory entries and total size lines. head
snips the first file (if any) from the directory being examined.
edited 2 days ago
answered 2 days ago
JRFerguson
9,54732329
9,54732329
Thx, but this wont work because I could have the latest log be 3mo old or more.
– SSDdude
2 days ago
All I appreciate all the feedback but still no luck. It is sounding to me that there is no real good way to search sub-dirs. and extract ONLY the SINGE absolute latest log file in said directory. None of these answers do that. Thx.
– SSDdude
2 days ago
See the alternative interpretation update.
– JRFerguson
2 days ago
add a comment |
Thx, but this wont work because I could have the latest log be 3mo old or more.
– SSDdude
2 days ago
All I appreciate all the feedback but still no luck. It is sounding to me that there is no real good way to search sub-dirs. and extract ONLY the SINGE absolute latest log file in said directory. None of these answers do that. Thx.
– SSDdude
2 days ago
See the alternative interpretation update.
– JRFerguson
2 days ago
Thx, but this wont work because I could have the latest log be 3mo old or more.
– SSDdude
2 days ago
Thx, but this wont work because I could have the latest log be 3mo old or more.
– SSDdude
2 days ago
All I appreciate all the feedback but still no luck. It is sounding to me that there is no real good way to search sub-dirs. and extract ONLY the SINGE absolute latest log file in said directory. None of these answers do that. Thx.
– SSDdude
2 days ago
All I appreciate all the feedback but still no luck. It is sounding to me that there is no real good way to search sub-dirs. and extract ONLY the SINGE absolute latest log file in said directory. None of these answers do that. Thx.
– SSDdude
2 days ago
See the alternative interpretation update.
– JRFerguson
2 days ago
See the alternative interpretation update.
– JRFerguson
2 days ago
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482161%2frecursively-find-only-the-latest-logs-in-all-sub-folders-and-save-to-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown