đź”— Link to the Room
🏷️ Table of Contents
- A Bit of Background on Linux
1.1 Where is Linux Used?
1.2 Flavours of Linux - Interacting With Your First Linux Machine (In-Browser)
- Running Your First few Commands
- 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 - Searching for files
6.1 Using Find
6.2 Using Grep
6.3 Searching Recursively with grep - An Introduction to Shell Operators
📚 Study Notes
A Bit of Background on Linux
Â
Where is Linux Used?
- websites
- car entertainment/control panels
- Point of Sale (PoS) systems - checkout tills, registers, …
- critical infrastructures - traffic light controllers, industrial sensors, …
Â
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:
Â
❓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
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:
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).
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.
Â
❓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:
Using find to find any file with the extension of .txt:
Â
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:
Using grep to find any entries with the IP address of “81.143.211.90” in access.log:
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:
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:
&runs a command in the background&&runs the next command only if the first succeeds>sends command output to a file (overwriting it)>>adds output to the end of a file without deleting existing content
Â
❓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 be
echo tryhackme >> passwords
Â