1

I'm using Linux Mint 18.3 and I have a school task to find all log files in one linux machine without any error messages. I need to put together a command and explain it throughly. I think I have found a way to use find but there is one access denied message regarding gvfs that I'm not sure how to handle. Can you help me assemble a simple and smart command that doesn't just blindly filter out any error messages but only leaves out those places where it's really no sense to look? My first try:

# find / -type f -name '*.log'

seems to return all log files but the result includes:

find: '/run/user/1000/gvfs': Permission denied

Then I tried to leave out one folder:

# find / -type d \( -name run \) -prune -o -type f -name '*.log' -print

but it doesn't seem smart to leave out the whole run folder so started to specify, to narrow it to one specific path maybe. Found this post, and unix.stackexchange.com/a/77592 answer, and tried to leave out this specific path:

# find / -name '*.log' -path '/run/user/1000/gvfs' -prune -o -type f -name '*.log' -print

but it doesn't seem to work as I expect, returning still the same, among seemingly all log files:

find: '/run/user/1000/gvfs': Permission denied

Now I run into understanding problem where I'm thinking wrong or is leaving out this one specific path the simplest and smartest thing to do at all.

  • Why not just hiding the error output ? find ... 2>/dev/null – Gilles Quenot Feb 14 '18 at 22:40
  • /dev/null is also a good discovery and gives ok result, thanks. – ktii Feb 15 '18 at 8:41
1

Log files are stored in /var/log so there's really no need to run find on the entire root directory. If you insist on doing so and want to exclude that directory so that you don't get errors then your syntax should be:

find / -wholename /run -prune -o -type f -name '*.log' -print

That directory is the mountpoint for FUSE and doesn't contain any log files and /run itself has directories (atleast in Centos, Fedora, and RHEL) inside which will give permission errors so the above command will exclude the directory altogether. I don't have Mint installed so you can edit the commmand to prune lower until you receive errors.

Also, one thing to keep in mind is that log files don't always end in .log such as messages, dmesg, cron, and secure.

  • /var/log would be simple but some log files seem to be elsewhere too. Your example works, thanks. But -path didn't work and reading about -path vs -wholename is a bit confusing but I'll try to chew it through. The last thing you say about log files is a good knowledge but confuses me even more because then I cannot be sure that I find literally all log files on that machine. – ktii Feb 15 '18 at 8:57
  • No problem. You can accept my answer. Depending on the distro and which one you use, rsyslog or journald tells the system where to store the log messages. As you're using Mint, the information for logging is located in the /etc/rsyslog.conf file. It's possible that someone has changed the options in that file to store logs elsewhere or that there's other software which has been configured to do the same. You are also correct in that you can't be certain that you've found all of the log files as they don't all end in .log. – Nasir Riley Feb 15 '18 at 11:48
0

Just do:

 find / -type f -name '*.log' 2>/dev/null

or

find /var -type f -name '*.log'

as far as logs should be in var

0

The correct idiom for avoiding the "permission denied" error messages is:

find <root-path> ! -readable -prune -o <rest of your find arguments>

Applying that to your original homework answer would yield:

find / ! -readable -prune -o -type f -name "*.log"

That should satisfy your requirement to "assemble a simple and smart command". It also fulfills the requirement "that doesn't just blindly filter out any error messages" because it only filters out unreadable stuff. Your final requirement "but only leaves out those places where it's really no sense to look" is another matter entirely, and would make a nice separate question, to wit, 'Is there a way for a script to find the default system log root directory, on the particular system on which the script is running?'. I'm unaware of an environment variable for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.