how to echo find command
For a raspberry backup bash-script I want to log which and how many older backups are deleted.
I use
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete
to clean.
How do I count and display and log to a file which files are deleted?
bash find
New contributor
add a comment |
For a raspberry backup bash-script I want to log which and how many older backups are deleted.
I use
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete
to clean.
How do I count and display and log to a file which files are deleted?
bash find
New contributor
add a comment |
For a raspberry backup bash-script I want to log which and how many older backups are deleted.
I use
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete
to clean.
How do I count and display and log to a file which files are deleted?
bash find
New contributor
For a raspberry backup bash-script I want to log which and how many older backups are deleted.
I use
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete
to clean.
How do I count and display and log to a file which files are deleted?
bash find
bash find
New contributor
New contributor
edited 1 hour ago
Thomas
3,70061225
3,70061225
New contributor
asked 1 hour ago
Thuurke
1
1
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
find
has an fprint
action that can write the results of the find command to a file. You can then extend your command as:
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -fprint /path/to/log.txt -delete
You can then retrieve the file count from the log file, by using wc
:
cat /path/to/log.txt | wc -l
If special characters can appear in the results of find, you can use the the fprint0
option as an alternative. This will write the results to the specified file as null-delimited strings.
To count the items in the resulting file, you can look the options discussed under this question: Count null delimited items in file.
1
Not all implementations offind
supportfprint
, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc:wc -l <FILE>
is enough.
– Arkadiusz Drabczyk
1 hour ago
@ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage ofcat
, I used it so that the output is only a number.wc
shows the filename beside the count with thewc -l file
syntax.
– Haxiel
54 mins ago
add a comment |
You can use the -print
option of find
, to output the files that are deleted, then pipe things to tee
to write results into a logfile. And finally count the lines of the deleted files and append it in the logfile.
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete -print | tee ${LOGFILE} | wc -l | xargs echo "Files deleted:" >> ${LOGFILE}
If you want to append new results to the same ${LOGFILE}
you would have to use tee -a
.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Thuurke is a new contributor. Be nice, and check out our Code of Conduct.
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%2f491302%2fhow-to-echo-find-command%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
find
has an fprint
action that can write the results of the find command to a file. You can then extend your command as:
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -fprint /path/to/log.txt -delete
You can then retrieve the file count from the log file, by using wc
:
cat /path/to/log.txt | wc -l
If special characters can appear in the results of find, you can use the the fprint0
option as an alternative. This will write the results to the specified file as null-delimited strings.
To count the items in the resulting file, you can look the options discussed under this question: Count null delimited items in file.
1
Not all implementations offind
supportfprint
, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc:wc -l <FILE>
is enough.
– Arkadiusz Drabczyk
1 hour ago
@ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage ofcat
, I used it so that the output is only a number.wc
shows the filename beside the count with thewc -l file
syntax.
– Haxiel
54 mins ago
add a comment |
find
has an fprint
action that can write the results of the find command to a file. You can then extend your command as:
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -fprint /path/to/log.txt -delete
You can then retrieve the file count from the log file, by using wc
:
cat /path/to/log.txt | wc -l
If special characters can appear in the results of find, you can use the the fprint0
option as an alternative. This will write the results to the specified file as null-delimited strings.
To count the items in the resulting file, you can look the options discussed under this question: Count null delimited items in file.
1
Not all implementations offind
supportfprint
, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc:wc -l <FILE>
is enough.
– Arkadiusz Drabczyk
1 hour ago
@ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage ofcat
, I used it so that the output is only a number.wc
shows the filename beside the count with thewc -l file
syntax.
– Haxiel
54 mins ago
add a comment |
find
has an fprint
action that can write the results of the find command to a file. You can then extend your command as:
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -fprint /path/to/log.txt -delete
You can then retrieve the file count from the log file, by using wc
:
cat /path/to/log.txt | wc -l
If special characters can appear in the results of find, you can use the the fprint0
option as an alternative. This will write the results to the specified file as null-delimited strings.
To count the items in the resulting file, you can look the options discussed under this question: Count null delimited items in file.
find
has an fprint
action that can write the results of the find command to a file. You can then extend your command as:
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -fprint /path/to/log.txt -delete
You can then retrieve the file count from the log file, by using wc
:
cat /path/to/log.txt | wc -l
If special characters can appear in the results of find, you can use the the fprint0
option as an alternative. This will write the results to the specified file as null-delimited strings.
To count the items in the resulting file, you can look the options discussed under this question: Count null delimited items in file.
edited 58 mins ago
answered 1 hour ago
Haxiel
1,099310
1,099310
1
Not all implementations offind
supportfprint
, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc:wc -l <FILE>
is enough.
– Arkadiusz Drabczyk
1 hour ago
@ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage ofcat
, I used it so that the output is only a number.wc
shows the filename beside the count with thewc -l file
syntax.
– Haxiel
54 mins ago
add a comment |
1
Not all implementations offind
supportfprint
, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc:wc -l <FILE>
is enough.
– Arkadiusz Drabczyk
1 hour ago
@ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage ofcat
, I used it so that the output is only a number.wc
shows the filename beside the count with thewc -l file
syntax.
– Haxiel
54 mins ago
1
1
Not all implementations of
find
support fprint
, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc: wc -l <FILE>
is enough.– Arkadiusz Drabczyk
1 hour ago
Not all implementations of
find
support fprint
, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc: wc -l <FILE>
is enough.– Arkadiusz Drabczyk
1 hour ago
@ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage of
cat
, I used it so that the output is only a number. wc
shows the filename beside the count with the wc -l file
syntax.– Haxiel
54 mins ago
@ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage of
cat
, I used it so that the output is only a number. wc
shows the filename beside the count with the wc -l file
syntax.– Haxiel
54 mins ago
add a comment |
You can use the -print
option of find
, to output the files that are deleted, then pipe things to tee
to write results into a logfile. And finally count the lines of the deleted files and append it in the logfile.
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete -print | tee ${LOGFILE} | wc -l | xargs echo "Files deleted:" >> ${LOGFILE}
If you want to append new results to the same ${LOGFILE}
you would have to use tee -a
.
add a comment |
You can use the -print
option of find
, to output the files that are deleted, then pipe things to tee
to write results into a logfile. And finally count the lines of the deleted files and append it in the logfile.
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete -print | tee ${LOGFILE} | wc -l | xargs echo "Files deleted:" >> ${LOGFILE}
If you want to append new results to the same ${LOGFILE}
you would have to use tee -a
.
add a comment |
You can use the -print
option of find
, to output the files that are deleted, then pipe things to tee
to write results into a logfile. And finally count the lines of the deleted files and append it in the logfile.
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete -print | tee ${LOGFILE} | wc -l | xargs echo "Files deleted:" >> ${LOGFILE}
If you want to append new results to the same ${LOGFILE}
you would have to use tee -a
.
You can use the -print
option of find
, to output the files that are deleted, then pipe things to tee
to write results into a logfile. And finally count the lines of the deleted files and append it in the logfile.
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete -print | tee ${LOGFILE} | wc -l | xargs echo "Files deleted:" >> ${LOGFILE}
If you want to append new results to the same ${LOGFILE}
you would have to use tee -a
.
answered 44 mins ago
Thomas
3,70061225
3,70061225
add a comment |
add a comment |
Thuurke is a new contributor. Be nice, and check out our Code of Conduct.
Thuurke is a new contributor. Be nice, and check out our Code of Conduct.
Thuurke is a new contributor. Be nice, and check out our Code of Conduct.
Thuurke is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f491302%2fhow-to-echo-find-command%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