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

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

Reading the question carefully

  • It says “on the system”, this indicates the path
  • then you need to be smart about the issue you see. it is using all you learned in this particular area

I did this and gort the right answer. Yes I had to read it carefully to get to my results

For anyone searching through this who still needs help

1.) In VM → open terminal and type ‘ssh htb-student@(TARGET IP)’
2.) enter password i.e (HTB_@cademy_stdnt!)
NOTE: You spawn in the wrong directory! To Fix:
3.) type ‘cd…’ until you are in ‘htb-student@nixfund:/$’ . This is the directory for ENTIRE target system.
4.) Now type find -type f -name * .log | wc -l (< Thats an L)
5.) Now you should have the correct answer (mine was 32, could be random for everyone)

~Good Luck
Cold<3

1 Like

hi there some problem in this question instance
$ find / -name *.log 2>/dev/null wc -l
$ find -name *.log 2>/dev/null | wc -l
$ find /var/ -name *.log 2>/dev/null | wc -l

you going to get different ans ???

Most people are very close to doing this correct. Think about everything you learned in “Find Files and Directories” AND “File Descriptors and Redirections”

We have predominantly been using the tool ‘find’. We’ve ventured into finding files with ‘-type f’, the name it contains with ‘-name’, who it belongs to and if “root” has access (-user root), how to redirect errors into a directory that discards all data automatically (2>/dev/null) to filter out the results we want to see.

With this in mind, we are being asked to “find out” how many ‘files’ (-type f) exist on the system with ‘.log’ extension, we know we need to use the ‘find’ command. We know it’s asking for ‘files’, we know it has already given us the file name so will still need to be specified (-name .log) and we know how to filter the word count with command used in the module before.

find -type f -name *.log | wc -l

With this command, if done correctly will show all the stderr (standard errors) and will place the ‘wc’ at the bottom. To get just the count, again, make sure you are sending the errors to the null device (2>/dev/null | wc -l)

If you do not get an answer the is correct, it will be because the command we are using is searching for things in the directory we are in. Make sure you are;

  • Not including any spaces in the scripting that are not intended
  • Are not starting from a random directory (cd to root is always the best place to start - ‘cd /’)
  • Logged in to the target machine via SSH as the question is asking for .log files on that machine, not your account with HTB.
1 Like

the -iname command was not listed within the tutorial and was unsure of which directory to search in… this command searches the entire system. TYTY.

@TazWake thanks for your guidance! I agree that some info on the guides is very vague for noobs.

Mine show 33. Why ? Then I tried enter 32, the answer is correct

Hey Everybody I found the Solution to all of the problems just run this command after ssh into your target :dart: system

Command –

find / -type f -name "*.log" 2>/dev/null | wc -l

And the corrected solution is –
[ 32 ] log files are present

Hey Guys i got answer : as we learned recently use of 2>/dev/null just use it

find / -type f -name "*.log" 2>/dev/null | wc -l