Linux Fundamentals: How many files exist on the system that have the ".log" file extension?

So I have been on this question for a couple days and have searched the web dozens of times and for some reason I cant get the answer they want…

I’ve tried tons of variations of commands I’ve learned from the module and from the web but had no success. I really don’t understand what I’m missing here?

The question : How many files exist on the system that have the “.log” file extension?

I have always made sure to ssh to the spawned system.

I’ve tried
find / *.log
find / -type f -name *.log
find / -type f -name *.log | wc -l
find / -type f -name .log 2>/dev/null | wc -l

I’ve tried using “.” instead of “/”
I’ve tried using the “*.log”
I’ve tried using locate and other commands… I’ve honestly tried so much more then I just listed but I’m completely lost now. I just don’t understand how to view the exact number of files with the .log extension?
I’ve gotten multiple answers (different numbers).
If I don’t use the 2>/dev/null command then I get massive lists of permission denied…

My head is spinning now from trying to figure this out for the last few days on and off and I’m stumped. Any help is much appreciated because I would like to move along with my studies… This question has gotten me a bit discouraged to say the least… Thanks!

2 Likes

@aintnosaint said:

The question : How many files exist on the system that have the “.log” file extension?

I’ve tried
find / *.log
find / -type f -name *.log
find / -type f -name *.log | wc -l
find / -type f -name .log 2>/dev/null | wc -l

Questions like this are always challenging because there are lots of ways to carve information and count it on a Linux filesystem.

So - with the caveat that I have no idea what the correct answer is here - this is how I would approach it.

The question asks how many files on the system have a .log extension. So my find command would start as:
find / -type f -iname "*.log" 2>/dev/null | wc -l

I would use / because they ask for the whole system and I’d use -iname to make it a case insensitive search (assuming they meant .LOG or .log to count - this could be incorrect). I’d put the *.log in quotes to stop the shell expanding the wildcard before find does.

If this gives an incorrect number, I’d check the results and see if anything weird had been returned. This is easy - find / -type f -iname "*.log" 2>/dev/null - then if spurious data exists, I’d modify the search based on what it returned. Without looking at the data, its very hard to know why the find is returning the wrong number of files.

2 Likes

Type your comment> @TazWake said:

@aintnosaint said:

The question : How many files exist on the system that have the “.log” file extension?

I’ve tried
find / *.log
find / -type f -name *.log
find / -type f -name *.log | wc -l
find / -type f -name .log 2>/dev/null | wc -l

Questions like this are always challenging because there are lots of ways to carve information and count it on a Linux filesystem.

So - with the caveat that I have no idea what the correct answer is here - this is how I would approach it.

The question asks how many files on the system have a .log extension. So my find command would start as:
find / -type f -iname "*.log" 2>/dev/null | wc -l

I would use / because they ask for the whole system and I’d use -iname to make it a case insensitive search (assuming they meant .LOG or .log to count - this could be incorrect). I’d put the *.log in quotes to stop the shell expanding the wildcard before find does.

If this gives an incorrect number, I’d check the results and see if anything weird had been returned. This is easy - find / -type f -iname "*.log" 2>/dev/null - then if spurious data exists, I’d modify the search based on what it returned. Without looking at the data, its very hard to know why the find is returning the wrong number of files.

So its not just me then, this is a poorly worded question? Because I have already tried your suggestion… I’ve seriously exhausted myself on this one…

@aintnosaint said:

So its not just me then, this is a poorly worded question? Because I have already tried your suggestion… I’ve seriously exhausted myself on this one…

I think it depends on the specific wording, but yes - questions like this can be hard to answer without digging in.

Have you checked the output of the find command to see if anything unusual has been counted in the wc -l bit?

Also, can I check which question you are working on? I’ve just had a look at the module and the question I found in Linux Fundamentals is:

How many files exist on the system that have the ".bak" extension?

Am I looking at the wrong question?

1 Like

Type your comment> @TazWake said:

@aintnosaint said:

