Bash Basics Tutorial: Foundational Skills for the Command Line
- Samul Black
- 4 days ago
- 8 min read
Updated: 3 days ago
Imagine being able to control your entire operating system with just your keyboard. No mouse, no menus—just you, your terminal, and absolute control over your files, applications, and system processes. That’s the power of Bash, and it’s why it’s a skill worth learning.
In this guide, we’re going to break down the basics of Bash—the Bourne Again Shell—so you can start using the command line like a pro. Whether you’re new to programming, exploring Linux for the first time, or looking to automate tasks on your system, understanding Bash is an essential stepping stone.

What is Bash - The Bourne Again Shell?
Before diving into commands and scripts, it’s important to understand what Bash actually is. Bash stands for Bourne Again Shell, and it’s a Unix shell and command language. It’s the default shell on many Unix-like operating systems, including most distributions of Linux and macOS.
At its core, Bash allows you to interact with your operating system through text-based commands. Instead of clicking buttons or opening folders graphically, you type commands to do everything from navigating directories to managing files and running complex scripts.
Login Shell vs Interactive Shell: Overview
There are two key dimensions to consider:
Login vs Non-login
Interactive vs Non-interactive
Let’s focus on the first two here:
What is a Login Shell?
A login shell is started when a user logs into a system. It can be through:
A text-based console (e.g., when you log into a server via SSH)
A terminal emulator that starts a login session (e.g., bash --login)
A graphical environment (on some systems) where a login shell is launched by your session manager
Characteristics:
Reads and executes login-related startup files
Used when initiating a full user session
Bash configuration files used:
In a login shell, Bash reads one or more of the following files, in this order:
/etc/profile – system-wide settings
~/.bash_profile – user-specific settings
If ~/.bash_profile doesn't exist, then ~/.bash_login
If neither exists, then ~/.profile
These files are typically used to set environment variables, define paths, and run login-time commands.
What is an Interactive Shell?
An interactive shell is one that is attached to a terminal session where the user can type and execute commands in real time.
This is what you usually get when you open a terminal window or emulator like GNOME Terminal, iTerm2, or Windows Terminal (with Bash installed).
Characteristics:
Accepts input from the keyboard
Displays a prompt and waits for user commands
Provides command history, autocompletion, etc.
Bash configuration files used:
An interactive, non-login shell reads:
~/.bashrc – This is the most common place to set shell preferences (aliases, PS1 prompt customization, shell options, etc.)
Visualizing the Difference
Here's a simple way to think about it:
Shell Type | Started By | Reads Config File(s) | Has Prompt? |
Login Shell | SSH, console login, bash --login | /etc/profile, ~/.bash_profile | Yes |
Interactive Shell | Terminal window, bash manually | ~/.bashrc | Yes |
A shell can be:
Login + Interactive (e.g., when logging in via SSH)
Non-login + Interactive (e.g., opening a new terminal window in your GUI)
Login + Non-interactive (e.g., executing a command via SSH like ssh user@host command)
Non-login + Non-interactive (e.g., Bash scripts, cron jobs)
Opening the Terminal
To start using Bash, you’ll need to open your system’s terminal.
On Linux, you can usually press Ctrl + Alt + T or find "Terminal" in your applications menu.
On macOS, open Spotlight with Cmd + Space, type "Terminal", and hit Enter.
On Windows, you can install the Windows Subsystem for Linux (WSL) or use a Bash emulator like Git Bash.
When you open the terminal, you’ll see something like this:
username@computer:~$
That’s the prompt. It's where Bash waits for you to enter a command.
Understanding Basic Command Structure
Every Bash command follows a simple structure:
command [options] [arguments]
The command tells the shell what action to take. Options modify how the command behaves, and arguments tell it what to act upon. For example:
ls -la /home/user
This command lists all files (including hidden ones) in long format from the specified directory. Understanding this structure will help you make sense of most Bash commands.
Navigating the Filesystem
One of the most fundamental tasks in Bash is moving through your computer’s directories, also known as the filesystem.
To see where you are in the filesystem, use:
pwd
This stands for "print working directory" and shows your current location in the directory tree.
To move between directories, you use the cd (change directory) command:
cd /path/to/folder
You can also use shortcuts:
cd .. moves you up one level.
cd ~ or just cd returns you to your home directory.
To list the contents of a directory, use
ls
You can modify it with options like -l for a detailed view and -a to show hidden files:
ls -la
Creating and Managing Files and Folders
Bash makes it easy to create, move, rename, and delete files or directories.
To create a new empty file, use the touch command:
touch filename.txt
To create a new directory, use:
mkdir foldername
You can even create nested directories in one go using the -p option:
mkdir -p path/to/new/folder
To rename or move a file:
mv oldname.txt newname.txt
To copy a file:
cp original.txt copy.txt
To delete files or directories:
rm filename.txt
rm -r foldername
Be very cautious with rm -r as it deletes folders and all their contents without sending them to a trash bin.
Viewing and Editing Files
Once you've created files, you’ll need ways to view or edit their contents.
To simply display the contents of a file, use:
cat filename.txt
If the file is long, less allows you to scroll through it:
less filename.txt
To see only the beginning or end of a file:
head filename.txt
tail filename.txt
For live-updating files like logs, use:
tail -f log.txt
When it comes to editing text files directly in the terminal, you can use editors like nano, which is beginner-friendly, or vim, which is powerful but complex.
nano filename.txt
Understanding File Permissions
Linux systems have a robust permission system. When you run ls -l, you’ll see permissions displayed like this:
-rwxr-xr--
This line breaks down the permissions for the owner, group, and others.
r = read
w = write
x = execute
What Are File Permissions?
Every file and directory in Linux has associated permissions that determine who can read, write, or execute them.
There are three categories of users:
User (u) – The owner of the file
Group (g) – Users in the file’s group
Others (o) – Everyone else
And three types of permissions:
r → Read (4)
w → Write (2)
x → Execute (1)
To change a file’s permissions, use the chmod command:
chmod +x script.sh
This gives the file execute permission, which is necessary for running scripts.
Numeric Representation of Permissions
Permissions are commonly represented in two ways:
Symbolically (e.g., -rw-r--r--)
Numerically using octal notation (e.g., 644, 755)
Each permission group (user, group, others) is assigned a digit from 0 to 7, based on the sum of the permission values:
Permission | Binary | Value | Meaning |
--- | 000 | 0 | No permissions |
--x | 001 | 1 | Execute only |
-w- | 010 | 2 | Write only |
-wx | 011 | 3 | Write + Execute |
r-- | 100 | 4 | Read only |
r-x | 101 | 5 | Read + Execute |
rw- | 110 | 6 | Read + Write |
rwx | 111 | 7 | Full permissions |
You write three digits, one for each group: user, group, others.
Examples of Numeric Permissions
Let’s look at a few common permission settings:
chmod 644 file.txt
User: 6 → rw- (read + write)
Group: 4 → r-- (read only)
Others: 4 → r-- (read only)
Use case: Most common for text files. The owner can edit, others can only read.
chmod 755 script.sh
User: 7 → rwx (read + write + execute)
Group: 5 → r-x (read + execute)
Others: 5 → r-x (read + execute)
Use case: Typical for executable scripts or applications. The owner can modify and run it, others can only run.
chmod 700 secrets.txt
User: 7 → rwx
Group: 0 → ---
Others: 0 → ---
Use case: Private file that only the owner can read, write, or execute.
chmod 777 file.txt
User, Group, Others: All get rwx
Use case: Rarely advisable! Grants everyone full control. Only use in controlled environments like development or shared directories.
Pipes, Redirection, and Filters
Bash becomes truly powerful when you start chaining commands together.
Redirection allows you to save output to a file:
ls > files.txt # Overwrites
ls >> files.txt # Appends
You can also redirect input from a file:
cat < files.txt
You can also redirect input from a file:
cat < files.txt
Pipes pass the output of one command as input to another:
ls -l | grep ".txt"
This example lists files and then filters to show only those with a .txt extension.
There are also filter commands that process text:
grep searches for text.
sort arranges lines alphabetically.
uniq removes duplicate lines.
wc -l counts lines in a file.
Combining these tools lets you build powerful one-liners.
Keyboard Shortcuts and History Navigation
Bash includes handy shortcuts that improve your workflow:
Ctrl + A: Move to the beginning of the line
Ctrl + E: Move to the end
Ctrl + C: Cancel the current command
Ctrl + R: Reverse search through command history
You can access previously used commands with:
history
Use !! to repeat your last command, or !n to repeat a specific command number.
Writing and Running Bash Scripts
One of Bash’s most powerful features is scripting. You can write a series of commands in a file and execute them as a script.
To create a script:
1. Open a new file in a text editor:
nano myscript.sh
2. Add the following content:
#!/bin/bash
echo "Hello from Bash!"
3. Save and exit the editor, then make the script executable:
chmod +x myscript.sh
4. Run the script:
./myscript.sh
Scripts allow you to automate tasks, from file management to application deployment.
Control Structures in Bash
Bash scripts support logic just like programming languages. You can use conditional statements and loops.
If statements allow decisions based on conditions:
if [ "$name" == "Alice" ]; then
echo "Welcome, Alice!"
else
echo "Hello, stranger."
fi
Loops let you repeat actions:
for file in *.txt
do
echo "Found file: $file"
done
With these structures, your scripts can handle complex, real-world automation tasks.
Using Variables in Bash
Variables allow you to store and reuse values.
To assign a variable:
name="Alice"
To use it:
echo $name
Environment variables are system-level variables that affect your session. Common ones include:
echo $HOME
echo $PATH
To create an environment variable for the current session:
export MY_VAR="value"
Conclusion
Mastering the basics of Bash is like unlocking a new level of control over your system. What might seem like a simple black terminal window is actually a powerful gateway to automation, customization, and deeper interaction with your machine.
Throughout this guide, we've explored:
The core purpose of the Bash shell and how it fits into the Unix philosophy
The difference between login and interactive shells, helping you understand where your configuration lives and when it gets loaded
The essential command-line operations for navigating files and directories with confidence
And finally, how to work with file permissions numerically, giving you the tools to manage access with precision and clarity
With these foundational skills in place, you’re not just using your system—you’re starting to speak its language. You can automate repetitive tasks, customize your environment, and handle your files and scripts with authority.
But remember: this is just the beginning. Bash has many more layers—loops, conditionals, scripting logic, functions, piping and redirection, job control, and beyond. Each new concept builds on the foundation you’ve just laid.
👋 Have Questions or Want to Learn More?
Whether you're just getting started with Bash or you're already experimenting with automation and scripting, we're here to help you grow your skills and tackle your challenges. If you:
Have questions about the concepts in this blog
Need help troubleshooting your shell setup
Want personalised training, tutorials, or consulting
Or simply want to share your feedback or success story
Don’t hesitate to reach out!
📩 Email us at: contact@colabcodes.com or visit this link for a specified plan.
We're always excited to connect with fellow learners, developers, and tech enthusiasts. Let's keep the conversation going!
留言