Bash and Zsh Basics Study Guide (Easy)

Bash and Zsh Basics Study Guide (Easy)

This study guide explains beginner shell concepts covered in the easy Bash/Zsh quiz. A shell is a program that lets you type commands to control your computer. bash and zsh are two common shells on macOS and Linux. The commands here are basic building blocks for moving around, creating files, and viewing information.

The Shell as a Workspace

Think of the shell as a workspace where you speak to your computer in short, direct instructions. Each command has a name and often uses options or arguments. An argument is extra information, like a file name or folder name. When you run a command, the shell shows the result on the screen and then waits for your next command.

Finding Your Location with pwd

The command pwd stands for “print working directory.” It shows the folder you are currently in. This is your current location in the filesystem. If you feel lost, pwd tells you where you are. This is a safe, read-only command that does not change anything.

Listing Files with ls

ls lists the files and folders in the current directory. It is how you “look around.” If you run ls and see a folder named projects, you can then move into it. When you are not sure what is inside a folder, use ls before making changes.

Moving Around with cd

cd means “change directory.” It moves you from one folder to another. For example, cd projects moves into the projects folder. You can also use cd .. to move up to the parent folder. Think of cd as walking through folders.

Creating Folders with mkdir

mkdir creates a new directory (folder). For example, mkdir notes makes a folder named notes. If you want to organize your files, this is how you create containers for them. It does not create files, only folders.

Creating Files with touch

touch creates an empty file if it does not exist. It also updates the file’s timestamp if it does exist. For beginners, you can think of touch as a quick way to make a new, blank file. Example: touch notes.txt creates a file named notes.txt. also touch ideas.txt and draft.txt to create more files.

Deleting Files with rm

rm removes files. It is powerful, so use it carefully. When you delete a file with rm, it is not sent to a trash bin. It is removed immediately. If you are unsure, double-check the file name with ls first. You can remove ideas.txt with rm ideas.txt, but be sure you want to delete it before running the command. (It CANNOT be undone!)

Copying Files with cp

cp copies files or folders. For example, cp notes.txt backup.txt creates a copy with a new name. Copying is useful when you want to save a version before making edits. If you copy folders, you usually add options to copy everything inside, but that is a more advanced topic. For now, just remember that cp makes duplicates.

Moving and Renaming with mv

mv moves files or folders to a new location. It also renames them. For example, mv draft.txt final.txt renames a file. If you move a file into another folder, you use mv file.txt folder/. It is the same command for both moving and renaming.

Viewing Files with cat

cat prints the contents of a file to the screen. If you have a file called notes.txt, you can run cat notes.txt to see what is inside. It is a quick way to read short files without opening an editor.

Printing Messages with echo

echo prints text to the terminal. It is often used to show messages or check variables. For a beginner, think of echo as “say this out loud.” Example: echo Hello prints Hello.

Clearing the Screen with clear

clear cleans up the terminal window so you can focus on new output. It does not delete any files or undo commands. It simply removes the visible history on the screen. You can still access command history if needed.

Special Paths: ~, ., and ..

These small symbols save time and help you navigate.

  • ~ means your home directory. It is your personal folder where your files live. cd ~ takes you home.
  • . (one dot) means the current directory. It is often used in paths, like ./script.sh, which means “run the script in this folder.”
  • .. (two dots) means the parent directory. cd .. moves up one level.

These shortcuts are used constantly, so it is worth memorizing them.

Command History with history

The history command lists commands you have run before. This is useful if you want to repeat something without retyping it. In many shells, you can also press the up arrow to cycle through previous commands. History makes you faster and helps reduce typing errors.

Building Good Habits

  • Look before you act: Use pwd and ls often so you know where you are and what is there.
  • Be cautious with rm: Double-check file names before deleting.
  • Use clear names: When you create files and folders, choose names that describe what they contain.
  • Keep your workspace tidy: Create folders with mkdir to keep related files together.

Common Beginner Mistakes

  • Forgetting where you are: If you run commands in the wrong folder, you might create or delete the wrong files. Use pwd to confirm.
  • Typos in file names: The shell is exact. Notes.txt and notes.txt are different files. Use ls to verify names.
  • Accidental deletes: rm removes files immediately. Use ls to confirm before deleting.
  • Confusing rename and copy: mv renames or moves; cp duplicates. Remember: “move” changes the location or name, “copy” keeps the original.

Practice Ideas

  • Create a folder called practice and move into it.
  • Make three files: one.txt, two.txt, three.txt.
  • Copy one.txt to one-backup.txt.
  • Rename two.txt to second.txt.
  • Print the contents of a file with cat.
  • Check your command history.

These simple steps help you connect commands to real actions.

Summary

Bash and Zsh are command-line shells that let you control your computer with text commands. The basics—pwd, ls, cd, mkdir, touch, rm, cp, mv, cat, echo, clear, ~, ., .., and history—form a toolkit for everyday tasks. If you understand these commands and use them carefully, you will be able to navigate, manage files, and work confidently in the terminal.