Skip to content

How to Linux in Just a Few Minutes

Posted in Student Blog Series

A Linux tutorial to get you started 

The fact of the matter is, Linux – for anyone close to computers and/or data in any way – is most likely going to be an integral part of any work that is done. I know personally that the Computer Science department at Hamilton College throws students right into the Linux furnace their second class into the major or minor. Why? Why do so many servers and systems rely on something Linux-like? What even is Linux? How do you use it? If you are asking all these questions and more, you are reading the right post. After this quick read, you should know what Linux is, why people like it, and how to navigate it like a pro.

Linux: What Is It and Why Should You Care?

Linux (LIN-uuks) is an open-source operating system kernel first released on September 17th, 1991 by Linus Torvalds [1].  The name Linux (named after Linus Torvalds’ himself) stands for Lovable Intellect Not Using XP (XP referring to Windows XP systems) [2]. There are a myriad of variations of Linux that are circulating throughout the world as we speak: Ubuntu, Lubuntu, Mint Cinnamon, SteamOS, and too many more to mention here. Each version has its own set of perks and is designed for specific tasks; Ubuntu is more like a regular desktop such as Windows or Mac which you may be familiar with, while SteamOS is specifically built to run games off the similarly named game-streaming distribution service Steam [3]. Because Linux is open-source, it allows for all of these variants to be made for individual tasks and has become extremely popular as a good budget option for PC connoisseurs and a great starting-point for development of massive projects like Google, Facebook, Amazon, etc. [4]. Also, as you will see in the Manipulating Information section, Linux for data manipulation and storage is extremely simple, which is another one of the many reasons why people like to use Linux for so many tasks and projects.

Conquering the Linux Terminal

For the rest of this post, I am going to assume you have access to some Linux distribution with access to the command-line terminal. For a Mac computer, this is extremely simple because every Mac’s terminal is based on Darwin, which is a Linux distribution itself! For Windows, this is a little more complicated because – as the name suggests – Linux is not built with a Windows computer in mind. If you do not have access to a Linux distribution and are on Windows but really want to follow along, I highly recommend going to GeekforGeeks for their tutorial for how to boot Linux onto your Windows computer. 

How to Print “Hello, World!”?

Alright, I understand Linux is not a programming language, but this is a good way to make sure that your Linux system is up and running correctly (if you ever feel like your Linux system may be broken in any way, this is a good test to run to see if it will even respond to basic input).

A Linux command-line terminal that is blank except for the current directory in the top left corner of the screen.
An empty Linux Terminal

Welcome to Linux! This is the most intimidating part of the entire process: staring at a blank screen and not knowing what to do. So, let’s fill the screen with something! We will use the echo command to tell the system to echo or print something to the screen. By inputting the command `echo “Hello, World!”`, you should get the same response I did from the system.

jgfrazie@decker:~$ echo "Hello, World!"
Hello, World!
jgfrazie@decker:~$
An example of the use of the echo command to print “Hello, World!” to the screen.

If you got something similar, then you can be confident that your Linux system is ready for the rest of this post!

Navigation

While it is nice to know that our system is working, it would be even better to know where the system even put us. There are two different ways we can extrapolate this information. The first way is by looking at our current directory address on the command line. That tilde in blue right before the dollar sign is actually our current directory. The tilde stands for the Home or Root directory of the system. If you are curious about what your literal home directory is, you can enter the pwd (print working directory) command to get specifics.

Alt Text: The same Linux terminal from before with as blue tilde preceding a dollar sign. On the first line, the command `pwd` is entered and the next line reads "/home/jgfrazie". The last line reads "jgfrazie@decker:~$ " just like the first line.
An example of the pwd command being used.

Since we are currently in a directory/folder, that means there could be other directories or files in the directory with us. To see if there is anything, type the ls command to “list” items in your current directory.

The command "ls" is typed into the command line, but nothing appears.
An example of the ls command being used

If you typed in the command and nothing appeared (like above) that is completely okay! That just means your current directory is empty. (Also, do not worry that the current directory now reads “~/linux_tutorial”. I did this to show what an empty directory looks like). However, more than likely, you had something similar to this happen.

The same command "ls" is put in but now a new line appears that has several words on it separated by spaces. The words include "important_secret_information" in blue, "my_cs_project.cpp", "ruby_script.rb", "scrape_fb.py", and "work" in blue.
An example of the ls command being used and it yielding some files and directories on screen.

These are all of the files and other directories that are in the same directory with you. Some Linux distributions will color-code items that appear for you, but all items will follow a similar naming convention. Any plain words such as “work” are directories that store items that you can access. Actual files will have their extensions listed after their file names (i.e. my_cs_project.cpp is a C++ program file named “my_cs_project”). If we wanted to look inside of the “important_secret_information” directory, we would need to navigate to it. We can accomplish this by using the cd (change directory) command followed by the directory we want to go into. Thus, we would want to enter cd important_secret_information to navigate there. Pro Tip: if you are typing a file or directory with a long name, you can press TAB to autocomplete your selection if the Linux system can guess what item you want. In my case, I only had to type “i” after the cd command because “important_secret_information” is the only item in this directory that starts with an “i”.

