Write and read files फ़ाइल लिखें और पढ़ें
Lesson 4 of 12 · about 12 minutes · echo, > to write, >> to add a line, cat to read.
⚡ 0 XP
Step 1 of 2
echo, > and >>
echo "hello" prints text. Add an arrow and the text goes into a file instead:
echo "Masala chai ₹10" > menu.txt — one arrow writes: it creates the file, or wipes it and starts fresh.echo "Ginger chai ₹15" >> menu.txt — two arrows add: a new line at the end, keeping what was there.cat menu.txt shows what is inside a file.
Careful: a single > on an existing file throws away its old text. When in doubt, use >>.
Exampleecho "Poha ₹20" > tiffin.txt
echo "Upma ₹25" >> tiffin.txt
cat tiffin.txt
🎯 Challenge: Write the chai menu +15 XP
In your home folder, create menu.txt with exactly two lines:
Masala chai ₹10Ginger chai ₹15
Write the first line with >, add the second with >>, then show the file with cat menu.txt.
Try twice to unlock the solution (0/2)
terminalCtrl ⏎
Files · ~ = /home/asha
Your home folder is empty.
Git timeline
No git repository yet. Start with git init.
Checklist
Press Run to check your code.
Lesson notes (text version)
1. echo, > and >>
echo "hello" prints text. Add an arrow and the text goes into a file instead:
echo "Masala chai ₹10" > menu.txt — one arrow writes: it creates the file, or wipes it and starts fresh.echo "Ginger chai ₹15" >> menu.txt — two arrows add: a new line at the end, keeping what was there.cat menu.txt shows what is inside a file.
Careful: a single > on an existing file throws away its old text. When in doubt, use >>.
echo "Poha ₹20" > tiffin.txt
echo "Upma ₹25" >> tiffin.txt
cat tiffin.txt
Challenge: Write the chai menu
In your home folder, create menu.txt with exactly two lines:
Masala chai ₹10Ginger chai ₹15
Write the first line with >, add the second with >>, then show the file with cat menu.txt.
2. Overwrite on purpose
Sometimes wiping a file is what you want — like changing yesterday's notice board. One > replaces everything; then >> adds more lines below.
Real developers use this all the time to create small config and note files straight from the terminal.
Challenge: Update the notice board
notice.txt still says "Closed today". Make it contain exactly these two lines:
Open 7am to 9pmDiwali special: kesar chai
The old text must be gone. Check with cat notice.txt.