Linux: find files *.log in directory trees and write 10 last lines in each
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I need to find all files, that ends with .log in directory /var and all its trees-directories; and to write ten last lines of each of these *.log files
cd /var
sudo find -name '*.log' -print
This command allows me to find these files. What I see is:
./log/auth.log
./log/Xorg.0.log
....
./log/apt/term.log
.log/alternatives.log
I've tried to usefor var in sudo find -name '*.log'; do tail -n 10 $var; done
to print the lines, but there was an error. So what command should I use in order to find files and print the lines?
linux
add a comment |Â
up vote
0
down vote
favorite
I need to find all files, that ends with .log in directory /var and all its trees-directories; and to write ten last lines of each of these *.log files
cd /var
sudo find -name '*.log' -print
This command allows me to find these files. What I see is:
./log/auth.log
./log/Xorg.0.log
....
./log/apt/term.log
.log/alternatives.log
I've tried to usefor var in sudo find -name '*.log'; do tail -n 10 $var; done
to print the lines, but there was an error. So what command should I use in order to find files and print the lines?
linux
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to find all files, that ends with .log in directory /var and all its trees-directories; and to write ten last lines of each of these *.log files
cd /var
sudo find -name '*.log' -print
This command allows me to find these files. What I see is:
./log/auth.log
./log/Xorg.0.log
....
./log/apt/term.log
.log/alternatives.log
I've tried to usefor var in sudo find -name '*.log'; do tail -n 10 $var; done
to print the lines, but there was an error. So what command should I use in order to find files and print the lines?
linux
I need to find all files, that ends with .log in directory /var and all its trees-directories; and to write ten last lines of each of these *.log files
cd /var
sudo find -name '*.log' -print
This command allows me to find these files. What I see is:
./log/auth.log
./log/Xorg.0.log
....
./log/apt/term.log
.log/alternatives.log
I've tried to usefor var in sudo find -name '*.log'; do tail -n 10 $var; done
to print the lines, but there was an error. So what command should I use in order to find files and print the lines?
linux
linux
asked Oct 1 '17 at 16:40
ÃÂøúþûðù ÃÂÃÂÃÂñð
285
285
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Try this:
find /var -name "*.log" -type f -exec tail '' +
Explanation:
-type f
- find only files
-exec <command> +
- execute command. See man find for more information
Or:
for i in $(find /var -name "*.log" -type f); do echo $i; tail $i; done
Gets the same output but with slight format difference
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Try this:
find /var -name "*.log" -type f -exec tail '' +
Explanation:
-type f
- find only files
-exec <command> +
- execute command. See man find for more information
Or:
for i in $(find /var -name "*.log" -type f); do echo $i; tail $i; done
Gets the same output but with slight format difference
add a comment |Â
up vote
2
down vote
accepted
Try this:
find /var -name "*.log" -type f -exec tail '' +
Explanation:
-type f
- find only files
-exec <command> +
- execute command. See man find for more information
Or:
for i in $(find /var -name "*.log" -type f); do echo $i; tail $i; done
Gets the same output but with slight format difference
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Try this:
find /var -name "*.log" -type f -exec tail '' +
Explanation:
-type f
- find only files
-exec <command> +
- execute command. See man find for more information
Or:
for i in $(find /var -name "*.log" -type f); do echo $i; tail $i; done
Gets the same output but with slight format difference
Try this:
find /var -name "*.log" -type f -exec tail '' +
Explanation:
-type f
- find only files
-exec <command> +
- execute command. See man find for more information
Or:
for i in $(find /var -name "*.log" -type f); do echo $i; tail $i; done
Gets the same output but with slight format difference
edited Oct 1 '17 at 16:51
answered Oct 1 '17 at 16:44
Egor Vasilyev
1,792129
1,792129
add a comment |Â
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%2f395485%2flinux-find-files-log-in-directory-trees-and-write-10-last-lines-in-each%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