The command "ls" is entered on the first line and the same items from before appear on a second line. On the next line, the command "cd important_secret_information/" is entered. The line after now reads the current directory as "~/linux_tutorial/important_secret_information". the command "ls" is entered again and this time one file named "information.txt" appears.
An example of the cd command being used.

We have successfully navigated to another directory (notice that the current working directory has now changed to “~/linux_tutorial/important_secret_information”). By using the ls command, we can see there is one file in this directory called “information.txt”. If we do not want to go snooping around this directory, we can exit it by entering cd .. which tells the Linux system to move out of the current directory and back to the previous directory we were in.

Interact with Items

Let’s say we wanted to see what “information.txt” is exactly. If we want to read the contents of it, there are plenty of options for doing so. For the sake of simplicity, we will explore one of the methods for doing so. The command cat (concatenate) with any file will print to the screen the literal information of that text file by concatenating its information to the screen.

jgfrazie@decker:~/linux_tutorial/important_secret_information$ ls
information.txt
jgfrazie@decker:~/linux_tutorial/important_secret_information$ cat information.txt
You ROCK at using Linux!
jgfrazie@decker:~/linux_tutorial/important_secret_information$
An example of the cat command being used.

If you want to make your own text file, you can use the touch command followed by the name of the file to make (make sure to include the file extension in the name)!

jgfrazie@decker:~/linux_tutorial/important_secret_information$ ls
information.txt
jgfrazie@decker:~/linux_tutorial/important_secret_information$ touch my_logs.txt
jgfrazie@decker:~/linux_tutorial/important_secret_information$ ls
information.txt my_logs.txt
jgfrazie@decker:~/linux_tutorial/important_secret_information$
An example of the touch command being used.

If you want to edit the file itself, there are many ways to do so. So, again, for the sake of simplicity, I am only going to mention one. The basic editor for Linux is called Nano and you can use it by typing the nano alias followed by what file you want to edit (i.e. nano my_logs.txt). Nano is a whole different system than Linux, so I am not going to cover it here, but if you need to change anything in a file on the fly, Nano is not a bad choice. Now, if you want to make a new directory, you can do so with the mkdir (make directory) command followed by the name of the directory.

jgfrazie@decker:~/linux_tutorial/important_secret_information$ ls
information.txt my_logs.txt
jgfrazie@decker:~/linux_tutorial/important_secret_information$ mkdir newDir
jgfrazie@decker:~/linux_tutorial/important_secret_information$ ls
information.txt my_logs.txt newDir
jgfrazie@decker:~/linux_tutorial/important_secret_information$
An example of the mkdir command being used.

Now, if you want to remove your new files and directories, we have to use a new command: rm (remove). Just like all the other commands we have covered so far, you give the name of the file or directory you want to delete and it does the work for you.

jgfrazie@decker:~/linux_tutorial/important_secret_information$ ls
information.txt my_logs.txt newDir
jgfrazie@decker:~/linux_tutorial/important_secret_information$ rm my_logs.txt
jgfrazie@decker:~/linux_tutorial/important_secret_information$ ls
information.txt newDir
jgfrazie@decker:~/linux_tutorial/important_secret_information$
An example of of the rm command being used.

Now, if you wanted to delete a directory with this command, you probably will not be able to. That is because the remove command only removes one file at a time. If you want to delete multiple files at once, then you are going to have to use a command option. An option for a command is denoted by a dash then usually a single letter (i.e. -f). Every option and every command is different, so to see the options for a specific command, you can use the –-help option to see the description of a command and a list of all its options.

jgfrazie@decker:~/linux_tutorial/important_secret_information$ rm --help

What follows is a paragraph which takes up the screen with example options to use with the rm command. One of the options shown is the -r or --recursive option.
An example of the –help option being used with the rm command.

Now we can see there is an option called -r that will recursively delete a directory and all its contents (assuming we are not currently inside that directory). So, if we wanted to delete the important_secret_files directory, we could do so by executing the following commands:

jgfrazie@decker:~/linux_tutorial/important_secret_information$ cd ..
jgfrazie@decker:~/linux_tutorial$ ls
important_secret_information my_cs_project.cpp ruby_script.rb scrape_fb.py work
jgfrazie@decker:~/linux_tutorial$ rm -r important_information/
jgfrazie@decker:~/linux_tutorial$ ls
my_cs_project.cpp ruby_script.rb scrape_fb.py work
jgfrazie@decker:~/linux_tutorial$
An example of the rm command being used with the -r option to remove a directory.

We were able to successfully delete the directory full of information! Of course, be very careful with this command – especially if you use the -f (force) option – as it can delete more than you expect to if you are not careful, and when using the remove command, there is no way to recover removed files.

Manipulating Information (The Basics)

Now that we have ways of accessing information and moving around, let’s do something interesting with what we know by piping information around. Piping refers to passing information (usually text) from one output of a command to another command’s input. To showcase how this works, we will work with one more function that is extremely useful to know. The command grep will filter text and only provide text that satisfies given conditions. It is an extremely convoluted and expressive command, so we are only going to use it in a very simple case.

