Chapter 3: Linux Basic Commands
Friends, from this chapter onwards the terminal is your best friend. If the black screen feels scary at first, don't worry – practise every day for one week and you will become faster on the command line than with the mouse. First let's understand why Linux is so important in the cloud, and then we will type commands together. Our example in this chapter: managing the website files, users and packages on the EC2 server of a dairy brand like Amul (sample data, for practice).
मित्रांनो, या चॅप्टरपासून टर्मिनल तुमचा बेस्ट फ्रेंड आहे. सुरुवातीला काळी स्क्रीन भीतीदायक वाटली तर काळजी करू नका – एक आठवडा रोज प्रॅक्टिस केली की माउसपेक्षा कमांड लाइनवर तुम्ही जास्त फास्ट व्हाल. आधी Linux क्लाउडमध्ये इतकं इम्पॉर्टंट का ते समजून घेऊ, आणि मग कमांड्स एकत्र टाइप करू. या चॅप्टरमध्ये आपलं उदाहरण: Amul-style dairy (सॅम्पल डेटा, सरावासाठी) च्या EC2 सर्व्हरवर वेबसाइटच्या फाइल्स, यूजर्स आणि पॅकेजेस मॅनेज करायचे आहेत.
दोस्तों, इस चैप्टर से टर्मिनल आपका बेस्ट फ़्रेंड है. शुरू में काली स्क्रीन डरावनी लगे तो चिंता मत करो – एक हफ़्ता रोज़ प्रैक्टिस की तो माउस से ज़्यादा कमांड लाइन पर आप फ़ास्ट हो जाओगे. पहले समझते हैं कि Linux क्लाउड में इतना इम्पॉर्टेंट क्यों है, और फिर कमांड्स साथ में टाइप करेंगे. इस चैप्टर में हमारा उदाहरण: Amul-style dairy (सैंपल डेटा, सिर्फ़ अभ्यास के लिए) के EC2 सर्वर पर वेबसाइट की फ़ाइलें, यूज़र्स और पैकेजेस मैनेज करने हैं.
In this chapter
- The Linux file-system hierarchy
- Navigating with pwd, ls and cd
- Creating, copying, removing files
- Viewing files and following logs
- Permissions: chmod and chown
- Users, groups and sudo
- Package managers: yum and apt
- Processes, help and editors
Concepts in this chapter
- 3.1Why Linux?
- 3.2Navigation
- 3.3Working with files and directories
- 3.4Viewing files
- 3.5Permissions
- 3.6Users, groups and sudo
- 3.7Package managers
- 3.8Processes
- 3.9Getting help
- 3.10Text editors: nano and vim
Review and practice
Trace a command from the terminal to its result
Read all steps
- Terminal input
The terminal provides the interaction surface. Your shell receives the line you entered. Check the host and current directory before a command that changes files.
- Shell processing
The shell interprets quoting, expansions, pipes and redirection. It may run a builtin or locate an executable. A quoted space can remain part of one argument rather than splitting the filename.
- Program and kernel
A running program asks the kernel for services such as reading a file or starting a process. Permissions and the program’s effective identity affect which requests can succeed.
- Output and status
A command can write standard output, standard error and an exit status. A quiet command is not automatically successful. Inspect its status and verify the intended resulting file or process state.
Your first shift at a Linux help desk
Imagine the coordinator of a college library asks you to check one thing. Students were able to borrow books in the morning, but the reading-room report has stopped appearing. You have a Linux training machine and a folder of practice files. Nobody expects you to know the whole system. Your first job is to find the right machine, find the report, read a useful clue and explain it clearly. In this chapter we will do that with commands that you can try one at a time.
It helps to know the difference between the pieces on your screen. The terminal is the place where you see text and type. The shell is the program that reads what you type, works out which command and arguments you meant and starts the work. Bash is the shell used in these examples. Linux is the operating system underneath it. The package names and default tools you get depend on the Linux distribution, such as Ubuntu or Amazon Linux 2023. If you start a remote session over SSH, the terminal can still be on your laptop while the shell is running on the server.
There is one habit to practise from the first command. Before you press Enter, name the machine, your account and the location where the command will act. After it runs, ask yourself which observation changed. Use a read command first if you are unsure. When you change a file, verify the result by reading it back. This is how you turn a sequence copied from a lesson into a task you can repeat on your own.
A good lab lets you try things without putting anyone else's work at risk. Use a disposable Linux VM or the isolated practice machine provided by your trainer. The walkthrough below uses a uniquely named folder in your home directory. It needs no administrator permissions and uses fictional library data. You can follow the worked terminal output by reading even if you do not have a machine to use today. On a cloud VM, keep its separate instance and volume costs in mind and clean up only the training resources you created.
Check whose shell will run the command
Sometimes the prompt looks like student@lab01:~$. Here student is the account name, lab01 is the machine name and the ~ often displays the home directory. Prompts are configurable, so use commands to confirm them. The prompt symbol at the end is already printed by the shell. Copy the command after the symbol. If the lesson shows output beneath the command, read it as a result and leave it out when you type.
hostname
whoami
pwd
id
cat /etc/os-release
The first line reports the machine's hostname. It could be a friendly local name such as lab01 or a cloud-generated name. The second reports your effective username. The third prints the current working directory, which is the starting point for relative paths. The fourth shows your numeric user ID, group ID and groups. The last reads the Linux distribution information file. Look for the distribution name and version. On a training system these may say Ubuntu or Amazon Linux. Your commands and package instructions should fit what you actually see.
Suppose your laptop account and your server account have the same name. whoami alone will look right in both windows. The hostname and working directory give you two more clues. Try writing the three results on the same line in your notes. If you accidentally type a command into your laptop shell, compare that line before continuing. A familiar folder name by itself cannot reveal which computer stores it. When you switch between two machines, name the machine out loud before running a write command.
Think of the current directory as the folder the shell starts from when you provide a short name. It can change without changing your user or your machine. If you open another terminal, that new shell usually starts with its own working directory. If one tab is in the library lab and the other is in your home directory, a command using just report.txt refers to a different path in each tab. This is a common reason why two students type the same words yet see different results.
When reading instructions, separate the command's name from the values after it. In ls -l drafts, ls is the command. The -l part is an option that asks for a long listing. The drafts part is its operand, the thing to list. In cd drafts, the same word is a directory to enter. An option changes the way a command operates, while a path tells the command where it should act. Read both before you decide whether a command is suitable.
As a quick exercise, ask a classmate to say which machine they are in and which folder they are about to list. Then have them confirm using hostname and pwd. If the answers differ from the prompt, trust your checks and inspect the prompt or terminal choice before you do anything else. Try again after a new terminal session starts. You now have a reliable first move even on a server you have never seen.
Create a small workspace you can recognise
We want a folder for sample input, another for work in progress and another for the version we hand to the library coordinator. We will first create one unique parent folder. The variable lab will hold the path returned by mktemp. A variable gives a short name to an exact value so you can refer to the same path later. Keep this terminal session for the exercises. Another shell will not automatically have the same variable. Write the printed path in your notes in case you need to return later.
lab=$(mktemp -d "$HOME/library-linux.XXXXXXXX") &&
cd -- "$lab" &&
mkdir -- incoming drafts published &&
printf 'Workspace: %s\n' "$lab" &&
pwd &&
ls -la
Read the workspace output before moving on. It should be a path under your home directory with a suffix chosen by mktemp. If the first command fails or prints no usable path, stop and check that your home directory is writable. With a working parent folder, the cd command enters that exact path. The double quotes keep it together if any part contains a space. The -- ends options for these commands, so a following path will be read as an operand. The three directory names after mkdir request three children of the current directory. The double ampersand between commands means that Bash takes the next step only if the previous one succeeds.
The long listing should show drafts, incoming and published. It also shows ., meaning this directory, and .., meaning its parent. Read the first character in the long listing. A d identifies a directory. Later, the dash on an ordinary file will look different. Running ls -la is useful when you ask a classmate to reproduce your steps because it reveals both names and basic file details. Default colour and sorting can differ by setup, so use the names rather than the colour to distinguish the results.
An absolute path starts with / and describes a location from the root of that machine's filesystem. A relative path starts from the current working directory. Inside your lab parent, incoming names its incoming folder. Inside drafts, ../incoming names that same folder by moving up one level and down into a sibling. ./incoming means the incoming folder in the current directory. Try explaining these paths without looking at the prompt. If your description and the intended destination differ, print pwd and rebuild the path.
Use a picture when you are new to paths. Write the folder names as a small tree with your workspace at the top. Put a dot by the node where your shell is now. If you start in the parent and run cd drafts, move the dot down to drafts. If you run cd .., move it up. Now draw ../published from inside drafts and predict where it goes. The same tree works when you are moving files. A relative path can be correct from one node and wrong from another, so the dot belongs in your notes.
There are two useful readings of a path when links are involved. A symbolic link is a directory entry that points to another path. If a lab uses a link called current to a particular release folder, you may navigate using the shorter name. On Bash, pwd -P can show the physical working directory instead of the logical path through that link. Read both if you are unsure where a write will land. A link is helpful because it gives a stable name, and it is also why the displayed shortcut and underlying location can differ.
Try this before adding files. Start from the lab parent, enter drafts and run pwd and ls ../incoming. The first should end in /drafts. The second should run successfully and show no entries yet. This means the directory exists and is empty. Then try ls ../archive, a name we did not create. It should report an error. Comparing the two empty-looking situations teaches you to distinguish an empty listing from a missing path using the message and status.
Follow one report through its working copies
Now the library coordinator sends three sample lines for the morning. The first line names the two columns, and the next two tell us the desk name and the number of books returned. Keep the incoming copy so you can compare it with your work. Create a draft as a separate file. A draft lets you adjust the result without losing the input. This detail matters even if all three files are plain text and look almost the same in an editor.
cd -- "$lab"
printf '%s\n' 'Desk Returns' 'Ground 12' 'First 8' > 'incoming/Morning returns.txt'
cp -i -- 'incoming/Morning returns.txt' 'drafts/Morning returns.txt'
ls -l -- 'incoming/Morning returns.txt' 'drafts/Morning returns.txt'
cmp -- 'incoming/Morning returns.txt' 'drafts/Morning returns.txt'
In printf, the format says to print each argument as text followed by a newline. The shell sends that output into the file named after the greater-than sign. If you reuse that redirection on an existing file, it can replace the earlier contents. Check the destination before running it. The quotes around Morning returns.txt are significant. They keep the words in that filename as one path. Without the quotes, the shell could pass Morning and returns.txt as separate arguments.
Read the arguments in the copy command in order. The incoming path is the source. The drafts path is the destination. The -i option asks before overwriting a destination that exists. The copy can succeed quietly. The listing shows that both paths exist and gives their sizes, and cmp checks byte equality. When the two inputs match, cmp is normally silent and returns status zero. Read that status immediately with printf '%s\n' "$?" if you want to see it. Another command run in between would replace the status with its own result.
Try using a name you can read quickly in your case notes. Add a fourth line saying Total 20 to the draft, then inspect the incoming and draft files one after the other. Append only after confirming the draft path. If you choose to use an editor instead, open the draft and check its title bar before saving. The result you want is the input remaining at three lines and the draft gaining one. Write the count and the last line beside each file in your notes. This verifies the effect of the edit and makes the two versions easy to tell apart.
printf '%s\n' 'Total 20' >> 'drafts/Morning returns.txt'
wc -l -- 'incoming/Morning returns.txt' 'drafts/Morning returns.txt'
tail -n 1 -- 'drafts/Morning returns.txt'
cp -i -- 'drafts/Morning returns.txt' 'published/Morning returns.txt'
cmp -- 'drafts/Morning returns.txt' 'published/Morning returns.txt'
Notice that wc -l can show a total when you give it more than one file. Read the row for each path before you interpret the total at the end. You should see three newline characters in the input and four in the draft. The last draft line reads Total 20. Repeating the append would add another total, so check the draft before rerunning a write. If you accidentally append twice, rewrite a new draft from the known good input or edit just the extra line. Confirm both files again before publishing.
Moving and copying have different results in the file tree. A move within the same filesystem can rename a path or change the directory entry that leads to the file. Moving across filesystems can involve copying the data and then removing the source. A copy leaves a source and a destination. Here we want to keep the draft for review and publish a separate copy. If you had decided to rename the draft instead, you would verify that the old name was gone and the new name held the intended contents. Always say which of those outcomes you want before you choose the command.
For removing disposable files, start with an exact path you just verified. Imagine that a learner says “delete the old report” when there are copies in incoming, drafts and published. The sentence does not identify the target. Write it down as a full or verified relative path first. Ask whether anyone still needs the original. Use a harmless scratch copy when practising a deletion. The result is that the chosen directory entry disappears, and a normal terminal removal does not make a desktop recycle-bin copy. That is why the check before removal is part of the command, not something to postpone until later.
Read just enough of a file to find the clue
Reading a file is often the first useful action in support work. If the file has four lines, cat prints all four. For a long report, head shows the beginning and tail shows the end. Use the beginning when you need a column header or the end when a program writes new lines there. less lets you move through a longer text file and search inside it. Press q to leave the viewer. Its presence depends on the distribution and installed packages.
Now give yourself a specific question. Did the morning report include a total? Read the bottom line with tail -n 1 and match the expected text. If you need every line mentioning a desk, use a search designed for that pattern. A count is only helpful when you can explain what was counted. If a report adds a header or note, a line count includes those lines too. Read the original or a small sample first so that the number you report has a clear meaning.
Make a simple log in the lab. In this exercise a log is a text record of events in the order we wrote them. Applications can use different formats and can write into a service journal instead of a file. The sample below has a time, a level and a short message. If you later see an ERROR from the morning and the following message says a report was recreated, keep both pieces of evidence. They tell a story with a failure and a later result.
printf '%s\n' \
'09:00 INFO library check started' \
'09:05 ERROR report draft missing' \
'09:10 INFO report draft recreated' > 'drafts/training.log'
head -n 1 -- 'drafts/training.log'
tail -n 2 -- 'drafts/training.log'
grep -F -- 'ERROR' 'drafts/training.log'
The first command creates the fixture and supplies the three intended rows. The backslashes at the ends of command lines let Bash read the lines as one command. If copying multi-line commands is new to you, paste the whole block and wait for the normal prompt. The head output should show the starting line. tail should show the error and the later recreation. With -F, grep searches for literal text rather than treating its pattern as a regular expression. Here it prints the one error row.
Give the same search a word that is absent and check its result. GNU grep returns status one for no match. When the file name is wrong and this command cannot read the file, it prints an error and normally returns two. Those two cases should make you say different things to the coordinator. “I checked this log and found no matching warning” gives evidence. “I could not read that log” describes evidence you still need. A script that treats both as a successful zero result can miss a real problem.
One more thing to notice. The vertical bar in a command such as grep -F -- ERROR drafts/training.log | wc -l connects the normal output of the first command to the input of the second one. You should see one line counted. If the file could not be opened, the final command can still count zero lines because no matching output reached it. Do the two checks separately in this beginner lab. In a Bash script where an earlier command failure must fail the pipeline, learn to handle the component statuses or use pipefail deliberately.
When troubleshooting real logs, write the time and the source beside each line you copy. A line in an old file or in a different service's journal may look like today's error. Use a narrow time window and confirm you are reading the resource for this incident. A recent matching line is evidence of an event. The next question is whether it describes the current request or an earlier action. To answer that, reproduce a harmless lab failure at a known time and confirm the record matches it.
Read permissions before changing them
Think of the report taking three roles. You wrote it, so you need to edit it. A reviewer should read it, and people outside the exercise should have no need to see it. On Linux, ownership and permissions help enforce a design like that. A regular file has an owner and a group. Its usual permission display has three groups of letters, for the owner, members of the group when the group class applies, and everyone else. Read the names printed after the permission string as well. The owner and group decide which column matters to the acting user.
Start by reading a line, such as -rw-r-----. The first dash tells you this is an ordinary file. The next three positions show read and write for its owner. The group positions show read only. The last three positions are dashes. Each dash in a permission position means that particular right is absent from the displayed mode. This is the meaning of mode 640. The numbers come from four for read, two for write and one for execute. For the owner, four and two add to six. The group gets four and others get zero.
A directory uses the same letters with a different practical meaning. Directory read gives you the ability to list names. Execute lets you traverse the directory to reach a named item, subject to the other permission checks. Write, together with traversal, can allow people to change entries in that folder. If a person says a file is readable and they still receive “Permission denied,” follow each directory from the starting point. A permission on a file can be right while one of its parent directories prevents the person from reaching it.
Use an ordinary account and your own lab copies to see the difference. First list the published report. Change it to the mode shown below and list it again. The write command changes permissions on the single path you name. Your output should show that you retain ownership. The permissions now allow the owner to read and write and the group to read, and ordinary mode bits grant other users no access. A cloud account with only one student user can verify the display without needing to create extra users.
chmod -- 640 'published/Morning returns.txt'
ls -l -- 'published/Morning returns.txt'
id
If an administrator wants a separate review group, that is a proposal about identities and folder access in addition to the report's own mode. Ask the administrator which group should own the shared location, and check the expected reader's active groups with id in their session. A newly assigned group can take effect in a new login while an earlier process still has its original groups. Compare the identity with the directory and file permissions instead of assuming that anyone who can log in has the same access.
When you use the symbolic form, read it as a smaller change. For a script you own, chmod u+x says add execute to the owner class. The characters after the option spell out who and which right. Using a numeric value sets complete mode bits for the three classes. That can be right when you know exactly what the file should become. When you want just one change and need the other bits to stay as they are, the symbolic form makes the intent clearer in the terminal history.
A habit worth keeping is to test a real outcome after a permission change. If your account is the owner, try reading your sample file to prove your own access still works. In a lab with a separate reviewer, identify the account, confirm the intended directory path and check that they can read the sample but cannot edit it. This is a more direct test than reporting that the permission command gave no error. The file mode, the user's identity, the permissions on parent directories and any other applicable access rules can all affect the actual result.
Connect the requested task to the person allowed to do it
In our library the coordinator asks for a report, a reader checks the totals and a machine administrator maintains the training server. Give these people separate jobs before you talk about commands. A Linux account gives a process an identity. Groups can give several people shared access through the appropriate permission rules. The root account has broad administrative authority. A program running as root may be able to make changes across the machine, so use a dedicated lab for experiments that require it.
sudo asks the system's configured policy whether the current user can run a specific command as another user, often root. That makes a difference when the library coordinator can read the report but only a service operator can restart a background program. Before attempting any privileged command, state which operation needs extra authority and check whether a normal read command already answers your question. If sudo is allowed on your own lab machine, sudo -l can list the relevant rules. Nothing in the report exercise requires that you elevate or change system accounts.
Use a pretend access request to understand why permissions have a scope. Suppose the operator can read status for the report service and the administrator can update packages. A request to update packages from the operator is a different operation. An account can have one permission and lack another without anything being broken. Ask for the smallest action a person needs. When you troubleshoot a denial, write down the caller, action, target and expected policy. It is often easier to solve once you can describe the particular request.
There is another practical detail. The shell still processes redirection before a command runs. If someone writes a harmless example such as sudo printf ... > protected-file, the shell setting up that output may have insufficient permission even if the command would run with elevated rights. Learn to identify which step tried to open the file. In a real administrative task, use the approved editing or configuration method and verify the exact destination. Do not change a system setting merely to make an example work.
For your notes, practise an answer to a classmate who thinks changing the whole folder to world writable will fix their report. Ask which account needs which operation. Find the entry and its parent directory with a listing and the account's relevant group with id. Try a focused change in a disposable folder and check the intended read or write. Stop when the required task works, and record the permission that made the difference. Broad access to every user makes the issue harder to diagnose and can expose data to people without a need for it.
Find the right tool on the machine you have
A fresh server may be missing a command that your trainer's machine already has. Begin by identifying the operating system and looking up the command. command -v asks the current shell how it would find a particular name. On Bash, type can also tell whether it is a shell builtin, alias, function or executable file. The command cd is a good example of a builtin because it must change the current shell's working directory. A separate program cannot move its parent shell to a new folder.
When you ask for help, give yourself one question. If you want the flag that asks before overwriting a copy, begin with the installed command's help or its manual entry. In GNU versions of many of the tools used here, --help displays an option summary. A shell builtin can have its own Bash help, such as help cd. When manual pages are installed, man cp provides a fuller description. Use the manual's synopsis to identify operands and optional flags. Try the smallest harmless example in the scratch folder and compare with its description.
A package is a prepared unit that installs files such as commands, examples and documentation. A repository publishes packages and information about their versions. The package manager downloads suitable packages and their dependencies, which are other pieces the installed tool needs to run. Use the Linux distribution information to choose the tool. Amazon Linux 2023 defaults to dnf. Ubuntu and Debian normally use apt and related tools. Read the specific distribution's docs when a package name or option differs.
Try a read-only search before asking for an installation. Pick the branch that matches your Linux distribution and inspect its output. Package search may rely on repository metadata and configured sources. If the metadata is unavailable or old, read the error or output before assuming the package does not exist. The lab does not require an installation. The main observation is that two distributions can provide a similar tool using different package-management commands.
command -v less
cat /etc/os-release
# On Amazon Linux 2023, when DNF is available:
dnf search less
# On an Ubuntu or Debian system, when APT is available:
apt-cache search '^less$'
Refreshing a package index and upgrading installed packages are separate actions. A refreshed list tells the package manager what versions it could install. An upgrade changes some of the installed software based on the repository information and dependency rules. Read the plan for changes in a lab before accepting them, especially if it adds or removes packages. For a report-reading task, installing one small viewer can be enough. Choosing not to install anything is also reasonable if the tools already on the host can answer the question.
When you report a missing command, include the exact text and the machine's distribution. “The guide says run this and mine gives command not found” is a useful start. That message says the shell did not locate a runnable command by the supplied name. Check spelling and the current search path, and whether the expected package is installed on this machine. If there are two different versions, check which one the shell resolves. Taking those measurements before an installation can save time and shows you know which part of the system made the decision.
Distinguish a running process from its finished work
On the same training machine, imagine a script is waiting to create the next report. A program is the instructions that can run. A process is a running instance with an identity and state. The process ID identifies that instance while it exists. Two runs of the same program can have different IDs. If you wrote down an ID earlier, check the process and command associated with it again before acting. IDs can be reused after processes finish.
Start a small waiting process in the lab instead of trying to stop a real service. The ampersand starts the command in the background so your shell can accept another command. $! gives you the process ID associated with this last background job. Save it before starting any others. The process listing asks for that exact ID and prints the fields shown. wait lets the shell wait for completion and collect the job's exit result. If the waiting process is still running, this waits briefly. It needs no administrator permission.
sleep 12 &
demo_pid=$!
printf 'Lab process: %s\n' "$demo_pid"
ps -p "$demo_pid" -o pid,ppid,stat,comm
wait "$demo_pid"
printf 'Finished with status %s\n' "$?"
In the sample reading, PID should agree with the number you saved. PPID identifies its parent process, usually the shell that launched it in this exercise. STAT describes the process state. A sleep job is often waiting and can show a state beginning with S. COMMAND or a similar heading names the program. If you ran the check after twelve seconds elapsed, the row might be gone because the process finished. The exit-status comparison is a useful part of the exercise. A normal finish can return zero even though the command printed no normal result.
On a service host, the question “is the application running?” can be answered in more than one useful way. A process check shows a running copy. If systemd supervises a service, systemctl status can show the unit's current state and recent context. Its journal can record earlier start failures. To test whether a reader can actually get today's report, perform the intended safe read, or ask the training app for its normal response. A process listing proves that the observed process exists at that moment and shows its state. The report read gives a different observation about whether it did the right work.
Practise listening to the problem before acting on a process. If a classmate says a program feels stuck, ask how long it usually takes and whether it has printed progress. Record the exact process identifier and command before considering any action. For a harmless job you started, first wait for it to finish. In a later troubleshooting exercise you may need a graceful stop. A forceful stop can skip the program's cleanup, so it belongs after you understand its impact and the process is yours to stop. In a beginner exercise, you can learn what a process listing means without using termination at all.
Make one edit and prove that it landed
An editor lets you update a file without reconstructing every line in a shell command. Open a new copy of the draft and change the desk total as a test. In nano, read the key hints at the bottom. The caret in a hint such as ^O means hold Ctrl and press the named key. When you write the file, read the proposed filename before confirming it. Then exit and inspect the exact changed line in the terminal. The filename shown during save matters just as much as the text you typed.
Vim has modes. When a new file opens, Normal mode interprets keys as commands and motions. Use i to insert text. When you finish editing, press Esc to return to Normal mode. Type :w and press Enter to write changes to disk, then use :q to quit. If you made a practice edit and want to abandon it, read the filename first and use :q! only when you intend to leave without saving. Try saving and abandoning edits on two separate disposable copies so you can see the expected result from each action.
Keep the draft and the published file separate while you practise. Save the draft, then use diff -u on the two versions. The header shows which file is first and which is second. Lines beginning with a minus belonged to the first file. Lines beginning with a plus belong to the second file. The comparison need not be dramatic. If exactly one intended line changed, you can point to it. If unrelated changes appear, inspect which file was opened and restore the lab draft you meant to edit.
Publishing in this exercise simply means making the verified draft available at the published path. Check that the draft contains the intended total and that the other lines still match the source. Copy it over only when it is right and the existing published copy is yours to replace. Confirm the destination by reading it with the full relative path and comparing it with the draft. If a file is for an application rather than a human report, look for an application-specific check that reads the file and explains an invalid setting before you reload anything.
Hand back a clear answer about the missing report
Return to our opening request. The coordinator wants to know why the report has not appeared. Start by saying which machine and location you checked. Verify the expected name under published. If the name is absent, look at the input and draft locations using the same workspace. Find whether a relevant error appears in the sample log and whether a later line says the draft was recreated. The published folder, the log and the contents of the draft are three different observations. Put them together before deciding the next action.
Suppose the published file is absent and the draft has four lines, including the total. You also find that the incoming sample is readable and unchanged. That narrows the missing step to publication in this exercise. Write a short note before copying. “The draft has the expected entries and total. The published path does not exist yet. I will copy the draft there and verify it.” This clear note makes the action easy for another learner to check. If the published path already exists with wrong content, inspect the two versions and ask who owns that copy before replacing it.
Next, write an alternative explanation for another plausible failure. The training account gets an error when it tries to enter drafts. In that case the appropriate next step is to check the path, the current account and directory access. A message about a missing path points to a different investigation from a permission denial. If the path is not where you expected, print the working directory and reconstruct the absolute path from your notes. If it does exist but you lack access, identify the owner and requested operation before adjusting anything.
Use your observations to choose the smallest change. If the missing report had never been calculated, rebuild the disposable draft from the incoming fixture. If the draft is valid but the publish step is missing, copy it and check the destination. If the error was from an earlier run and today's output is already right, document the evidence. Each case has its own next action from the same set of basic commands. A safe workflow changes one condition at a time so you can tell which action made the result different.
A useful final note gives the time, machine, path and evidence without copying unrelated file contents. For this lab, the note might say that the published sample exists and contains four lines, ending with Total 20. Its contents match the verified draft. The incoming file still has the original three lines. The note can also mention the earlier missing-draft log entry and the later recreation. A colleague can repeat these checks and tell whether they are looking at the same file on the same host.
Clean up after the last check. First leave the workspace and confirm you are back in your home directory. Show the saved path with printf. Compare it with the path you wrote down at the beginning. If you want to retain the exercise, keep the uniquely named folder as a record. If you choose to remove it, inspect that exact disposable folder and use a file manager or remove its known lab files individually. Check the listing afterward. An empty directory can be removed with rmdir, which refuses to remove a nonempty directory. This makes it good for a cleanup you can monitor a step at a time.
Explain your reasoning in an interview
The same command works in one terminal and fails in another. What would you check?
I would compare the machines, accounts and working directories first. A relative path belongs to the shell that receives it. Then I would check which command each shell is using, whether the input exists at the resolved path and what the error actually says. Finally I would run the smallest read-only check that proves the difference. This explains what changed between the two terminals instead of assuming the utility is broken.
Why can a successful copy show no message, and how do you verify it?
Many ordinary tools stay quiet when the requested operation completes. I would check the exit result at the right time and list the intended destination. If the copy should match exactly, I would compare the bytes of the original and the destination, and inspect the access mode when that matters. For a file served to a reader, I would also verify that the account which needs it can read the correct path. Each check proves a specific part of success.
What is your first move if you see “Permission denied”?
I would identify the account, action and path. Then I would read the file's owner, group and permissions and check the relevant parent directories. If the policy depends on group access, I would use the groups from the active session. I would compare with the intended design before asking for additional permission. For a lab change, after adjusting the intended permission, I would repeat the same action as the intended user and confirm the result.
Why would you inspect both a process status and the report?
The process status tells me that a program is present and what state it is in. It does not establish the report's contents or prove that the last scheduled work completed. I would use the recorded time, the expected output path and a small content check to verify the work. If there is a service log, I would narrow its evidence to the intended run. This connects the user's result to the process instead of treating a running status as a complete diagnosis.
Try the next report on your own
In the same disposable workspace, make a second fictional input for the afternoon. Choose two desk counts, five for Ground and seven for First. Write down the expected total before you touch a command. Use a filename with a space and keep the incoming file separate. First create the three input lines. Copy them to drafts and append the correct total. Verify the draft's four lines and publish a copy with the intended name. Keep enough terminal output in your notes for a classmate to reproduce your result.
Give yourself a negative case too. Ask a classmate to move only a disposable copy of today's draft to a known review folder while you look away. Use the current directory and its listings to explain why the old name is missing. Trace the review folder and compare the file with the incoming copy. Finish by choosing whether the draft should be returned to its old location or kept in review. The lesson is to make your reasoning visible, including the exact name, location and contents you used in the decision.
Score your own exercise against what you can reproduce. One point goes to identifying the machine and workspace before any change. One goes to keeping the source's original content. Another goes to the right total and line count in the destination. One more goes to explaining the negative case using the error and a second observation. The last point goes to a cleanup or documented choice to keep the workspace. Retry from a new scratch folder if a stage depends on values or files you cannot explain.
Check your understanding
You are standing in drafts below the lab parent. Which path reaches its sibling folder, incoming? Choose between incoming, ../incoming and /incoming before opening the result.
Answer and reasoning
Use ../incoming. The first component moves from drafts to the lab parent, and the second enters the sibling. The short name by itself would refer to a child of drafts. The leading slash would start at the machine's filesystem root.
The draft has the correct count and the incoming file should stay unchanged. Which operation publishes a separate copy: move the incoming file, append to the published path blindly, or copy the verified draft to the checked destination?
Answer and reasoning
Copy the verified draft to the checked destination. Evidence of success includes both the draft still being present and the published output matching it. Verify whether the destination already exists and whether you should replace it before entering the command.
One log search returns status one on a readable file. Another returns an input error. Which result means the term was absent from the file that was actually searched?
Answer and reasoning
The first. GNU grep uses one for no match. A read error means the search did not establish the answer for that input. Compare both the log output and the status before reporting a result to a colleague.
Revision cards
Name the active context
Use hostname, whoami and pwd together. The machine, user and directory can change independently. Confirm the context before a write and repeat it when switching sessions.
Keep the source and verify the destination
Read the source and destination paths in order. After making a draft, compare it with the input before changing it and compare it with the intended publication afterward.
Read a file's purpose before its output
Use the beginning for headers, the end for recent entries, and a focused search for a term. Record which file and time produced the clue.
Find the smallest change that helps
Measure the state before changing it, check your target and permissions, make one reversible lab change and repeat the same observation.
Official references
Practice Tasks
Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.
About this scenarioDublin Fitness Club is a fitness business in Dublin. Siobhan Murphy looks after its IT and cloud work. They count money in EUR and run their AWS resources in the eu-west-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.
0 / 12
Easy List all files with details
Hidden files (like .env) and file sizes or owners only show with the right options.
Show a long listing of every file, including hidden ones, in /var/www/dublinfit.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Create nested folders in one go
Projects need a clean folder tree. Making all levels in one command saves time and avoids errors.
Create the folder /srv/dublinfit/reports/2026 for Dublin Fitness Club. The parent folders do not exist yet, so create them too.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Show where you are
Before you copy or delete anything, you must know which folder you are in.
Siobhan Murphy logged in to the Dublin Fitness Club server and is not sure which folder the terminal is in. Print the current folder path.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Read a config file
Reading a file on the screen is the quickest way to check its settings.
Print the whole file /etc/dublinfit/app.conf on the screen.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Create an empty file
Some apps need a file to exist before they can write to it.
Create an empty file named orders-eur.csv in the current folder.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Copy a folder with everything inside
A plain copy skips folders. You need the recursive option to copy a whole tree.
Copy the folder site to a new folder named site-backup (both in the current folder).
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Rename a file
In Linux, renaming is the same as moving a file to a new name.
Rename the file report.txt to report-dublin.txt.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Go into the logs folder
Moving into a folder makes the next commands shorter.
Move into the folder /var/log/dublinfit.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy List Availability Zones
Spreading servers across AZs keeps you up if one data centre fails.
List the Availability Zones in eu-west-1.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy List your EC2 instances
Before changing anything, see what is running and in which state.
Show details of all EC2 instances of Dublin Fitness Club in eu-west-1.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy List all Regions
Choose a Region close to your users for low delay and the right laws.
List the AWS Regions available to your account.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Delete an old folder
Old build folders waste disk. rm needs the recursive option for folders, and force skips the questions.
Delete the folder old-build and everything inside it without being asked to confirm each file.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.