Skip to the content.

đź”— Link to the Room

🏷️ Table of Contents

  1. A Bit of Background on Linux
    1.1 Where is Linux Used?
    1.2 Flavours of Linux
  2. Interacting With Your First Linux Machine (In-Browser)
  3. Running Your First few Commands
  4. Interacting with the Filesystem!
    5.1 Listing Files in Our Current Directory with ls
    5.2 Changing Our Current Directory with cd
    5.3 Outputting the Contents of a File with cat
    5.4 Finding out the full Path to our Current Working Directory with pwd
  5. Searching for files
    6.1 Using Find
    6.2 Using Grep
    6.3 Searching Recursively with grep
  6. An Introduction to Shell Operators

📚 Study Notes

A Bit of Background on Linux

 

Where is Linux Used?

 

Flavours of Linux

The name “Linux” is actually an umbrella term for multiple OS’s that are based on UNIX (another operating system). For example, Ubuntu & Debian are distributions of Linux. You can also run Ubuntu as a server (such as websites & web applications) or as a fully-fledged desktop. Note: Ubuntu Server can run on systems with only 512MB of RAM!

Similar to how you have different versions Windows (7, 8 and 10), there are many different versions/distributions of Linux.

 


❓Research: What year was the first release of Linux operating system?1991

 

Interacting With Your First Linux Machine (In-Browser)

 

This room has a Ubuntu Linux machine that you can interact with all within your browser.

Now is your turn to deploy your first Linux machine.

 

Running Your First few Commands

 

In Linux there is often no GUI (Graphical User Interface) or what is also known as a desktop environment Most of the time we interact with these systems using terminal, which is text-based.

At first you need to learn basics such as how to navigate to these files, output their contents or create some new ones.

Command Description
echo Ouptut any text that you provide
whoami Find out what user you’re currently logged in as

To echo single word use echo word To echo string (sentence) enclose it in double quotes: `echo “More words” Example:

image

 


❓If we wanted to output the text "TryHackMe", what would our command be?echo TryHackMe

❓What is the username of who you're logged in as on your deployed Linux machine?tryhackme

 

Interacting with the Filesystem!

 

Command Full Name
ls listing
cd change directory
cat concentrate
pwd print working directory

 

Listing Files in Our Current Directory with ls

image

Tip: You can list the contents of a directory without having to navigate to it by using ls and the name of the directory. For example ls Pictures

 

Changing Our Current Directory with cd

cd is short for change directory, hence to open directory (folder) use cd Your_Directory Then to check its content use ls again:

image

In this case, there are 4 pictures of dogs.

 

Outputting the Contents of a File with cat

Cat is short for concatenating and it’s a fantastic way for us to output the contents of files (not just text files).

image

Tip: You can use cat to output the contents of a file within directories without having to navigate to it by using cat and the name of the directory. For example: cat /home/ubuntu/Documents/todo.txt

 

Finding out the full Path to our Current Working Directory with pwd

pwd stands for print working directory.

image

 


❓On the Linux machine that you deploy, how many folders are there?4

❓Which directory contains a file?folder4

❓What is the contents of this file?Hello World!

❓Use the cd command to navigate to this file and find out the new current working directory. What is the path?/home/tryhackme/folder4

 

Searching for files

 

You can use find let you quickly search the whole system instead of manually navigating with cd and ls.

 

Using Find

find in Linux is used to quickly search for files inside folders and subfolders; you can search by an exact filename (e.g., find -name passwords.txt) or by a pattern like all .txt files using a wildcard (find -name "*.txt").

Using find to find a file with the name of passwords.txt:

image

Using find to find any file with the extension of .txt:

image

 

Using Grep

grep in Linux searches inside files for specific text and shows the lines where it appears (e.g., grep "81.143.211.90" access.log finds all log entries containing that IP address).

Using wc to count the number of entries in access.log:

image

Using grep to find any entries with the IP address of “81.143.211.90” in access.log:

image

Grep has searched through this file and has shown you any entries of what you’ve provided and that is contained within this log file for the IP.

 

Searching Recursively with grep

Using grep -R lets you search for specific text across all files and subfolders in a directory, showing where the text appears and which file contains it.

-R means recursive option.

Example: To search for a variable across all files in the current directory and its subfolders: grep -R "PRETTY_NAME" /etc/ Example Output: image

The file path is shown before the matching line, making it easy to identify where the result was found.

 


❓Use grep on "access.log" to find the flag that has a prefix of "THM". What is the flag? Note: The "access.log" file is located in "/home/tryhackme/" directory.THM{******}

 

An Introduction to Shell Operators

 

Shell operators in Linux let you control how commands run:

 


❓If we wanted to run a command in the background, what operator would we want to use?&

❓If we wanted to replace the contents of a file named "passwords" with the word "password123", what would my command be?echo password123 > passwords

❓Now if we wanted to add "tryhackme" to this file named "passwords" but also keep "passwords123", what would my command beecho tryhackme >> passwords

Â