Linux Basics


CybHer Dojo.

This module will teach you the basics of using Linux, specifically on the command line. The command line (also called the terminal or shell) is a way to control your computer by typing instructions instead of clicking on buttons. You type a command, press Enter, and the computer follows your instructions — like opening a file, moving something, or searching for a word. It might look plain, but it's a powerful tool!

If you ever forget a command you've learned, check out the Cheat Sheet below!



Resources

  • cd - change directory (move into a folder)
    • cd [folder_path]
    • Use cd .. to go up one folder level
  • ls - list files and folders in the current directory
  • pwd - print working directory (shows the full path to your current folder)
  • touch - create a new empty file
    • touch [filename]
  • rm - remove (delete) a file
    • rm [filename]
    • Be careful — you can never get these files back!
  • mv - move or rename a file
    • mv [source] [destination]
    • Use to rename: mv oldname.txt newname.txt
  • cp - copy a file
    • cp [source] [destination]
    • Keeps the original file and makes a copy!
  • cat - show the contents of a file
    • cat [filename]
  • nano - open a simple text editor to write or edit a file
    • nano [filename]
    • Will create a new file or open an existing one, depending on the filename you use
    • Use Ctrl + X -> y -> Enter to save and close
  • grep - search for text inside a file
    • grep [word_to_find] [filename]
    • Use * to search all files in a folder: grep word *

Challenges

Challenge Description

In this challenge, you will learn to run some Linux commands! When using the terminal, the main way to interact with your computer is to type commands. Instead of clicking buttons, these commands tell your computer what you want to do.

We will focus on two commands for this challenge:

  • ls - the "list" command allows you to list or view the files in your current folder.
    • usage: type ls and press Enter
    • This will show all files in your current directory
  • cd - the "change directory" command allows you to move to a different folder.
    • usage: type cd new_folder and press Enter
    • replace "new_folder" with the name of the folder/directory you want to navigate to
    • This will move you to the new folder. You should see your terminal prompt change to show the folder you're currently in.

This challenge will require you to run the challenge file - but you don't know the file name this time! You will need to navigate to the /challenge directory, find the file, and run it.

Challenge Steps

  1. Open a terminal in the Desktop
  2. Navigate to the /challenge directory (Hint: Type cd /challenge and press Enter)
  3. Use the ls command to find the challenge file (Hint: it is NOT the DESCRIPTION.md file)
  4. To run this challenge, type the filename and press Enter!
  5. Submit your flag!

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

The Linux Filesystem

In Linux, the filesystem is structured like a tree, starting from the root directory (denoted by the character '/'), which is the base of everything. A 'directory' is just a folder. Think of / as the foundation that holds every file and folder on the system. Here are a few essential directories to get familiar with:

  • / (Root): The top level of the filesystem. All other files and folders are organized underneath it.
  • /home Directory: This is where personal files and folders for each user are stored. Each user has their own folder inside /home, such as /home/username, which is like a private workspace.
  • /tmp Directory: Stores temporary files that are deleted when the machine is restarted. Don't store important things here!

As an example, if you're a Linux user with the account name 'wkiffin', your home directory would be: /home/wkiffin

  • / at the beginning is the root of the directory tree, where all paths start.
  • home is the folder inside '/' that all Linux users home directories are stored.
  • wkiffin is the directory where our specific user files are stored.

Understanding this structure helps you know where to find your files, system settings, and applications on Linux.

This challenge will continue using the cd and ls commands as you traverse the Linux filesystem.