So its not just me then, this is a poorly worded question? Because I have already tried your suggestion… I’ve seriously exhausted myself on this one…

I think it depends on the specific wording, but yes - questions like this can be hard to answer without digging in.

Have you checked the output of the find command to see if anything unusual has been counted in the wc -l bit?

Also, can I check which question you are working on? I’ve just had a look at the module and the question I found in Linux Fundamentals is:

How many files exist on the system that have the ".bak" extension?

Am I looking at the wrong question?

Yes that was an older question which I actually got correct using the same methods I am now. The difference is this time it won’t accept my answer as correct. If I recall correctly the .bak question only had like 4 files or so so it was easy to count just by looking at the list. The .log extension seems to have many more files but so many of them I don’t have permission to see as it would seem. I will boot up my workstation and try again… This is day 4 on this question.

@TazWake said:
@aintnosaint said:

So its not just me then, this is a poorly worded question? Because I have already tried your suggestion… I’ve seriously exhausted myself on this one…

I think it depends on the specific wording, but yes - questions like this can be hard to answer without digging in.

Have you checked the output of the find command to see if anything unusual has been counted in the wc -l bit?

Also, can I check which question you are working on? I’ve just had a look at the module and the question I found in Linux Fundamentals is:

How many files exist on the system that have the ".bak" extension?

Am I looking at the wrong question?

Okay so this is what I get back

htb-student@nixfund:~$ find / -type f -iname “*.log” 2>/dev/null | wc -l

(NUMBER)

And when I remove the (wc-l) I get the following…

htb-student@nixfund:~$ find / -type f -iname “*.log” 2>/dev/null

/var/log/installer/curtin-install.log
/var/log/installer/block/discover.log
/var/log/installer/subiquity-debug.log
/var/log/mail.log
/var/log/proftpd/controls.log
/var/log/proftpd/proftpd.log
/var/log/vmware-vmsvc.log
/var/log/fontconfig.log
/var/log/bootstrap.log
/var/log/kern.log
/var/log/dpkg.log
/var/log/vmware-vmsvc-root.3.log
/var/log/vmware-vmsvc-root.log
/var/log/alternatives.log
/var/log/vmware-network.log
/var/log/vmware-vmsvc-root.2.log
/var/log/vmware-vmtoolsd-root.log
/var/log/apt/history.log
/var/log/apt/term.log
/var/log/cloud-init.log
/var/log/landscape/sysinfo.log
/var/log/cloud-init-output.log
/var/log/auth.log
/var/log/vmware-vmsvc-root.1.log
/run/cloud-init/ds-identify.log
/run/cloud-init/cloud-init-generator.log
/run/initramfs/overlayroot.log
/usr/share/grc/conf.log
/snap/powershell/137/opt/powershell/Modules/PowerShellGet/GovCompDisc_Log_20200422202439.log
/snap/powershell/137/opt/powershell/Modules/PowerShellGet/GovCompDisc_Log_20200422202549.log

@aintnosaint said:

Okay so this is what I get back

htb-student@nixfund:~$ find / -type f -iname “*.log” 2>/dev/null | wc -l

Just to check - what happens when you submit that as an answer?

I’ve tried the lab and I get the same number as you do, but it marks it correct.

Type your comment> @TazWake said:

@aintnosaint said:

Okay so this is what I get back

htb-student@nixfund:~$ find / -type f -iname “*.log” 2>/dev/null | wc -l

Just to check - what happens when you submit that as an answer?

I’ve tried the lab and I get the same number as you do, but it marks it correct.

When I submit the answer it says its incorrect. I get a red popup on the top right as I usually do when the answer is wrong.

@aintnosaint said:
Type your comment> @TazWake said:

@aintnosaint said:

Okay so this is what I get back

htb-student@nixfund:~$ find / -type f -iname “*.log” 2>/dev/null | wc -l

Just to check - what happens when you submit that as an answer?

I’ve tried the lab and I get the same number as you do, but it marks it correct.

When I submit the answer it says its incorrect. I get a red popup on the top right as I usually do when the answer is wrong.

