Linux on call · Chapter 1 of 30
Your first login
By the end of this chapter you can find out where you are and who you are on a Linux server, list a folder with its hidden names, read a file, and save a line of text in a file. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Finding your way
- 4 tasks
- Linux
- Free chapter
Free with a Google or GitHub sign-in, like the first 2 chapters of every lab.
Why you need this
Tapri's ordering app has moved off a laptop and onto a real Linux server, and since this morning that server is yours to look after. Arjun, the last admin, has moved to the Hyderabad office. He left a handover note in this folder, and the first thing in it that Ravi needs is the server's name: the hosting company asks for it on every support call.
There is no desktop here and no file manager to click through, only the terminal on the right. Bunty already had a look: he listed the folder, saw three names, none of them a note, and decided Arjun had forgotten. The note is there. Some names simply do not show up unless you ask for them.
The lesson
Where am I, and who am I?
pwd
/workspace/chapters/01-first-login
pwd (print working directory) prints the folder you are in. whoami prints the user you are logged in as:
whoami
student
On a server you share with other people, check both before you change anything: many accidents start with "I thought I was somewhere else".
Linux cares about capital letters. Type Pwd and the shell does not know it:
bash: Pwd: command not found
Listing a folder
ls lists the folder you are in, or the folder you name:
ls docs
menu.txt old-notes.txt
ls hides every name that starts with a dot. These "dotfiles" are usually settings. /etc/skel holds the settings every new user gets, and ls /etc/skel prints nothing at all, as if the folder were empty. Ask for everything:
ls -a /etc/skel
. .. .bash_logout .bashrc .profile
-a (all) shows them. . is the folder itself and .. is the folder above it. Press Next to see what each listing leaves out:
ls -l gives the long format (size, owner, date), and options combine: ls -la is both at once.
ls -l docs
total 8
-rw-r--r-- 1 student student 44 Oct 6 22:44 menu.txt
-rw-r--r-- 1 student student 33 Oct 6 22:44 old-notes.txt
The dates show when your chapter folder was built, so yours differ.
Reading a file
cat docs/menu.txt
Masala chai 40
Cutting chai 25
Bun maska 50
cat prints a whole file. It reads files, not folders:
cat docs
cat: docs: Is a directory
For a long file, less lets you scroll (press q to quit).
Paths
docs/menu.txt is a path: the folder docs, then the file inside it. The shell looks for it starting from the folder you are in. Stand in the /tmp folder instead, and the same command fails:
cat: docs/menu.txt: No such file or directory
The same file has another path that works from anywhere: /workspace/chapters/01-first-login/docs/menu.txt. The folder at the very top of the server is called the root, and its name is a single /. Every other folder lives somewhere inside it:
ls /
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr workspace
Compare the two paths to the menu: what changes when a path starts with a /? That is your interview question.
Saving a line in a file
echo prints the text you give it. Add > and a file name, and the text goes into that file instead of onto the screen:
echo "Masala chai" > special.txt
cat special.txt
Masala chai
> makes the file if it is missing, and empties it if it is there, so the next echo "Ginger chai" > special.txt leaves only Ginger chai:
Your turn
Your four tasks are at the top, and the terminal prints them too (lab tasks shows them again). The note is not where a plain ls looks, and answer.txt holds the server's name and nothing else. The last task is an interview warm-up: answer it in your own words. If you delete something by accident, lab reset builds the whole chapter folder again, so you would redo your other files too.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
Find where you are and who you are
Find out which folder you are in and which user you are.
1. Open the terminal below. It starts in the chapter folder.
2. Run pwd. It prints the folder you are in.
3. Run whoami. It prints your user name.
To pass: you ran pwd and whoami (or id) in the chapter folder. A command with a typing mistake does not count, so type it again.
- Task 2
Find Arjun's hidden note
Arjun left you a note, but it is hidden.
1. Run ls in the chapter folder. You do not see the note.
2. Run ls -a. The -a shows hidden names too. Hidden names start with a dot.
3. You now see one more folder. Look inside it.
4. Open NOTE.txt with cat. Give cat the path to the note: the folder name, a slash, then NOTE.txt.
To pass: you ran ls -a (or ls -la), and you opened NOTE.txt with cat (or less, head or tail), in the chapter folder.
- Task 3
Save the server's name in answer.txt
Save the server's name in a file.
1. Read Arjun's note again. Find the line that gives the server's name.
2. Save only that name in answer.txt, in the chapter folder. echo with > writes text into a file.
3. Run cat answer.txt to see what you saved.
To pass: answer.txt has the server's name, spelled exactly as in the note, and nothing else.
- Task 4 · interview question
Interview: what a path starting with / means
Interview question: what does a path that starts with / mean?
1. Write one sentence in your own words.
2. In it, say which folder such a path starts from. Use that folder's name.
3. Save the sentence in paths.txt, in the chapter folder.
To pass: paths.txt has your sentence, and it names the folder that every / path starts from.
What you will learn
- pwd and whoami: the folder you are in, and the user you are.
- ls and ls -a: list a folder, and see its hidden names too.
- cat: print a file on the screen.
- Paths and echo: how the shell finds a file from where you stand, and how to save a line of text in a file.
More in Finding your way
Build "Your first login" yourself
Tapri’s ordering app moves onto a Linux server, and the server is now yours to run. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
Free with a Google or GitHub sign-in, like the first 2 chapters of every lab.