Lesson 4.1: Bash Introduction
Bash (Bourne Again Shell) is the default command-line interface on most Linux systems, including Ubuntu. It's a powerful tool that lets you interact with your system through text commands.
Opening a Terminal
On Ubuntu 24.04, you have several ways to open a terminal:
Method 1: Keyboard Shortcut
Press Ctrl + Alt + T - this is the fastest way to open a terminal.
Method 2: Application Menu
- Click the "Show Applications" button (9 dots) in the dock
- Type "Terminal" in the search bar
- Click on the Terminal application
Method 3: Right-Click Menu
Right-click on your desktop and select "Open in Terminal" (if available).
Understanding the Prompt
When you open a terminal, you'll see something like this:
Let's break down what this means:
- valente: Your username
- @: Separator (at)
- ubuntu: Your hostname (computer name)
- : Separator
- ~: Your current directory (~ means home directory)
- $: Prompt character (means you're a regular user)
$ means regular user, # means root/superuser. If you see #, be extra careful with your commands!
Your First Commands
Let's start with some basic commands to get familiar with the terminal:
Check Who You Are
See Where You Are
List Files in Current Directory
See Current Date and Time
Command Structure
Linux commands follow a basic structure:
- command: The program you want to run
- options: Flags that modify how the command works (usually start with -)
- arguments: What the command operates on (like filenames)
Example: ls with options
Here: ls is the command, -l is an option (long format), and /home is an argument (directory to list).
Navigation Commands
Moving around the filesystem is fundamental to using the command line:
Change Directory (cd)
Special Directory References
- . - Current directory
- .. - Parent directory
- ~ - Home directory
- / - Root directory
- - - Previous directory
File Operations
Basic file management commands:
Create Files
View Files
Copy and Move Files
Remove Files
rm command is permanent! There's no recycle bin or undo. Always double-check your commands, especially with rm -rf.
Bash Features That Make Life Easier
Tab Completion
Type part of a command or filename and press Tab to complete it:
Command History
Use arrow keys to navigate previous commands:
- ↑ - Previous command
- ↓ - Next command
- Ctrl + R - Search command history
- history - Show all previous commands
Clear Screen
Getting Help
Linux has built-in help systems:
man Pages
--help Flag
what is and apropos
Command Line Shortcuts
These shortcuts will save you time:
- Ctrl + C: Cancel current command
- Ctrl + D: Exit terminal or logout
- Ctrl + A: Move to beginning of line
- Ctrl + E: Move to end of line
- Ctrl + U: Delete from cursor to beginning
- Ctrl + K: Delete from cursor to end
- Ctrl + L: Clear screen
- Ctrl + Z: Suspend current command
Working with Multiple Commands
Command Chaining
Background Processes
Environment Variables
Environment variables store system information:
Customizing Your Shell
You can customize Bash using configuration files:
.bashrc File
The ~/.bashrc file runs every time you open a terminal. You can add:
- Aliases (command shortcuts)
- Custom prompt settings
- Environment variables
- Functions
Example .bashrc additions
Practice Exercises
Try these exercises to practice what you've learned:
Exercise 1: Navigation Practice
- Navigate to your Documents directory
- Create a new directory called "practice"
- Go into that directory
- Create a file called "test.txt"
- Go back to your home directory
- Remove the practice directory and its contents
Click for solution
Exercise 2: File Management
- Create three files: file1.txt, file2.txt, file3.txt
- Copy file1.txt to backup.txt
- Rename file2.txt to renamed.txt
- Move file3.txt to a new directory called "moved"
- List all files to verify your work
Click for solution
What's Next?
Now that you understand Bash basics, let's explore terminal applications that will make you more productive!
Key Takeaways
- Bash is the default shell on Ubuntu and most Linux systems
- Commands follow the structure: command [options] [arguments]
- Tab completion saves time and prevents typos
- Command history lets you reuse previous commands
- Use
manand--helpto learn about commands - Always be careful with
rm- there's no undo!
Linux 101