Introduction to Linux

LinuxLinuxBeginner
Practice Now

Introduction

Welcome to your first Linux lab! This introduction is designed for complete beginners who have never used Linux before. Linux is a free, open-source operating system that powers everything from smartphones to supercomputers. Unlike Windows or macOS, Linux allows users to interact directly with the system through a command-line interface, giving you more control and flexibility.

In this lab, you'll learn the basics of using Linux through its command-line interface, called the terminal. Don't worry if this sounds intimidating – we'll guide you through each step, explaining what you're doing and why it's important.

Understanding and Opening the Terminal

Before we start, let's understand what a terminal is:

The terminal, also known as the command line or shell, is a text-based interface to interact with your computer. Instead of clicking on icons or menus, you type commands to perform actions like creating files, navigating directories, or running programs.

Terminal

Now, let's open the terminal:

  1. Look for an icon on your desktop labeled "Terminal" or "XFCE Terminal". It might look like a small black screen.
  2. Double-click this icon to open the terminal.

Once open, you'll see a window with text. This is your gateway to interacting with Linux!

The last line in this window is called the "prompt". It typically ends with a $ symbol. This is where you'll type your commands.

Just like your computer has folders and files, Linux organizes information in a similar way. In Linux, we call folders "directories". Let's learn how to move around these directories using the terminal.

  1. First, let's find out where we are. Type the following command and press Enter:
pwd

pwd stands for "print working directory". It tells you which directory you're currently in.

alt text

You should see something like /home/labex/project. This is your current location in the file system.

Tips: No more operation screenshots will be added later to avoid duplication. Just follow the instructions to complete the lab.

  1. Now, let's move to your home directory. Type:
cd ~

cd means "change directory", and ~ is a shortcut that always represents your home directory.

  1. Let's check our location again:
pwd

You should now see /home/labex. This is your home directory!

  1. To go back to the project directory, type:
cd project
  1. Now, let's see what's in this directory. Type:
ls

ls stands for "list". It shows you all the files and directories in your current location.

Remember, in Linux:

  • / is the root of the file system (like C: in Windows)
  • Directories are separated by / (not \ like in Windows)
  • File and directory names are case-sensitive (unlike Windows)

Creating Files and Directories

Now that we can move around, let's learn how to create new files and directories.

Before proceeding, ensure you are in the /home/labex/project directory. If not, utilize the cd command to navigate to the correct directory.

  1. First, let's create a new directory called linux_practice:
mkdir linux_practice

mkdir stands for "make directory". This command creates a new folder.

  1. Move into the new directory:
cd linux_practice
  1. Now, let's create an empty file called hello.txt:
touch hello.txt

touch is a command that creates an empty file if it doesn't exist, or updates the timestamp if it does.

  1. Let's confirm our file was created:
ls

You should see hello.txt listed.

  1. Now, let's add some text to our file:
echo "Hello, Linux" > hello.txt

echo is like "print" in other languages. The > symbol tells Linux to put the output into a file instead of displaying it on the screen.

  1. To view the contents of our file:
cat hello.txt

cat is short for "concatenate", but it's often used to display file contents.

These commands demonstrate how Linux uses small, specialized tools that can be combined to perform complex tasks.

Using Wildcards

Wildcards are special characters that help you work with multiple files at once. They're like search patterns for file names. Let's practice using them.

Before proceeding, ensure you are in the /home/labex/project/linux_practice directory. If not, utilize the cd command to navigate to the correct directory.

  1. First, let's create a few more files:
touch file1.txt file2.txt file3.txt

This creates three new empty files in one command!

  1. Now, let's list all files ending with .txt:
ls *.txt

The * is a wildcard that matches any number of characters. So *.txt means "any file name ending with .txt".

  1. We can also create numbered files using a range:
touch note_{1..5}.txt

This creates note_1.txt, note_2.txt, note_3.txt, note_4.txt, and note_5.txt all at once!

  1. Let's list files starting with "note":
ls note*

This should show all five note files we just created.

Wildcards are powerful tools for working with groups of files. The most common wildcards are:

  • *: Matches any number of characters
  • ?: Matches any single character
  • [abc]: Matches any one character listed in the brackets

Basic File Operations

Now that we have some files to work with, let's learn how to copy, move, and delete them.

Before proceeding, ensure you are in the /home/labex/project/linux_practice directory. If not, utilize the cd command to navigate to the correct directory.

  1. Let's copy hello.txt to a new file called hello_copy.txt:
cp hello.txt hello_copy.txt

cp stands for "copy". The first argument is the source file, the second is the destination.

  1. Now, let's move hello_copy.txt to the parent directory:
mv hello_copy.txt ..

mv stands for "move". The .. represents the parent directory (one level up).

  1. Let's remove file1.txt:
rm file1.txt

rm stands for "remove". Be careful with this command – in Linux, deleted files don't go to a Recycle Bin!

  1. List the contents of the current directory to see the changes:
ls
  1. Now, list the contents of the parent directory to see the moved file:
ls ..

These commands – cp, mv, and rm – are some of the most frequently used in day-to-day Linux operations.

Using Command Line Shortcuts

Linux provides several helpful shortcuts to make your command line experience more efficient. Let's try some of them:

  1. Use the up arrow key (↑) to recall the last command you typed. Try pressing it now – you should see your last command appear!

  2. Use Tab completion:
    Start typing hel and then press the Tab key. It should auto-complete to hello.txt.
    This feature saves a lot of typing and helps prevent spelling mistakes.

  3. Use Ctrl+C to interrupt a running command:
    Type the following command and press Enter:

    tail -f /dev/null

    This command will wait for input indefinitely. Now press Ctrl+C to stop it. This is useful when a command is taking too long or you want to stop a continuous output.

  4. Use Ctrl+L to clear the screen:
    Your terminal might be getting cluttered. Press Ctrl+L to clear it and give yourself a fresh view.

These shortcuts will make your Linux experience much smoother as you become more proficient.

Getting Help

One of the best things about Linux is its extensive built-in help system. Let's learn how to use it:

  1. To get a quick summary of a command and its options, use the --help option. Try it with ls:
ls --help

This shows a brief description of ls and its most common options.

  1. For more detailed information, use the man command (short for "manual"):
man ls

This opens the full manual page for ls. Use the arrow keys to scroll, and press 'q' to quit.

  1. Let's try getting help for another command, like cp:
man cp

The man pages are comprehensive guides for almost every command in Linux. Whenever you're unsure about how to use a command or what options are available, the man pages are your best resource.

Summary

Congratulations! You've completed your first introduction to Linux. Let's recap what you've learned:

  1. You've used the terminal, the powerful text-based interface to interact with Linux.
  2. You've navigated the file system using commands like cd, pwd, and ls.
  3. You've created files and directories with touch and mkdir.
  4. You've used wildcards to work with multiple files at once.
  5. You've performed basic file operations like copying, moving, and deleting.
  6. You've learned some helpful command-line shortcuts to improve your efficiency.
  7. You've accessed Linux's built-in help system using --help and man.

These skills form the foundation for working with Linux systems. As you continue your journey, you'll build upon these basics to become proficient in Linux administration and usage.

Remember, becoming comfortable with Linux takes practice. Don't be afraid to experiment and explore further in your Linux environment. If you make a mistake, it's a learning opportunity! Keep exploring, and you'll soon find yourself navigating Linux with confidence.

Other Linux Tutorials you may like