Okay so I just tried again after re booting every thing and now it accepts my answer…
I swear I used that answer the first time and several attempts more over the last few days and it kept saying it was wrong… :frowning:
Sorry for wasting time… That was really weird.

1 Like

@aintnosaint said:

Okay so I just tried again after re booting every thing and now it accepts my answer…
I swear I used that answer the first time and several attempts more over the last few days and it kept saying it was wrong… :frowning:
Sorry for wasting time… That was really weird.

No worries - things like that happen to me all the time. I am just glad you’ve made it past this now!

Thanks for being patient!

1 Like

Hi i`ve been reading this topic in order to answer 3 questions:

  1. How many files exist on the system that have the “.bak” file extension?
  2. How many files exist on the system that have the “.log” file extension?
  3. How many total packages are installed on the target system?

So i use this commands:

  1. find / -name “*.bak” 2>/dev/null | wc -l
  2. find / -name “*.log” 2>/dev/null | wc -l
  3. apt list --installed | wc -l

The results of the output are:

  1. 1
  2. 136
  3. 3602

The 3 results are incorrect answers… i dont understand what is wrong, can sombody help me?
I know the answer for question number 1 is 4 by reading this topic but i can only obtein 1 as an output.

When I tried the 3. command I had a completely different result. My result was 738. The answer was incorrect. Then I just tried to type in 737 and it was correct. Does anybody know why there was one more package listed?

1 Like

You answered it wonderfully. Thank you!

Here is the original syntax from HTB on the “find files and directories” page.

 find / -type f -name *.conf -user root -size +20k -newermt 2020-03-03 -exec ls -al {} \; 2>/dev/null

So start breaking it down. Do you need a -user since you are already logged in? no. Scratch that. Now we have this.

 find / -type f -name *.conf  -size +20k -newermt 2020-03-03 -exec ls -al {} \; 2>/dev/null

Does the question ask for size of the files? No. Scratch that and now we have this.

 find / -type f -name *.conf  -newermt 2020-03-03 -exec ls -al {} \; 2>/dev/null

Does the question ask for a date for the file? No. Scratch that. And now we have this.

 find / -type f -name *.conf  -exec ls -al {} \; 2>/dev/null

Does the question ask for a .conf file? No it asks for a log file. Scratch and edit. And now we have this.

 find / -type f -name *.log -exec ls -al {} \; 2>/dev/null

I did not get a number to count. But I do know how to add the results. Or, be goofy and copy and paste into excel to get your number.

I did notice that a lot of comments had things like "" in their syntax and added a few flags outside of the original syntax. Although its awesome to be creative and in fact some of those syntax add-ons may work elsewhere, just remember that HTB is not trying to throw you for a loop. If its not in the Modules then it probably wont work. Stick to whats being taught.
If it aint broke, dont fix it.

**ring ring**

Call Center: Call cneter to fix all your computer needs, may I help you?

Caller: My computer isnt working. Help!

Call Center: is it plugged in?


Sometimes the simplest things work best. Use the KISS method.

Keep 
It
Simple
Stupid

Happy Hunting.
2 Likes

i was having a similar issue with the question ‘How many files exist on the system that have the “.bak” extension?’ where i kept getting 1 as the answer until i realized i didnt ssh to the target than i got the correct answer of 4

  1. *find / -name .bak 2>/dev/null will return all files with .bak extension and using |wc - l will give a count of them.

This command worked for me for both logs and bak files:

find / -type f -name *.bak -exec ls -al {} ; 2>/dev/null |wc -l

Try:
locate *.bak | wc -l

1 Like

I tried this and got the correct answer:
htb-student@nixfund:~$ find / -name “*.log” 2>/dev/null | wc -l
32

1 Like

if you run ‘apt list --installed’ first line of output is ‘Listing… Done’ so you need to exclude that line. To get the correct answer command should be ‘apt list --installed | grep “installed” | wc -l’ this will exclude the first line of the output.

1 Like