jgfrazie@decker:~/linux_tutorial$ ls
my_cs_project.cpp ruby_script.rb scrape_fb.py work
jgfrazie@decker:~/linux_tutorial$ ls | grep "m"
my_cs_project.cpp
jgfrazie@decker:~/linux_tutorial$
An example of the grep command being used with piping.

This example does a lot of things at once, so let’s break it down. As we know, the ls command shows all items in the current working directory. We can pipe the information that ls provides to another command in series by using the “|” character. We then use the grep command to filter the information to provide only information that contains the character m. Which is why we only see my_cs_project.cpp on the second command call above. Another example of piping information can be used to find specific sentences in text. Using the cat command then piping the information from a file to grep can filter the text from a text file for you.

A new text called lorem.txt is read using the cat command and 4 sentences of text are displayed to screen. Then the same file is read using the cat command but in this way:

jgfrazie@decker:~/linux_tutorial$ cat lorem.txt | grep "veniam"

And this command yields a single sentence that contains the word "veniam"
Another example of grep being used with piping to filter a text file.

One other very useful thing piping can do is store information into files for you. So, if you wanted to store the filtered information above into a text file, you can do so using the “>” character which tells Linux to pipe information into another file.

The same image from before is displayed with one difference in that the command to filter the text file now reads

jgfrazie@decker:~/linux_tutorial$ cat lorem.txt | grep "veniam > new_text.txt

This results in a new text file containing a sentence with the word "veniam" in it.
The same example from above that now pipes the filtered string into another text file to store.

An interesting point to note here is that I did not have to create a new text file for this; by saying I wanted to pipe the output from the grep call into a text file, Linux was able to determine that it needed to create a new text file itself!

Now there is one more thing piping can do that can really speed up your daily work. As you probably have guessed, since Linux can pipe information as output, it can also pipe information as input. This makes testing scripts that require user input extremely easy as seen in the example below.

jgfrazie@decker:~/linux_tutorial$ ls
calculator.py input.txt
jgfrazie@decker:~/linux_tutorial$ python3 calculator.py
3 + 6
9
jgfrazie@decker:~/linux_tutorial$ cat input.txt
3 + 6
jgfrazie@decker:~/linux_tutorial$ python3 calculator.txt < input.txt
9
jgfrazie@decker:~/linux_tutorial$
An example of using input piping to provide user input to a python program.

In this example, I have a python script that can perform a basic calculation by calling the alias python3 and choosing the python script to run. It takes in the line “3 + 6” as input and correctly calculates the sum to be 9. Then I look to see that my input.txt file contains the exact same information as what I gave the script before, so when I pipe the text file’s contents into the script, it is able to read the text file as human input and calculate the sum once again.

Additional Resources

As mentioned before, the aim of this blog post is to help you begin your journey with using Linux and to help you navigate the basics of the operating system. Just like a Windows or Mac operating system, there is too much to cover in such a short post, but what was covered should be enough for managing your files and being able to find your way around the system. However, the real magic of Linux comes from understanding and learning specific concepts (like piping) which help you navigate quickly around the system and manage your files without thinking about it. To learn more about Linux, I recommend looking into the following resources.

  • Top 50+ Linux Commands with Example (puttygen.com): A phenomenal list of Linux commands for you to learn and use to become a proficient Linux command-line user. I highly recommend going through the entire list and trying to memorize a few a day if you are serious about becoming a Linux pro.
  • 60 Linux Commands you NEED to know (in 10 minutes) – YouTube: If reading over 50 commands is not exactly your style, this video by the YouTube channel NetworkChuck is a great resource for visually learning instead. It is fast-paced and covers a lot in just 10 minutes.
  • OverTheWire: Bandit: If you like to learn by a hands-on approach, I recommend the Bandit online WarGame by OverTheWire. It has you learn Linux commands by applying your knowledge to progress to the next level. The great part about this resource is that if you complete this WarGame, then there are several intermediate and advanced level WarGames you can play to learn the specifics of Linux as well.
  • UNIX / Linux Tutorial for Beginners: Learn Online in 7 days (guru99.com): Finally, if you really want to go from Zero-to-Hero as quickly as possible, this free online course through Linux will do just that. It goes far more in depth than any of the resources above and will carry you through the finish line and beyond.

If this post helped to get your foot in the door with using Linux, then using the above resources will have you well on your way to navigating and manipulating Linux distributions unlike before. If you want additional resources or clarification on anything covered in this post, you can contact me at jgfrazie@hamilton.edu. Start filling that Linux terminal with commands!

Sources

[1] Twenty Years of Linux according to Linus Torvalds | ZDNET

[2] LINUX Full Form – GeeksforGeeks

[3] https://www.linux.com/news/best-linux-distros-2016/


[4] Who Uses Linux? (careerkarma.com)

James is smiling in front of a white background. His hair is pulled back in a ponytail and he is wearing a blue shirt.
+ posts