INTRODUCTION TO
LINUX
Reference: Tryhackme
Welcome to the first part of the "Linux Fundamentals"
room series. You're most likely using a Windows or Mac
machine, both are different in visual design and how they
operate. Just like Windows, iOS and MacOS, Linux is just
another operating system and one of the most popular in
the world powering smart cars, android devices,
supercomputers, home appliances, enterprise servers, and
more.
We'll be covering some of the history behind Linux and
then eventually starting your journey of being a
Linux-wizard! This room will have you:
● Running your very first commands in an interactive
Linux machine in your browser
● Teaching you some essential commands used to
interact with the file system
● Demonstrate how you can search for files and
introduce shell operators
Where is Linux Used?
It's fair to say that Linux is a lot more intimidating to approach than Operating System's (OSs) such as Windows. Both variants have
their own advantages and disadvantages. For example, Linux is considerably much more lightweight and you'd be surprised to
know that there's a good chance you've used Linux in some form or another every day! Linux powers things such as:
● Websites that you visit
● Car entertainment/control panels
● Point of Sale (PoS) systems such as checkout tills and registers in shops
● Critical infrastructures such as traffic light controllers or 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). Thanks to
Linux being open-source, variants of Linux come in all shapes and sizes - suited best for what the system is being used for.
For example, Ubuntu & Debian are some of the more commonplace distributions of Linux because it is so extensible. I.e. you can
run Ubuntu as a server (such as websites & web applications) or as a fully-fledged desktop. For this series, we're going to be using
Ubuntu.
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
Interacting With Your First Linux Machine (In-Browser)
As we previously discussed, a large selling point of using OSs such as Ubuntu is how lightweight they can be. This, of course,
doesn't come without its disadvantages, where for example, often there is no GUI (Graphical User Interface) or what is also
known as a desktop environment that we can use to interact with the machine (unless it has been installed). A large part of
interacting with these systems is using the "Terminal".
The "Terminal" is purely text-based and is intimidating at first. However, if we break down some of the commands, after some
time, you quickly become familiar with using the terminal!
See the snippets below for an example of each command being used
So far we've only covered the "echo" and "whoami" commands. Not all that useful when you consider things that we need to do -
including navigating the filesystem, read and write to it as well.
In this task, we're going to be learning the commands so that we can do just that. Just like the previous task, I'll display the
commands in the table in the next heading & show examples of these commands being used.
Listing Files in Our Current Directory (ls)
Before we can do anything such as finding out the contents of any files or folders, we need to know what
exists in the first place. This can be done using the "ls" command (short for listing)
In the screenshot above, we can see there are the following directories/folders:
● Important Files
● My Documents
● Notes
● Pictures
Great! You can probably take a guess as to what to expect a folder to contain given by its name.
Pro tip: You can list the contents of a directory without having to navigate to it by using ls and the
name of the directory. I.e. ls Pictures
Changing Our Current Directory (cd)
Outputting the Contents of a File (cat)
Whilst knowing about the existence of files is great — it's not all that useful unless we're able to
view the contents of them.
We will come on to discuss some of the tools available to us that allows us to transfer files from
one machine to another in a later room. But for now, we're going to talk about simply seeing the
contents of text files using a command called "cat".
"Cat" is short for concatenating & is a fantastic way for us to output the contents of files (not just
text files!).
In the screenshot below, you can see how I have combined the use of "ls" to list the files within a
directory called "Documents":
We've applied some knowledge from earlier in this task to do the following:
1. Used "ls" to let us know what files are available in the "Documents" folder of this machine. In
this case, it is called "[Link]".
2. We have then used cat [Link] to concatenate/output the contents of this "[Link]" file,
where the contents are "Here's something important for me to do later!"
Pro 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. I.e. cat /home/ubuntu/Documents/[Link]
Finding out the full Path to our Current Working Directory (pwd)
You'll notice as you progress through navigating your Linux machine, the name of the directory that you are currently
working in will be listed in your terminal.
It's easy to lose track of where we are on the filesystem exactly, which is why I want to introduce "pwd". This stands for
print working directory.
Using the example machine from before, we are currently in the "Documents" folder — but where is this exactly on the
Linux machine's filesystem? We can find this out using this "pwd" command like within the screenshot below.
Although it doesn't seem like it so far, one of the redeeming features of Linux is truly how
efficient you can be with it. With that said, you can only be as efficient as you are familiar with
it of course. As you interact with OSs such as Ubuntu over time, essential commands like those
we've already covered will start to become muscle-memory.
One fantastic way to show just how efficient you can be with systems like this is using a set of
commands to quickly search for files across the entire system that our user has access to. No
need to consistently use cd and ls to find out what is where. Instead, we can use commands
such as find to automate things like this for us!
This is where Linux starts to become a bit more intimidating to approach -- but we'll break this
down and ease you into it.
The find command is fantastic in the sense that it can be used both very simply or rather complex depending upon what it is you want to
do exactly. However, let's stick to the fundamentals first.
Using
Take the snippet below; Find
we can see a list of directories available to us:
Using "ls" to list the contents of the current directory
tryhackme@linux1:~$ ls
Desktop Documents Pictures folder1
tryhackme@linux1:~$
1. Desktop
2. Documents
3. Pictures
4. folder1
Now, of course, directories can contain even more directories within themselves. It becomes a headache when we're having to look
through every single one just to try and look for specific files. We can use find to do just this for us!
Let's start simple and assume that we already know the name of the file we're looking for — but can't remember where it is exactly! In
this case, we're looking for "[Link]"
If we remember the filename, we can simply use find -name [Link] where the command will look through every folder in our
current directory for that specific file like
Using Grep
An Introduction to Shell Operators
Conclusions & Summaries
Nice work on getting to this stage! We covered quite a bit for your first interactions with Linux. However,
these are the most essential/functions you're going to be using whenever you interact with a Linux
machine.
I hope this room hasn't been too daunting for you to power-on through with. It's as I previously
mentioned, you're going to become familiar with these things very quickly because of how often you're
going to be using them.
To quickly recap, we've covered the following:
● Understanding why Linux is so commonplace today
● Interacting with your first-ever Linux machine!
● Ran some of the most fundamental commands
● Had an introduction to navigating around the filesystem & how we can use commands like find and
grep to make finding data even more efficient!
● Power up your commands by learning about some of the important shell operators.
THANK YOU!