Linux Modules — TryHackMe Writeup

Helloww… world,

I don’t know why would anyone try to even read this…No offence, but this was literally an easy WALKTHROUGH room that I created, but still some people out there find it difficult to solve the tasks… So here’s a short cheatsheet for everybody out there who still have a little discrepancy in their minds, regarding the tasks being buggy 😃. TryHackMe

Awk Command

Question: Download the above given file, and use awk command to print the following output:


Well this was no difficult task… The answer was:

awk ‘BEGIN{OFS=”:”} {print $1,$4}’ awk.txt

“Errr… Wrong answer.”, yelled the page… Let’s try to view the hint now.

Ohh ok, so I guess that’s the twist in the question… We need to use FS too to submit the answer… Well, I know that FS is a field separator(acts as a delimiter for dividing the input line into fields). Well, by default, FS divides the fields using white spaces. So may be… We need to specify the obvious: (FS=” “) before the OFS. Alright then.

awk ‘BEGIN{FS=” “; OFS=”:”} {print $1,$4}’ awk.txt

Bingo, we got the answer

So my dear fellas, this was an intended twist for the question i.e. to include FS. As I want to explain the usage of multiple variables in one liner scripts. Again, the harder you think on a challenge, the more you gain from it 😉

Question: How will you make the output as following (there can be multiple; answer it using the above specified variables in BEGIN pattern):

ippsec, john, thecybermentor, liveoverflow, nahamsec, stok,

Well this was an easy task, just a little thinking… All we gotta do is change the Output Row Separator to a comma(,) and a space(‘ ‘)

awk ‘BEGIN{ORS=”, “} {print $1}’ awk.txt

Sed command

Question: How would you substitute every 3rd occurrence of the word ‘hack’ to ‘back’ on every line inside the file file.txt?

Normal Substitution:

sed ‘s/hack/back/3g’ file.txt

Question: How will you do the same operation only on 3rd and 4th line in file.txt?

Specifying conditions/area of search:

sed ‘3,4 s/hack/back/3g’ file.txt

Question: Download the given file, and try formatting the trailing spaces in sed1.txt with a colon(:).

Select the trailing spaces, and substitute it with (:)

sed ‘s/ */:/g’ sed1.txt

Question: View the sed2 file in the directory. Try putting all alphabetical values together, to get the answer for this question.

Believe it or not, this was a fun question… Yet tricky one… So, I specified the hint for that too… And hence, you could grab the string by selecting all the digits([[:digit:]]) and substituting it with… literally NOTHING. This is because we want to remove the digits in order to put those alphabets together… Therefore, if we run the sed command with this pattern:


It will give me the following string…


Question: What pattern did you use to reach that answer string?

Yeaps we already answered that in the previous question

Xargs command

Quesetion: You’re working in a team and your team leader sent you a list of files that needs to be created ASAP within current directory so that he can fake the synopsis report (that needs to be submitted within a minute or 2) to the invigilator and change the permissions to read-only to only you(Numberic representation). You can find the files list in the “one” folder.

Use the following flags in ASCII order:

  • Verbose
  • Take argument as “files”

Key points to note down from the question:

  • Read-only to only you(Numeric: 400)
  • Ascii order to use flags… -I files (take arg as files) and -t (verbose) (yes, Capital I comes before small t in ASCII)
  • Create files and also change permissions (sh -c “command1; command2”)
  • Use double quotes (From the hint)

Answer command:

cat file | xargs -I files -t sh -c “touch files; chmod 400 files”

Question: Your friend trying to run multiple commands in one line, and wanting to create a short version of rockyou.txt, messed up by creating files instead of redirecting the output into “shortrockyou”. Now he messed up his home directory by creating a ton of files. He deleted rockyou wordlist in that one liner and can’t seem to download it and do all that long process again.

He now seeks help from you, to create the wordlist and remove those extra files in his directory. You being a pro in linux, show him how it’s done in one liner way.

Use the following flags in ASCII order:

  • Take argument as “word”
  • Verbose
  • Max number of arguments should be 1 in for each file

You can find the files for this task in two folder.

Key points to note down from the question:

  • Create a wordlist with all the file names in directory
  • File name to save the names in: “shortrockyou”
  • Delete the files after appending the name into the file.
  • ASCII order of flags to use: “-I word -n 1 -t”
  • Use single quotes this time…

Answer command:

ls | xargs -I word -n 1 -t sh -c ‘echo word >> shortrockyou; rm word’

Question: Which flag to use to specify max number of arguments in one line.


Question: How will you escape command line flags to positional arguments?

(double hiphens; I can’t put them here as medium interpret it as — )

Special Mention

There were no bugs in the following questions. The reason why most people are getting different results with sort and uniq commands is because of this $LANG variable (that’s set during installation of your linux OS; when you choose the language to install and keyboard layout). If you’re not getting the correct answer, change the value of $LANG variable to ‘en_US.UTF-8’. Your terminal will then output the results accurately.

export LANG=’en_US.UTF-8’

Question: Download the file given for this task, find the uniq items after sorting the file. What is the 2271st word in the output.


Question: What was the index of term ‘michele’


This is it for this writeup, the most difficult and annoying problems that you were facing, hope are now resolved. Again, this was a walkthrough room, the only purpose was to learn new modules that can be extremely helpful in messy situations, so it’s fine if you copy… But try to carry those concepts with you, for the rest of your hacking journey. If you still got any doubts, you can find me on twitter with the same handle: j4x0n. I’ll be happy to help 😉.


Nehh, just a n00b

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store