Challenge Steps

  1. Start the challenge and open a terminal
  2. Run /challenge/solve (This means you're running a file named 'solve' found within the 'challenge' directory that is held within the root '/' directory!)
  3. Follow the instructions given in /challenge/solve (It may be a bit tricky! Read all instructions carefully!)
  4. Submit the flag once you find it!

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

In this challenge you will be learning how to create and delete files on the command line.

Challenge Steps

  1. Start the challenge and open a terminal
  2. Run /challenge/solve
  3. Follow the instructions
  4. Submit the flag once you find it!

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

In this challenge you will be learning how to move, rename, and copy files.

Challenge Steps

  1. Start the challenge and open a terminal
  2. Run /challenge/solve
  3. Follow the instructions
  4. Submit the flag once you find it!

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

In this challenge you will be learning how to display the contents of a file within the linux terminal.

Challenge Steps

  1. Start the challenge and open a terminal
  2. Run /challenge/solve
  3. Follow the instructions
  4. Submit the flag once you find it!

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

Nano Text Editor

In Linux, while you're using the command line, you'll probably need a way to edit files. On Windows we can use an app like notepad or Microsoft Word to edit files. Unfortunately, we don't have access to tools like this in the terminal because they are graphical tools. However, the Linux command line offers a wide range of text editors that we can use - one option is called nano.

You can use Nano by typing the command nano {filename} in the terminal. If that filename already exists, it will open the existing file. Otherwise, it will create a new file with whatever filename you used. For example: nano myfile.txt will create a new text file named myfile.txt.

You can then begin writing text to the screen as if you were using notepad on Windows. To move around in nano you will have to use the arrow keys. In nano, you can't use your mouse to click buttons like 'file' and 'save as' - you have to use Keyboard shortcuts. You're probably already familiar with certain keybaord shortcuts such as CTRL+C to copy, and CTRL+V to paste.

In nano, they provide you with all of the keyboard shortcuts you will need to use at the bottom of your screen. It shows you the shortcut you need to enter with the syntax of up carrot '^' and then a letter following it. The up carrot ('^') means you have to hold the control key and then hit the letter that follows to execute the proper function.

To save and close a file, you will use the 'Exit' shortcut to save your file - CTRL+X. You will then be prompted if you want to "Save modified buffer", you can hit the 'y' key for yes to save your changes. Next it will ask you to confirm your filename at the bottom of the screen. It will be the filename you used when you ran nano, in our example "myfile.txt". To confirm your filename, press Enter. Or, if you'd like to change your filename, use the backspace button to delete it and then create a new name.

To put that all together for you, when you're done editing your file and are ready to save and close it: CTRL+X -> y -> Enter.

Challenge Steps

  1. Start the challenge and open a terminal
  2. Use nano to create a file named my_nano_file.txt
  3. Type the phrase "Nano is fun!" in your file
  4. Save and close your file: CTRL+X -> y -> Enter
  5. Run /challenge/solve to verify your solution
  6. Submit your flag

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

In the previous challenge you saw how to create a file with nano. In this challenge you will see how to edit an existing file. Spoiler Alert: It's easy!

Challenge Steps

  1. Start the challenge and open a terminal
  2. Open the file you created in the previous challenge by typing nano [your_file]
  3. Edit the current line to say anything you want in the file, just change it
  4. Save and close, then run /challenge/solve to verify your solution
  5. Submit the flag!

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

In this challenge you will learn how to find files if you don't know where they are. When you get into the Linux terminal run /challenge/solve to get your instructions.

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

This challenge will teach you to find information in a file - you will learn to search for a string. (A string is just a sequence of characters - like a word or a phrase!) More detailed instructions will be given in /challenge/solve.

Challenge Steps

  1. Start the challenge and open a terminal
  2. Run /challenge/solve
  3. Follow the instructions given
  4. Submit the flag!

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

In this challenge you will learn how to create and remove directories, as well as view hidden files! You can start the VSCode workspace, open a terminal, and run /challenge/solve to get your instructions.

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

In this challenge you will learn how to find out system information on the command line, as well as how to use flags with commands! You will also find out how to learn a new command you know nothing about! You can start the VSCode workspace, open a terminal, and run /challenge/solve to get your instructions.

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

30-Day Scoreboard:

This scoreboard reflects solves for challenges in this module after the module launched in this dojo.

Rank Hacker Badges Score