Ubuntek Banner

Learning Basic Commands

Operating System Beginner 15 minutes

Summary

This tutorial introduces you to essential Linux command line commands that every Ubuntu user should know. You'll learn how to navigate directories, create files and folders, and perform basic file operations using the terminal.

These commands form the foundation of working with Linux systems and will help you become comfortable with the command line interface.

Key Vocabulary

Terminal: A text-based interface for interacting with the operating system using commands.
Directory: A folder that contains files and other directories.
Current Directory: The directory you are currently working in.
Path: The location of a file or directory in the file system.
Permissions: Settings that control who can read, write, or execute files and directories.

Prerequisites

  • Ubuntu Linux system
  • Terminal application open
  • Basic understanding of computer files and folders

Step-by-Step Instructions

Step 1

Check Current Directory

Display the current working directory path.

pwd
Why this works: Shows your current location in the file system.
Step 2

Create a Practice Directory

Create a new directory called 'practice' to work in.

mkdir practice
Why this works: Creates a new folder named 'practice' in the current directory.
Step 3

List Directory Contents

Display the contents of the current directory.

ls
Why this works: Lists all files and directories in the current location.
Step 4

Change to Practice Directory

Navigate into the practice directory.

cd practice
Why this works: Changes your current directory to the 'practice' folder.
Step 5

Create a Text File

Create an empty text file named 'myfile.txt'.

touch myfile.txt
Why this works: Creates a new empty file with the specified name.
Step 6

List Files in Practice Directory

Check the contents of the practice directory.

ls
Why this works: Shows the files that are now in the practice directory.
Step 7

Edit File with Nano

Open the text file in the Nano text editor.

nano myfile.txt
Why this works: Opens the file in Nano, a simple command-line text editor.
Step 8

Edit the File

Type something, then press Ctrl+O (save), Ctrl+X (exit)

Why this works: Nano uses keyboard shortcuts for saving and exiting.
Step 9

Display File Contents

View the contents of the text file.

cat myfile.txt
Why this works: Displays the text content of the file on the screen.
Step 10

List Files with Details

Show detailed information about files including permissions and sizes.

ls -la
Why this works: The -l flag shows detailed info, -a shows hidden files.
Step 11

Create a Subfolder

Create a subdirectory within the practice folder.

mkdir subfolder
Why this works: Creates a new directory inside the current directory.
Step 12

Navigate to Subfolder

Change to the subfolder directory.

cd subfolder
Why this works: Moves into the newly created subfolder.
Step 13

Create File in Subfolder

Create another text file in the subfolder.

touch test.txt
Why this works: Creates a new file in the current subfolder.
Step 14

Go Back to Parent Directory

Navigate back to the practice directory.

cd ..
Why this works: Moves up one directory level to the parent folder.
Step 15

List Subfolder Contents

Check what files are in the subfolder.

ls subfolder
Why this works: Lists the contents of the subfolder without changing directories.
Step 16

Return to Home Directory

Go back to your home directory.

cd ..
Why this works: Moves up another level to return to the original starting directory.
Step 17

Remove Practice Directory

Delete the entire practice directory and its contents.

rm -r practice
Why this works: Recursively removes the directory and all files within it.
⚠️ Warning: This command permanently deletes files. Use with caution!
Step 18

Verify Cleanup

Confirm the practice directory has been removed.

ls
Why this works: Checks that the practice directory is no longer present.

Common Issues & Solutions

Problem: Command not found error
Solution: Ensure you're typing the command correctly. Linux commands are case-sensitive.
Problem: Permission denied
Solution: Some commands require administrator privileges. Use 'sudo' before the command if needed.
Problem: File or directory not found
Solution: Check your current directory with 'pwd' and ensure the file/directory exists with 'ls'.
Problem: Nano editor won't start
Solution: Make sure Nano is installed with 'sudo apt install nano'.

Conclusion

Congratulations! You've learned the essential Linux commands for navigating and managing files. These commands are the building blocks for working with Linux systems.

Key commands you learned:

  • pwd - Show current directory
  • ls - List directory contents
  • cd - Change directory
  • mkdir - Create directory
  • touch - Create empty file
  • nano - Edit text files
  • cat - Display file contents
  • rm -r - Remove directories and contents

Practice these commands regularly to become comfortable with the Linux command line. Remember to use man command to get help for any command!