๐ Table of Contents
What Is a Shell?
Your terminal is a program that lets you type text-based commands and see their output.
But what runs those commands?
Thatโs the shell.
๐ ๏ธ What Does a Shell Do?
The shellโs main job is to:
- Interpret the commands you type
- Execute those commands
๐ Shells as REPLs
Shells are often called REPLs, which stands for:
- Read
- Eval (evaluate)
- Loop
In simple terms, a shell:
- Reads the command you type
- Evaluates it (runs the program or command)
- Prints the output
- Loops back, showing a new prompt for the next command
๐ก This cycle makes shells interactive and powerful command interpreters.
Filesystem Commands
These commands help you interact with your Linux filesystem โ navigate, read, modify, and search files or directories.
๐ธ echo $variable
Displays the value of a variable.
NAME="Adarsh"
echo $NAME
# Output: Adarsh
๐ธ whoami
Prints the current logged-in username.
whoami
# Output: your_username
๐ธ pwd
Prints the current working directory (stands for โPrint Working Directoryโ).
pwd
# Output: /home/user/projects
๐ธ cat
Displays the entire content of a file.
cat notes.txt
๐ธ head
Shows the first 10 lines of a file (default).
head log.txt
You can change line count:
head -n 5 log.txt
๐ธ tail
Shows the last 10 lines of a file (default).
tail log.txt
Watch file updates live:
tail -f log.txt
๐ธ mv
Moves or renames a file or directory.
mv old.txt new.txt # Rename
mv file.txt /path/dir/ # Move
๐ธ cp
Copies files or directories.
cp a.txt b.txt # Copy file
cp -r folder1 folder2 # Copy directory recursively
๐ธ grep
Searches for patterns inside files.
grep "error" logfile.txt
Case-insensitive search:
grep -i "error" logfile.txt
๐ธ find
Searches for files/directories in a path.
find . -name "*.py"
Find files modified in the last 1 day:
find . -mtime -1
๐ธ ls
Lists files and folders in a directory.
ls
ls -l # Long format
ls -a # Include hidden files
๐ธ rm
Deletes files or directories.
rm file.txt # Delete file
rm -r folder/ # Delete folder and contents
โ ๏ธ Use with caution. No undo.
๐ธ touch
Creates an empty file or updates timestamp.
touch hello.txt
๐ธ mkdir
Creates a new directory.
mkdir new_folder