Tools
Linux Globbing — FULL Exercise Set
2025-12-26
0 views
admin
0️⃣ Setup (Run Once) ## 1️⃣ * — Match ANY number of characters ## Concept ## Exercises ## Expected understanding ## 2️⃣ ? — Match EXACTLY ONE character ## Concept ## Exercises ## Try and think ## 3️⃣ [abc] — Match ONE character from a set ## Concept ## Exercises ## Practical DevOps usage ## 4️⃣ [a-z] — Match a RANGE ## Concept ## Exercises ## 5️⃣ [!abc] — NEGATION (NOT match) ## Concept ## Exercises ## 6️⃣ {} — Brace Expansion (NOT globbing, but related) ## Exercises ## 7️⃣ Combine Globs (Real-world patterns) ## Exercises ## 8️⃣ Recursive Globbing ** (Advanced) ## Enable first ## Create nested structure ## Exercise ## 9️⃣ Hidden Files (.*) ## Create hidden files ## Exercises ## 🔟 Globbing with Commands (Critical DevOps Skill) ## Delete safely ## Count files ## 1️⃣1️⃣ Quoting DISABLES Globbing (Important) ## Exercise ## 1️⃣2️⃣ When GLOB DOES NOT MATCH ## Enable safer behavior ## 1️⃣3️⃣ Exam / Interview Questions (Very Common) ## 1️⃣4️⃣ Mini Lab (Assignment) ## 1️⃣5️⃣ Real DevOps Usage Examples ## ✅ Summary Table ## find Command — ? Meaning & Exercises (Ubuntu) ## 1️⃣ What does ? mean in find? ## 2️⃣ Setup (Run Once) ## 3️⃣ Basic find with ? ## Find files with ONE character after file ## 4️⃣ Compare ? vs * (Very Important) ## Using ? ## Using * ## 5️⃣ ? with directories ## 6️⃣ Multiple ? characters ## 7️⃣ Case-Insensitive search (-iname) ## 8️⃣ Real DevOps-style exercises ## 1️⃣ Find log files with one-digit version ## 2️⃣ Delete files carefully using ? ## 3️⃣ Count files matching ? ## 4️⃣ Combine ? with type ## 9️⃣ Common Mistake (Interview Question) ## 🔟 Interview Questions ## ✅ Summary ## head and tail Commands — Full Explanation + Exercises ## 1️⃣ What is head? ## Default behavior ## 2️⃣ What is tail? ## Default behavior ## 3️⃣ Setup (Run Once) ## 4️⃣ head Exercises ## Show first 5 lines ## Show first 1 line ## Shortcut ## 5️⃣ tail Exercises ## Show last 5 lines ## Show last line only ## 6️⃣ tail -f (VERY IMPORTANT for DevOps) ## Terminal 1 ## Terminal 2 ## 7️⃣ tail -n +NUMBER (Start from line) ## 8️⃣ Combine head and tail ## Get line 10 only ## Get lines 10–15 ## 9️⃣ Real DevOps Log Examples ## View last 50 lines of syslog ## Follow Docker logs ## Follow Kubernetes pod logs ## 🔟 Common Interview Questions ## 1️⃣1️⃣ Mini Lab (Homework) ## ✅ Summary Table ## wc (Word Count) — Full Explanation + Exercises ## 1️⃣ What is wc? ## 2️⃣ wc Output Explained ## 3️⃣ Setup (Run Once) ## 4️⃣ wc -l — Line Count (Most Used) ## 5️⃣ wc -w — Word Count ## 6️⃣ wc -c — Byte Count ## 7️⃣ wc -m — Character Count ## 8️⃣ Using wc with Pipes (Very Important) ## Count files ## Count log lines ## Count matching lines ## 9️⃣ Real DevOps Use Cases ## 1️⃣ Count running pods ## 2️⃣ Count files in directory ## 3️⃣ Count users ## 🔟 Common Mistakes ## 1️⃣1️⃣ Mini Lab (Homework) ## 1️⃣2️⃣ Interview Questions ## ✅ Summary Table ## File Size Determination — Exercises (Ubuntu) ## 1️⃣ Setup (Run Once) ## 2️⃣ ls -lh — Human-readable size (Most common) ## Exercise ## Questions ## 3️⃣ du -h — Disk usage (Real storage used) ## Exercise ## File only ## Directory size ## Summary only ## 4️⃣ stat — Exact size in bytes (Interview favorite) ## Exercise ## 5️⃣ wc -c — Size in bytes (Content-based) ## Exercise ## 6️⃣ Compare Commands (Important Concept) ## 7️⃣ Find Files Bigger Than X Size ## Bigger than 1MB ## Smaller than 1KB ## 8️⃣ Sort Files by Size ## Largest first ## Smallest first ## 9️⃣ Real DevOps Exercises ## 1️⃣ Find large log files ## 2️⃣ Check directory disk usage ## 3️⃣ Monitor growing file ## 🔟 Common Mistakes (Interview) ## 1️⃣1️⃣ Mini Lab (Homework) ## 1️⃣2️⃣ Interview Questions ## ✅ Summary Cheat Sheet ## Output Redirection Exercises — > and >> ## 1️⃣ What are > and >>? ## 2️⃣ Setup (Run Once) ## 3️⃣ > — Overwrite Redirection ## Exercise 1 ## Exercise 2 (Overwrite) ## 4️⃣ >> — Append Redirection ## Exercise 3 ## 5️⃣ Real Difference Test (Very Important) ## 6️⃣ Redirect Command Output ## Save ls output ## Append more output ## 7️⃣ Redirect Errors (stderr) ## Error without redirect ## Redirect error ## Append error ## 8️⃣ Redirect Both Output and Error ## 9️⃣ Discard Output (Production Trick) ## 🔟 Combine with wc, tail, grep ## Count lines and save ## Append logs ## 1️⃣1️⃣ Real DevOps Examples ## Log rotation simulation ## Save command result in script ## 1️⃣2️⃣ Common Mistakes (Interview) ## 1️⃣3️⃣ Mini Lab (Homework) ## 1️⃣4️⃣ Interview Questions ## ✅ Summary Cheat Sheet ## tee Command — Exercises & Explanation ## 1️⃣ What is tee? ## 2️⃣ Setup (Run Once) ## 3️⃣ Basic tee Exercise ## Write output to screen AND file ## 4️⃣ tee -a (Append Mode) ## Overwrite vs append ## 5️⃣ tee vs > (Important Difference) ## Using > ## Using tee ## 6️⃣ Multiple Files with tee ## 7️⃣ tee in Pipelines ## Count and save ## Analyze logs ## 8️⃣ sudo + tee (VERY IMPORTANT) ## Problem ## Solution ## Append with sudo ## 9️⃣ Real DevOps Use Cases ## Save disk report ## Capture install logs ## Kubernetes debugging ## 🔟 Common Mistakes ## 1️⃣1️⃣ Mini Lab (Homework) ## 1️⃣2️⃣ Interview Questions ## ✅ Summary Cheat Sheet ## uniq and grep — Exercises & Explanation ## 1️⃣ What is grep? ## 2️⃣ What is uniq? ## 3️⃣ Setup (Run Once) ## 4️⃣ grep — Basic Exercises ## Find lines containing error ## Case-insensitive search ## Show line numbers ## Count matching lines ## Search multiple patterns ## 5️⃣ grep — Inverted Match (-v) ## Show lines WITHOUT info ## 6️⃣ grep with Pipes (Real Usage) ## Find errors in last 100 log lines ## Count errors ## 7️⃣ uniq — Basic (Important Rule) ## ❌ Wrong (no effect) ## 8️⃣ sort + uniq (Correct Way) ## Remove duplicates ## Count duplicate lines ## 9️⃣ uniq Options (Very Important) ## Show only duplicates ## Show only unique (non-duplicate) ## 🔟 Combine grep + uniq ## Unique error messages ## Count unique errors ## 1️⃣1️⃣ Real DevOps Examples ## Count unique IPs ## Unique Kubernetes errors ## 1️⃣2️⃣ Common Mistakes (Interview) ## 1️⃣3️⃣ Mini Lab (Homework) ## 1️⃣4️⃣ Interview Questions ## ✅ Summary Cheat Sheet ## PATH Environment Variable — Explanation & Exercises ## 1️⃣ What is PATH? ## 2️⃣ Why PATH Matters (Real Meaning) ## 3️⃣ Setup (Run Once) ## 4️⃣ Command NOT in PATH ## 5️⃣ Temporarily Add to PATH ## 6️⃣ Check Where Command Comes From ## 7️⃣ Order of PATH (VERY IMPORTANT) ## 8️⃣ Put Directory FIRST in PATH (Danger Demo) ## 9️⃣ Permanent PATH Change (User Only) ## 🔟 System-wide PATH (Admins) ## 1️⃣1️⃣ PATH with Scripts (DevOps Use) ## 1️⃣2️⃣ Common Mistakes (Interview) ## 1️⃣3️⃣ Mini Lab (Homework) ## 1️⃣4️⃣ Interview Questions ## ✅ Summary Cheat Sheet ## Bash Variables & Environment Variables ## Full Exercise Set for DevOps Engineers ## 1️⃣ Bash Variable (Local Variable) ## What it is ## Exercise ## 2️⃣ Variable Scope Test (Very Important) ## 3️⃣ Environment Variable (export) ## What it is ## Exercise ## 4️⃣ Difference: Bash vs Env Variable ## 5️⃣ List Variables ## All shell variables ## Only environment variables ## 6️⃣ Unset Variables ## 7️⃣ Read-only Variables ## 8️⃣ Command Substitution (VERY IMPORTANT) ## Store command output in variable ## 9️⃣ Variable Expansion Types ## Default value ## Assign default ## Error if unset ## 🔟 Positional Variables (Scripts) ## 1️⃣1️⃣ Special Variables (INTERVIEW FAVORITE) ## Exercise ## 1️⃣2️⃣ Global Environment Files (DevOps MUST KNOW) ## 1️⃣3️⃣ Permanent Environment Variable ## User-level ## 1️⃣4️⃣ Environment Variables in Scripts ## 1️⃣5️⃣ Inline Environment Variable (VERY COMMON) ## 1️⃣6️⃣ .env File (Real DevOps Pattern) ## 1️⃣7️⃣ PATH Variable (Critical) ## 1️⃣8️⃣ DevOps Tool Examples ## Docker ## Kubernetes ## 1️⃣9️⃣ Security Best Practices (IMPORTANT) ## 2️⃣0️⃣ Mini DevOps Lab (Homework) ## 2️⃣1️⃣ Interview Questions (REAL) ## ✅ Final Cheat Sheet Create a safe practice directory. Matches zero or more characters Matches one and only one character Why does file10.txt match? Matches any ONE character inside brackets Deletes app1.log and app2.log Alphabetical or numeric range Matches anything NOT in brackets ⚠️ Happens before globbing Multiple patterns at once: ⚠️ * does NOT match hidden files by default What is the difference between * and ?? Why does rm *.log sometimes delete too much? Why doesn’t ls * show .env? Difference between {} and []? 👉 ? is a wildcard that matches EXACTLY ONE character
It is used inside -name or -iname. Q1: Difference between ? in ls and find?
Answer: Q2: Why does file10.txt not match file?.txt?
Answer:
Because ? matches exactly one character 👉 head shows the first lines of a file. ✔ Shows first 10 lines 👉 tail shows the last lines of a file. ✔ Shows last 10 lines This file has 50 lines. 👉 Follow a file in real time You will see output instantly. ✔ Shows from line 10 till end What is difference between tail and tail -f? How to get only the first line of a file? How to get last line only? 👉 wc = word count
Used to count: ✔ Counts number of lines Counts words separated by spaces Counts bytes (includes newline) Better for multi-byte characters (UTF-8) ❌ Thinking lc exists
✔ Correct is: Q1: Difference between wc -c and wc -m
Answer: Q2: How to count output lines of a command?
Answer:
Use pipe: ✔ Shows file sizes in: ✔ du = how much disk space is actually used ✔ Most accurate size info ✔ Counts bytes including newline ❌ Using ls to check disk usage
✔ Use du for actual disk usage ❌ Confusing bytes vs blocks
✔ stat is the source of truth Q1: Difference between ls -lh and du -h?
Answer: Q2: Which command gives exact size in bytes?
Answer:
stat ❗ Previous content is deleted ✔ Content is added, not replaced ❌ Using > instead of >> → data loss
❌ Forgetting 2> for errors
❌ Overwriting log files accidentally Q1: Difference between > and >>
Answer: Q2: How to redirect error only?
Answer: 👉 tee reads from standard input and writes to: Think of it as a splitter. ✔ -a = append
❌ Without -a = overwrite ❌ No output on screen ✔ Output shown AND saved ❌ Forgetting -a → overwrites logs
❌ Using > with sudo
❌ Thinking tee replaces pipes Q1: Why use tee instead of >?
Answer:
To see output and save it at the same time. Q2: Why does sudo echo text > file fail?
Answer:
Redirection happens before sudo. 👉 grep searches for patterns in text. 👉 uniq removes or analyzes duplicate lines
⚠️ Important: uniq works only on adjacent lines → usually needs sort first. Used a lot in log filtering. Why?
👉 Duplicates are not adjacent ❌ Using uniq without sort
❌ Forgetting -i for case-insensitive search
❌ Using grep instead of grep -v Q1: Why doesn’t uniq remove all duplicates?
Answer:
Because it works only on adjacent lines Q2: Difference between grep error and grep -v error?
Answer: 👉 PATH is a colon-separated list of directories.
When you type a command, Linux searches these directories in order. Linux actually checks: Create a custom command: ✔ Works without full path ⚠️ This change lasts only for this terminal session Shows exact path of the command being used. Create another command: Why didn’t it run your fake one? 👉 Because your directory is after /usr/bin ⚠️ Your fake ls runs! 👉 Security risk — interview favorite ⚠️ Requires sudo
⚠️ Affects all users If AWS CLI not in PATH → script fails ❌ Putting . in PATH (security risk) Q1: What is PATH?
Answer:
A list of directories where shell looks for commands Q2: Why is PATH order important?
Answer:
First match wins → security impact Q3: Difference between temporary and permanent PATH?
Answer: ❌ Space is not allowed: ❌ Output is empty
👉 Local variables do not pass to child shells Old style (still seen): ✔ Variable exists only for this command ⚠ Never overwrite PATH ❌ Never hardcode secrets: ✔ Use env vars or secret managers ✔ .env → add to .gitignore Q: Difference between set and env
A: Q: Why use env vars in DevOps?
A:
For configuration, secrets, portability Q: How do you pass env vars to Docker/K8s?
A:
Environment variables or secret managers Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse CODE_BLOCK:
mkdir ~/globbing-lab
cd ~/globbing-lab
touch file1.txt file2.txt file10.txt fileA.txt fileB.log fileC.log
touch app.log app1.log app2.log error.log
mkdir dir1 dir2 dirA Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
mkdir ~/globbing-lab
cd ~/globbing-lab
touch file1.txt file2.txt file10.txt fileA.txt fileB.log fileC.log
touch app.log app1.log app2.log error.log
mkdir dir1 dir2 dirA CODE_BLOCK:
mkdir ~/globbing-lab
cd ~/globbing-lab
touch file1.txt file2.txt file10.txt fileA.txt fileB.log fileC.log
touch app.log app1.log app2.log error.log
mkdir dir1 dir2 dirA CODE_BLOCK:
ls *
ls *.txt
ls *.log
ls file*
ls app* Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls *
ls *.txt
ls *.log
ls file*
ls app* CODE_BLOCK:
ls *
ls *.txt
ls *.log
ls file*
ls app* CODE_BLOCK:
ls file?.txt
ls app?.log
ls dir? Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls file?.txt
ls app?.log
ls dir? CODE_BLOCK:
ls file?.txt
ls app?.log
ls dir? CODE_BLOCK:
ls file??.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls file??.txt CODE_BLOCK:
ls file??.txt CODE_BLOCK:
ls file[12].txt
ls file[A-Z].txt
ls dir[12] Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls file[12].txt
ls file[A-Z].txt
ls dir[12] CODE_BLOCK:
ls file[12].txt
ls file[A-Z].txt
ls dir[12] CODE_BLOCK:
rm app[12].log Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
rm app[12].log CODE_BLOCK:
rm app[12].log CODE_BLOCK:
ls file[a-z].txt
ls file[0-9].txt
ls dir[a-z] Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls file[a-z].txt
ls file[0-9].txt
ls dir[a-z] CODE_BLOCK:
ls file[a-z].txt
ls file[0-9].txt
ls dir[a-z] CODE_BLOCK:
ls file[!1].txt
ls file[!0-9].txt
ls *.log
ls [!a]*.log Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls file[!1].txt
ls file[!0-9].txt
ls *.log
ls [!a]*.log CODE_BLOCK:
ls file[!1].txt
ls file[!0-9].txt
ls *.log
ls [!a]*.log CODE_BLOCK:
touch {dev,stage,prod}.env
ls *.env Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
touch {dev,stage,prod}.env
ls *.env CODE_BLOCK:
touch {dev,stage,prod}.env
ls *.env CODE_BLOCK:
ls file{1,2}.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls file{1,2}.txt CODE_BLOCK:
ls file{1,2}.txt CODE_BLOCK:
ls file[0-9]*.txt
ls app?.log
ls *[A-Z].* Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls file[0-9]*.txt
ls app?.log
ls *[A-Z].* CODE_BLOCK:
ls file[0-9]*.txt
ls app?.log
ls *[A-Z].* CODE_BLOCK:
shopt -s globstar Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
shopt -s globstar CODE_BLOCK:
shopt -s globstar CODE_BLOCK:
mkdir -p logs/2024/app
touch logs/2024/app/app.log Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
mkdir -p logs/2024/app
touch logs/2024/app/app.log CODE_BLOCK:
mkdir -p logs/2024/app
touch logs/2024/app/app.log CODE_BLOCK:
ls **/*.log Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls **/*.log CODE_BLOCK:
ls **/*.log CODE_BLOCK:
touch .env .gitignore .bashrc Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
touch .env .gitignore .bashrc CODE_BLOCK:
touch .env .gitignore .bashrc CODE_BLOCK:
ls .*
ls -a Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls .*
ls -a CODE_BLOCK:
ls .*
ls -a CODE_BLOCK:
cp *.log /tmp/ Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
cp *.log /tmp/ CODE_BLOCK:
cp *.log /tmp/ CODE_BLOCK:
rm -i file*.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
rm -i file*.txt CODE_BLOCK:
rm -i file*.txt CODE_BLOCK:
ls *.log | wc -l Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls *.log | wc -l CODE_BLOCK:
ls *.log | wc -l CODE_BLOCK:
echo *.log
echo "*.log" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
echo *.log
echo "*.log" CODE_BLOCK:
echo *.log
echo "*.log" CODE_BLOCK:
ls nomatch* Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls nomatch* CODE_BLOCK:
ls nomatch* CODE_BLOCK:
shopt -s nullglob
ls nomatch* Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
shopt -s nullglob
ls nomatch* CODE_BLOCK:
shopt -s nullglob
ls nomatch* COMMAND_BLOCK:
kubectl logs pod-* aws s3 rm s3://bucket/logs/2024/*
scp app*.jar server:/opt/apps/ Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
kubectl logs pod-* aws s3 rm s3://bucket/logs/2024/*
scp app*.jar server:/opt/apps/ COMMAND_BLOCK:
kubectl logs pod-* aws s3 rm s3://bucket/logs/2024/*
scp app*.jar server:/opt/apps/ CODE_BLOCK:
mkdir ~/find-lab
cd ~/find-lab
touch file1.txt file2.txt file10.txt fileA.txt fileB.log
mkdir dir1 dir2 dir10 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
mkdir ~/find-lab
cd ~/find-lab
touch file1.txt file2.txt file10.txt fileA.txt fileB.log
mkdir dir1 dir2 dir10 CODE_BLOCK:
mkdir ~/find-lab
cd ~/find-lab
touch file1.txt file2.txt file10.txt fileA.txt fileB.log
mkdir dir1 dir2 dir10 CODE_BLOCK:
find . -name "file?.txt" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -name "file?.txt" CODE_BLOCK:
find . -name "file?.txt" CODE_BLOCK:
find . -name "file?.txt" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -name "file?.txt" CODE_BLOCK:
find . -name "file?.txt" CODE_BLOCK:
find . -name "file*.txt" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -name "file*.txt" CODE_BLOCK:
find . -name "file*.txt" CODE_BLOCK:
find . -type d -name "dir?" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -type d -name "dir?" CODE_BLOCK:
find . -type d -name "dir?" CODE_BLOCK:
find . -name "file??.txt" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -name "file??.txt" CODE_BLOCK:
find . -name "file??.txt" CODE_BLOCK:
find . -iname "file?.txt" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -iname "file?.txt" CODE_BLOCK:
find . -iname "file?.txt" CODE_BLOCK:
find /var/log -name "app?.log" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find /var/log -name "app?.log" CODE_BLOCK:
find /var/log -name "app?.log" CODE_BLOCK:
find . -name "file?.txt" -delete Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -name "file?.txt" -delete CODE_BLOCK:
find . -name "file?.txt" -delete CODE_BLOCK:
find . -name "file?.txt" | wc -l Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -name "file?.txt" | wc -l CODE_BLOCK:
find . -name "file?.txt" | wc -l CODE_BLOCK:
find . -type f -name "file?.*" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -type f -name "file?.*" CODE_BLOCK:
find . -type f -name "file?.*" CODE_BLOCK:
find . -name file?.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -name file?.txt CODE_BLOCK:
find . -name file?.txt CODE_BLOCK:
find . -name "file?.txt" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -name "file?.txt" CODE_BLOCK:
find . -name "file?.txt" CODE_BLOCK:
head file.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
head file.txt CODE_BLOCK:
head file.txt CODE_BLOCK:
tail file.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
tail file.txt CODE_BLOCK:
tail file.txt COMMAND_BLOCK:
mkdir ~/head-tail-lab
cd ~/head-tail-lab
seq 1 50 > numbers.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
mkdir ~/head-tail-lab
cd ~/head-tail-lab
seq 1 50 > numbers.txt COMMAND_BLOCK:
mkdir ~/head-tail-lab
cd ~/head-tail-lab
seq 1 50 > numbers.txt CODE_BLOCK:
head -n 5 numbers.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
head -n 5 numbers.txt CODE_BLOCK:
head -n 5 numbers.txt CODE_BLOCK:
head -n 1 numbers.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
head -n 1 numbers.txt CODE_BLOCK:
head -n 1 numbers.txt CODE_BLOCK:
head -5 numbers.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
head -5 numbers.txt CODE_BLOCK:
head -5 numbers.txt CODE_BLOCK:
tail -n 5 numbers.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
tail -n 5 numbers.txt CODE_BLOCK:
tail -n 5 numbers.txt CODE_BLOCK:
tail -n 1 numbers.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
tail -n 1 numbers.txt CODE_BLOCK:
tail -n 1 numbers.txt CODE_BLOCK:
tail -f numbers.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
tail -f numbers.txt CODE_BLOCK:
tail -f numbers.txt COMMAND_BLOCK:
echo "new log line" >> numbers.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
echo "new log line" >> numbers.txt COMMAND_BLOCK:
echo "new log line" >> numbers.txt CODE_BLOCK:
tail -n +10 numbers.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
tail -n +10 numbers.txt CODE_BLOCK:
tail -n +10 numbers.txt CODE_BLOCK:
head -n 10 numbers.txt | tail -n 1 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
head -n 10 numbers.txt | tail -n 1 CODE_BLOCK:
head -n 10 numbers.txt | tail -n 1 CODE_BLOCK:
head -n 15 numbers.txt | tail -n 6 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
head -n 15 numbers.txt | tail -n 6 CODE_BLOCK:
head -n 15 numbers.txt | tail -n 6 CODE_BLOCK:
tail -n 50 /var/log/syslog Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
tail -n 50 /var/log/syslog CODE_BLOCK:
tail -n 50 /var/log/syslog COMMAND_BLOCK:
docker logs -f container_name Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
docker logs -f container_name COMMAND_BLOCK:
docker logs -f container_name COMMAND_BLOCK:
kubectl logs -f pod-name Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
kubectl logs -f pod-name COMMAND_BLOCK:
kubectl logs -f pod-name CODE_BLOCK:
head -n 1 file.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
head -n 1 file.txt CODE_BLOCK:
head -n 1 file.txt CODE_BLOCK:
tail -n 1 file.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
tail -n 1 file.txt CODE_BLOCK:
tail -n 1 file.txt CODE_BLOCK:
wc file.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
wc file.txt CODE_BLOCK:
wc file.txt CODE_BLOCK:
LINES WORDS BYTES filename Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
LINES WORDS BYTES filename CODE_BLOCK:
LINES WORDS BYTES filename CODE_BLOCK:
50 50 141 file.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
50 50 141 file.txt CODE_BLOCK:
50 50 141 file.txt COMMAND_BLOCK:
mkdir ~/wc-lab
cd ~/wc-lab
seq 1 20 > numbers.txt
echo "hello linux devops world" > text.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
mkdir ~/wc-lab
cd ~/wc-lab
seq 1 20 > numbers.txt
echo "hello linux devops world" > text.txt COMMAND_BLOCK:
mkdir ~/wc-lab
cd ~/wc-lab
seq 1 20 > numbers.txt
echo "hello linux devops world" > text.txt CODE_BLOCK:
wc -l numbers.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
wc -l numbers.txt CODE_BLOCK:
wc -l numbers.txt CODE_BLOCK:
wc -w text.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
wc -w text.txt CODE_BLOCK:
wc -w text.txt CODE_BLOCK:
wc -c text.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
wc -c text.txt CODE_BLOCK:
wc -c text.txt CODE_BLOCK:
wc -m text.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
wc -m text.txt CODE_BLOCK:
wc -m text.txt CODE_BLOCK:
ls | wc -l Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
tail -n 100 /var/log/syslog | wc -l Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
tail -n 100 /var/log/syslog | wc -l CODE_BLOCK:
tail -n 100 /var/log/syslog | wc -l CODE_BLOCK:
grep error /var/log/syslog | wc -l Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep error /var/log/syslog | wc -l CODE_BLOCK:
grep error /var/log/syslog | wc -l COMMAND_BLOCK:
kubectl get pods | wc -l Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
kubectl get pods | wc -l COMMAND_BLOCK:
kubectl get pods | wc -l CODE_BLOCK:
find . -type f | wc -l Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -type f | wc -l CODE_BLOCK:
find . -type f | wc -l CODE_BLOCK:
cat /etc/passwd | wc -l Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
cat /etc/passwd | wc -l CODE_BLOCK:
cat /etc/passwd | wc -l CODE_BLOCK:
wc -l Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
ls wc -l # wrong
ls | wc -l # correct Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
ls wc -l # wrong
ls | wc -l # correct COMMAND_BLOCK:
ls wc -l # wrong
ls | wc -l # correct CODE_BLOCK:
command | wc -l Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
command | wc -l CODE_BLOCK:
command | wc -l COMMAND_BLOCK:
mkdir ~/file-size-lab
cd ~/file-size-lab
echo "hello world" > small.txt
seq 1 1000 > numbers.txt
dd if=/dev/zero of=bigfile.bin bs=1M count=5
mkdir logs
cp numbers.txt logs/ Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
mkdir ~/file-size-lab
cd ~/file-size-lab
echo "hello world" > small.txt
seq 1 1000 > numbers.txt
dd if=/dev/zero of=bigfile.bin bs=1M count=5
mkdir logs
cp numbers.txt logs/ COMMAND_BLOCK:
mkdir ~/file-size-lab
cd ~/file-size-lab
echo "hello world" > small.txt
seq 1 1000 > numbers.txt
dd if=/dev/zero of=bigfile.bin bs=1M count=5
mkdir logs
cp numbers.txt logs/ CODE_BLOCK:
ls -lh Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
du -h Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
du -h small.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
du -h small.txt CODE_BLOCK:
du -h small.txt CODE_BLOCK:
du -h logs/ Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
du -h logs/ CODE_BLOCK:
du -h logs/ CODE_BLOCK:
du -sh logs/ Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
du -sh logs/ CODE_BLOCK:
du -sh logs/ CODE_BLOCK:
stat numbers.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
stat numbers.txt CODE_BLOCK:
stat numbers.txt CODE_BLOCK:
Size: 3893 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
wc -c small.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
wc -c small.txt CODE_BLOCK:
wc -c small.txt CODE_BLOCK:
stat small.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
stat small.txt CODE_BLOCK:
stat small.txt CODE_BLOCK:
find . -type f -size +1M Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -type f -size +1M CODE_BLOCK:
find . -type f -size +1M CODE_BLOCK:
find . -type f -size -1k Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find . -type f -size -1k CODE_BLOCK:
find . -type f -size -1k CODE_BLOCK:
ls -lhS Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls -lhrS Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find /var/log -type f -size +100M Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
find /var/log -type f -size +100M CODE_BLOCK:
find /var/log -type f -size +100M CODE_BLOCK:
du -sh /var/log Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
du -sh /var/log CODE_BLOCK:
du -sh /var/log CODE_BLOCK:
watch -n 1 ls -lh bigfile.bin Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
watch -n 1 ls -lh bigfile.bin CODE_BLOCK:
watch -n 1 ls -lh bigfile.bin CODE_BLOCK:
ls -lh file
du -sh file_or_dir
stat file
wc -c file
find . -size +10M Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls -lh file
du -sh file_or_dir
stat file
wc -c file
find . -size +10M CODE_BLOCK:
ls -lh file
du -sh file_or_dir
stat file
wc -c file
find . -size +10M CODE_BLOCK:
mkdir ~/redirect-lab
cd ~/redirect-lab Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
mkdir ~/redirect-lab
cd ~/redirect-lab CODE_BLOCK:
mkdir ~/redirect-lab
cd ~/redirect-lab COMMAND_BLOCK:
echo "Hello DevOps" > output.txt
cat output.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
echo "Hello DevOps" > output.txt
cat output.txt COMMAND_BLOCK:
echo "Hello DevOps" > output.txt
cat output.txt COMMAND_BLOCK:
echo "Linux is powerful" > output.txt
cat output.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
echo "Linux is powerful" > output.txt
cat output.txt COMMAND_BLOCK:
echo "Linux is powerful" > output.txt
cat output.txt COMMAND_BLOCK:
echo "Line 1" >> output.txt
echo "Line 2" >> output.txt
cat output.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
echo "Line 1" >> output.txt
echo "Line 2" >> output.txt
cat output.txt COMMAND_BLOCK:
echo "Line 1" >> output.txt
echo "Line 2" >> output.txt
cat output.txt COMMAND_BLOCK:
echo "START" > test.txt
echo "APPEND" >> test.txt
echo "OVERWRITE" > test.txt
cat test.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
echo "START" > test.txt
echo "APPEND" >> test.txt
echo "OVERWRITE" > test.txt
cat test.txt COMMAND_BLOCK:
echo "START" > test.txt
echo "APPEND" >> test.txt
echo "OVERWRITE" > test.txt
cat test.txt CODE_BLOCK:
OVERWRITE Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
ls > files.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
ls > files.txt COMMAND_BLOCK:
ls > files.txt COMMAND_BLOCK:
ls /etc >> files.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
ls /etc >> files.txt COMMAND_BLOCK:
ls /etc >> files.txt CODE_BLOCK:
ls not_exist Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls not_exist CODE_BLOCK:
ls not_exist COMMAND_BLOCK:
ls not_exist 2> error.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
ls not_exist 2> error.txt COMMAND_BLOCK:
ls not_exist 2> error.txt COMMAND_BLOCK:
ls not_exist 2>> error.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
ls not_exist 2>> error.txt COMMAND_BLOCK:
ls not_exist 2>> error.txt COMMAND_BLOCK:
ls /etc not_exist > all.txt 2>&1 Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
ls /etc not_exist > all.txt 2>&1 COMMAND_BLOCK:
ls /etc not_exist > all.txt 2>&1 COMMAND_BLOCK:
ls not_exist > /dev/null
ls not_exist 2> /dev/null
ls not_exist > /dev/null 2>&1 Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
ls not_exist > /dev/null
ls not_exist 2> /dev/null
ls not_exist > /dev/null 2>&1 COMMAND_BLOCK:
ls not_exist > /dev/null
ls not_exist 2> /dev/null
ls not_exist > /dev/null 2>&1 COMMAND_BLOCK:
ls /etc | wc -l > count.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
ls /etc | wc -l > count.txt COMMAND_BLOCK:
ls /etc | wc -l > count.txt COMMAND_BLOCK:
date >> app.log Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
date >> app.log COMMAND_BLOCK:
date >> app.log COMMAND_BLOCK:
echo "$(date) App started" >> app.log Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
echo "$(date) App started" >> app.log COMMAND_BLOCK:
echo "$(date) App started" >> app.log COMMAND_BLOCK:
df -h > disk_report.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
df -h > disk_report.txt COMMAND_BLOCK:
df -h > disk_report.txt CODE_BLOCK:
2> Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
command > file
command >> file
command 2> error.txt
command > all.txt 2>&1
command > /dev/null Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
command > file
command >> file
command 2> error.txt
command > all.txt 2>&1
command > /dev/null COMMAND_BLOCK:
command > file
command >> file
command 2> error.txt
command > all.txt 2>&1
command > /dev/null CODE_BLOCK:
command | tee file.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
command | tee file.txt CODE_BLOCK:
command | tee file.txt CODE_BLOCK:
mkdir ~/tee-lab
cd ~/tee-lab Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
mkdir ~/tee-lab
cd ~/tee-lab CODE_BLOCK:
mkdir ~/tee-lab
cd ~/tee-lab CODE_BLOCK:
echo "Hello DevOps" | tee output.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
echo "Hello DevOps" | tee output.txt CODE_BLOCK:
echo "Hello DevOps" | tee output.txt CODE_BLOCK:
cat output.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
cat output.txt CODE_BLOCK:
cat output.txt CODE_BLOCK:
echo "Line 1" | tee output.txt
echo "Line 2" | tee -a output.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
echo "Line 1" | tee output.txt
echo "Line 2" | tee -a output.txt CODE_BLOCK:
echo "Line 1" | tee output.txt
echo "Line 2" | tee -a output.txt COMMAND_BLOCK:
ls > files.txt Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
ls > files.txt COMMAND_BLOCK:
ls > files.txt CODE_BLOCK:
ls | tee files.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls | tee files.txt CODE_BLOCK:
ls | tee files.txt CODE_BLOCK:
echo "Shared log line" | tee file1.log file2.log Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
echo "Shared log line" | tee file1.log file2.log CODE_BLOCK:
echo "Shared log line" | tee file1.log file2.log CODE_BLOCK:
ls | tee list.txt | wc -l Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
ls | tee list.txt | wc -l CODE_BLOCK:
ls | tee list.txt | wc -l CODE_BLOCK:
grep error /var/log/syslog | tee errors.txt | wc -l Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep error /var/log/syslog | tee errors.txt | wc -l CODE_BLOCK:
grep error /var/log/syslog | tee errors.txt | wc -l COMMAND_BLOCK:
sudo echo "text" > /root/test.txt # fails Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
sudo echo "text" > /root/test.txt # fails COMMAND_BLOCK:
sudo echo "text" > /root/test.txt # fails CODE_BLOCK:
echo "text" | sudo tee /root/test.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
echo "text" | sudo tee /root/test.txt CODE_BLOCK:
echo "text" | sudo tee /root/test.txt CODE_BLOCK:
echo "more text" | sudo tee -a /root/test.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
echo "more text" | sudo tee -a /root/test.txt CODE_BLOCK:
echo "more text" | sudo tee -a /root/test.txt CODE_BLOCK:
df -h | tee disk_report.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
df -h | tee disk_report.txt CODE_BLOCK:
df -h | tee disk_report.txt COMMAND_BLOCK:
sudo apt update | tee update.log Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
sudo apt update | tee update.log COMMAND_BLOCK:
sudo apt update | tee update.log COMMAND_BLOCK:
kubectl logs pod-name | tee pod.log Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
kubectl logs pod-name | tee pod.log COMMAND_BLOCK:
kubectl logs pod-name | tee pod.log CODE_BLOCK:
command | tee file.txt
command | tee -a file.txt
command | tee file1 file2
command | sudo tee /path/file Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
command | tee file.txt
command | tee -a file.txt
command | tee file1 file2
command | sudo tee /path/file CODE_BLOCK:
command | tee file.txt
command | tee -a file.txt
command | tee file1 file2
command | sudo tee /path/file CODE_BLOCK:
grep PATTERN file Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep PATTERN file CODE_BLOCK:
grep PATTERN file COMMAND_BLOCK:
mkdir ~/grep-uniq-lab
cd ~/grep-uniq-lab cat <<EOF > logs.txt
error disk full
info service started
warning cpu high
error disk full
error network down
info service started
EOF Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
mkdir ~/grep-uniq-lab
cd ~/grep-uniq-lab cat <<EOF > logs.txt
error disk full
info service started
warning cpu high
error disk full
error network down
info service started
EOF COMMAND_BLOCK:
mkdir ~/grep-uniq-lab
cd ~/grep-uniq-lab cat <<EOF > logs.txt
error disk full
info service started
warning cpu high
error disk full
error network down
info service started
EOF CODE_BLOCK:
grep error logs.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep error logs.txt CODE_BLOCK:
grep error logs.txt CODE_BLOCK:
grep -i ERROR logs.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep -i ERROR logs.txt CODE_BLOCK:
grep -i ERROR logs.txt CODE_BLOCK:
grep -n error logs.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep -n error logs.txt CODE_BLOCK:
grep -n error logs.txt CODE_BLOCK:
grep -c error logs.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep -c error logs.txt CODE_BLOCK:
grep -c error logs.txt CODE_BLOCK:
grep -E "error|warning" logs.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep -E "error|warning" logs.txt CODE_BLOCK:
grep -E "error|warning" logs.txt CODE_BLOCK:
grep -v info logs.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep -v info logs.txt CODE_BLOCK:
grep -v info logs.txt CODE_BLOCK:
tail -n 100 /var/log/syslog | grep error Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
tail -n 100 /var/log/syslog | grep error CODE_BLOCK:
tail -n 100 /var/log/syslog | grep error CODE_BLOCK:
grep error logs.txt | wc -l Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep error logs.txt | wc -l CODE_BLOCK:
grep error logs.txt | wc -l CODE_BLOCK:
uniq logs.txt Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
uniq logs.txt CODE_BLOCK:
uniq logs.txt CODE_BLOCK:
sort logs.txt | uniq Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
sort logs.txt | uniq CODE_BLOCK:
sort logs.txt | uniq CODE_BLOCK:
sort logs.txt | uniq -c Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
sort logs.txt | uniq -c CODE_BLOCK:
sort logs.txt | uniq -c CODE_BLOCK:
2 error disk full
2 info service started
1 warning cpu high Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
2 error disk full
2 info service started
1 warning cpu high CODE_BLOCK:
2 error disk full
2 info service started
1 warning cpu high CODE_BLOCK:
sort logs.txt | uniq -d Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
sort logs.txt | uniq -d CODE_BLOCK:
sort logs.txt | uniq -d CODE_BLOCK:
sort logs.txt | uniq -u Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
sort logs.txt | uniq -u CODE_BLOCK:
sort logs.txt | uniq -u CODE_BLOCK:
grep error logs.txt | sort | uniq Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep error logs.txt | sort | uniq CODE_BLOCK:
grep error logs.txt | sort | uniq CODE_BLOCK:
grep error logs.txt | sort | uniq -c Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep error logs.txt | sort | uniq -c CODE_BLOCK:
grep error logs.txt | sort | uniq -c CODE_BLOCK:
grep "GET" access.log | awk '{print $1}' | sort | uniq -c Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep "GET" access.log | awk '{print $1}' | sort | uniq -c CODE_BLOCK:
grep "GET" access.log | awk '{print $1}' | sort | uniq -c COMMAND_BLOCK:
kubectl logs pod-name | grep error | sort | uniq -c Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
kubectl logs pod-name | grep error | sort | uniq -c COMMAND_BLOCK:
kubectl logs pod-name | grep error | sort | uniq -c CODE_BLOCK:
grep pattern file
grep -i pattern file
grep -v pattern file
grep -c pattern file sort file | uniq
sort file | uniq -c
sort file | uniq -d Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
grep pattern file
grep -i pattern file
grep -v pattern file
grep -c pattern file sort file | uniq
sort file | uniq -c
sort file | uniq -d CODE_BLOCK:
grep pattern file
grep -i pattern file
grep -v pattern file
grep -c pattern file sort file | uniq
sort file | uniq -c
sort file | uniq -d CODE_BLOCK:
echo $PATH Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin CODE_BLOCK:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin CODE_BLOCK:
ls Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
/usr/local/sbin/ls
/usr/local/bin/ls
/usr/sbin/ls
/usr/bin/ls ✅ found here Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
/usr/local/sbin/ls
/usr/local/bin/ls
/usr/sbin/ls
/usr/bin/ls ✅ found here CODE_BLOCK:
/usr/local/sbin/ls
/usr/local/bin/ls
/usr/sbin/ls
/usr/bin/ls ✅ found here CODE_BLOCK:
mkdir -p ~/path-lab/bin
cd ~/path-lab/bin Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
mkdir -p ~/path-lab/bin
cd ~/path-lab/bin CODE_BLOCK:
mkdir -p ~/path-lab/bin
cd ~/path-lab/bin COMMAND_BLOCK:
echo -e '#!/bin/bash\necho "Hello from custom command"' > hello
chmod +x hello Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
echo -e '#!/bin/bash\necho "Hello from custom command"' > hello
chmod +x hello COMMAND_BLOCK:
echo -e '#!/bin/bash\necho "Hello from custom command"' > hello
chmod +x hello CODE_BLOCK:
hello Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
~/path-lab/bin/hello Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
~/path-lab/bin/hello CODE_BLOCK:
~/path-lab/bin/hello CODE_BLOCK:
export PATH=$PATH:$HOME/path-lab/bin Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
export PATH=$PATH:$HOME/path-lab/bin CODE_BLOCK:
export PATH=$PATH:$HOME/path-lab/bin CODE_BLOCK:
hello Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
which ls Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
which hello Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
which hello CODE_BLOCK:
which hello COMMAND_BLOCK:
echo -e '#!/bin/bash\necho "Fake ls command"' > ls
chmod +x ls Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
echo -e '#!/bin/bash\necho "Fake ls command"' > ls
chmod +x ls COMMAND_BLOCK:
echo -e '#!/bin/bash\necho "Fake ls command"' > ls
chmod +x ls CODE_BLOCK:
ls Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
export PATH=$HOME/path-lab/bin:$PATH Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
export PATH=$HOME/path-lab/bin:$PATH CODE_BLOCK:
export PATH=$HOME/path-lab/bin:$PATH CODE_BLOCK:
ls Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
nano ~/.bashrc Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
nano ~/.bashrc CODE_BLOCK:
nano ~/.bashrc CODE_BLOCK:
export PATH=$PATH:$HOME/path-lab/bin Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
export PATH=$PATH:$HOME/path-lab/bin CODE_BLOCK:
export PATH=$PATH:$HOME/path-lab/bin CODE_BLOCK:
source ~/.bashrc Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
source ~/.bashrc CODE_BLOCK:
source ~/.bashrc CODE_BLOCK:
/etc/profile
/etc/environment Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
/etc/profile
/etc/environment CODE_BLOCK:
/etc/profile
/etc/environment CODE_BLOCK:
#!/bin/bash
aws s3 ls Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
#!/bin/bash
aws s3 ls CODE_BLOCK:
#!/bin/bash
aws s3 ls CODE_BLOCK:
which aws Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
/usr/bin/aws s3 ls Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
/usr/bin/aws s3 ls CODE_BLOCK:
/usr/bin/aws s3 ls COMMAND_BLOCK:
export PATH=/my/bin # WRONG Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
export PATH=/my/bin # WRONG COMMAND_BLOCK:
export PATH=/my/bin # WRONG CODE_BLOCK:
export PATH=$PATH:/my/bin Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
export PATH=$PATH:/my/bin CODE_BLOCK:
export PATH=$PATH:/my/bin CODE_BLOCK:
echo $PATH
export PATH=$PATH:/new/path
which command
source ~/.bashrc Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
echo $PATH
export PATH=$PATH:/new/path
which command
source ~/.bashrc CODE_BLOCK:
echo $PATH
export PATH=$PATH:/new/path
which command
source ~/.bashrc CODE_BLOCK:
NAME="devops"
echo $NAME Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
NAME="devops"
echo $NAME CODE_BLOCK:
NAME="devops"
echo $NAME COMMAND_BLOCK:
NAME = devops # wrong Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
NAME = devops # wrong COMMAND_BLOCK:
NAME = devops # wrong CODE_BLOCK:
MYVAR="local"
bash
echo $MYVAR Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
MYVAR="local"
bash
echo $MYVAR CODE_BLOCK:
MYVAR="local"
bash
echo $MYVAR CODE_BLOCK:
exit Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
export ENV="production"
echo $ENV Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
export ENV="production"
echo $ENV CODE_BLOCK:
export ENV="production"
echo $ENV CODE_BLOCK:
bash
echo $ENV
exit Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
bash
echo $ENV
exit CODE_BLOCK:
bash
echo $ENV
exit CODE_BLOCK:
set Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
env Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
printenv Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
TEMP=123
unset TEMP
echo $TEMP Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
TEMP=123
unset TEMP
echo $TEMP CODE_BLOCK:
TEMP=123
unset TEMP
echo $TEMP CODE_BLOCK:
readonly VERSION="1.0"
VERSION="2.0" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
readonly VERSION="1.0"
VERSION="2.0" CODE_BLOCK:
readonly VERSION="1.0"
VERSION="2.0" CODE_BLOCK:
DATE=$(date)
echo $DATE Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
DATE=$(date)
echo $DATE CODE_BLOCK:
DATE=$(date)
echo $DATE CODE_BLOCK:
DATE=`date` Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
DATE=`date` CODE_BLOCK:
DATE=`date` CODE_BLOCK:
echo ${APP:-nginx} Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
echo ${APP:-nginx} CODE_BLOCK:
echo ${APP:-nginx} CODE_BLOCK:
echo ${APP:=nginx} Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
echo ${APP:=nginx} CODE_BLOCK:
echo ${APP:=nginx} CODE_BLOCK:
echo ${APP:?APP is not set} Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
echo ${APP:?APP is not set} CODE_BLOCK:
echo ${APP:?APP is not set} CODE_BLOCK:
nano args.sh Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
nano args.sh CODE_BLOCK:
nano args.sh CODE_BLOCK:
#!/bin/bash
echo "Script: $0"
echo "First: $1"
echo "Second: $2"
echo "All: $@" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
#!/bin/bash
echo "Script: $0"
echo "First: $1"
echo "Second: $2"
echo "All: $@" CODE_BLOCK:
#!/bin/bash
echo "Script: $0"
echo "First: $1"
echo "Second: $2"
echo "All: $@" CODE_BLOCK:
chmod +x args.sh
./args.sh dev prod Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
chmod +x args.sh
./args.sh dev prod CODE_BLOCK:
chmod +x args.sh
./args.sh dev prod CODE_BLOCK:
ls
echo $? Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
echo 'export APP_ENV=prod' >> ~/.bashrc
source ~/.bashrc Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
echo 'export APP_ENV=prod' >> ~/.bashrc
source ~/.bashrc COMMAND_BLOCK:
echo 'export APP_ENV=prod' >> ~/.bashrc
source ~/.bashrc CODE_BLOCK:
#!/bin/bash
echo "Deploying to $APP_ENV" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
#!/bin/bash
echo "Deploying to $APP_ENV" CODE_BLOCK:
#!/bin/bash
echo "Deploying to $APP_ENV" CODE_BLOCK:
APP_ENV=stage ./script.sh Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
APP_ENV=stage ./script.sh CODE_BLOCK:
APP_ENV=stage ./script.sh CODE_BLOCK:
DB_HOST=localhost DB_PORT=5432 ./app.sh Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
DB_HOST=localhost DB_PORT=5432 ./app.sh CODE_BLOCK:
DB_HOST=localhost DB_PORT=5432 ./app.sh CODE_BLOCK:
nano .env Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
DB_USER=admin
DB_PASS=secret Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
DB_USER=admin
DB_PASS=secret CODE_BLOCK:
DB_USER=admin
DB_PASS=secret CODE_BLOCK:
export $(cat .env | xargs) Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
export $(cat .env | xargs) CODE_BLOCK:
export $(cat .env | xargs) CODE_BLOCK:
echo $DB_USER Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
echo $DB_USER CODE_BLOCK:
echo $DB_USER CODE_BLOCK:
echo $PATH
export PATH=$PATH:/custom/bin Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
echo $PATH
export PATH=$PATH:/custom/bin CODE_BLOCK:
echo $PATH
export PATH=$PATH:/custom/bin CODE_BLOCK:
export DOCKER_BUILDKIT=1 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
export DOCKER_BUILDKIT=1 CODE_BLOCK:
export DOCKER_BUILDKIT=1 CODE_BLOCK:
export KUBECONFIG=~/.kube/config Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
export KUBECONFIG=~/.kube/config CODE_BLOCK:
export KUBECONFIG=~/.kube/config CODE_BLOCK:
export AWS_ACCESS_KEY_ID=xxx
export AWS_SECRET_ACCESS_KEY=yyy
export AWS_DEFAULT_REGION=us-east-1 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
export AWS_ACCESS_KEY_ID=xxx
export AWS_SECRET_ACCESS_KEY=yyy
export AWS_DEFAULT_REGION=us-east-1 CODE_BLOCK:
export AWS_ACCESS_KEY_ID=xxx
export AWS_SECRET_ACCESS_KEY=yyy
export AWS_DEFAULT_REGION=us-east-1 CODE_BLOCK:
DB_PASS=admin123 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
DB_PASS=admin123 CODE_BLOCK:
DB_PASS=admin123 CODE_BLOCK:
VAR=value
export VAR=value
unset VAR
readonly VAR=value
VAR=$(command)
echo $?
env
set Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
VAR=value
export VAR=value
unset VAR
readonly VAR=value
VAR=$(command)
echo $?
env
set CODE_BLOCK:
VAR=value
export VAR=value
unset VAR
readonly VAR=value
VAR=$(command)
echo $?
env
set - * expands before command runs
- Matches filenames, not file content - Quotes prevent shell expansion - Delete all .log files except error.log
- List only files ending with numbers
- Copy only file1.txt and file2.txt using ONE command
- List everything except .txt files - ? is evaluated by find, not by the shell
- It matches one character only - file10.txt (because 10 = two characters) - ? → exactly 1 character
- * → any number of characters - ?? = exactly two characters - filea.txt (if exists) - Without quotes, shell may expand ? before find runs - ls → shell expands
- find → find evaluates pattern - Application debugging - tail → static output
- tail -f → live streaming - Create a file with 100 lines
- Print first 20 lines
- Print last 15 lines
- Show line number 50
- Follow file while adding new lines - characters / bytes - Count lines in /etc/passwd
- Count words in a file you create
- Count number of .log files
- Count how many users have /bin/bash
- Count errors in syslog - -m → characters - Which file is the largest?
- What size is bigfile.bin? - Create a file of 10MB
- Show its size using 4 different commands
- Find files larger than 1MB
- Sort files by size
- Check disk usage of a directory - ls → file size
- du → disk blocks used - Create report.txt using >
- Append 5 lines using >>
- Save ls /etc output
- Save errors separately
- Discard output using /dev/null - > overwrites - and one or more files at the same time - Save ls output and still see it
- Append 5 lines to a log file
- Write output to two files
- Save error logs and count them
- Write to a protected file using sudo - Find all error lines
- Count how many times each error appears
- Show unique log messages
- Exclude info messages
- Find warnings OR errors - grep error → matches
- grep -v error → excludes - Print your PATH
- Create a custom command
- Run it using full path
- Add directory to PATH
- Make change permanent
- Explain PATH order - Temporary → export
- Permanent → .bashrc - Exists only in current shell
- NOT available to child processes - Available to child processes
- Used heavily in DevOps tools - Create local variable and test scope
- Export env variable and test child shell
- Create script using positional parameters
- Use $? to check command success
- Load variables from .env
- Set permanent env variable
- Use inline env variable - set → shell variables
- env → environment variables
how-totutorialguidedev.toailinuxubuntuserverbashshellnetworknginxdockerkubernetesk8s