Unit 2 subjective questions System Utilities and Basic Commands
CSE105 — Creative Engineering Workshop 20 questions with model answers. Write yours first, then compare.
-
Question 1 of 20
Explain the general structure of a Linux command. Describe each component with a suitable example.
Model answer
A Linux command follows a well-defined syntax that the shell parses before execution.
General Syntax:
command [options] [arguments]
- Command: The name of the program or utility to be executed (e.g.,
ls,cat,date). - Options (Flags/Switches): Modify the behaviour of the command. They usually begin with a hyphen
-(short form) or double hyphen--(long form). Example:-l,--all. - Arguments: The objects or data on which the command operates, such as filenames, directories, or text.
Example:
ls -l /home/user
ls→ command-l→ option (long listing format)/home/user→ argument (directory to list)
Key points:
- Commands are case-sensitive in Linux.
- Multiple options can be combined:
ls -la. - White space separates the command, options, and arguments.
- The shell interprets and passes these tokens to the program.
- Command: The name of the program or utility to be executed (e.g.,
-
Question 2 of 20
Describe the
calcommand. Explain its important options with examples and outputs.Model answer
The
calcommand displays a calendar in the terminal.Syntax:
cal [options] [[month] year]
Common usages:
cal→ Displays the calendar of the current month.cal 2026→ Displays the calendar for the entire year 2026.cal 9 2026→ Displays September 2026.cal -3→ Displays previous, current, and next month.cal -y→ Displays the calendar for the whole current year.cal -j→ Displays the Julian calendar (day of the year, 1–366).
Example:
$ cal 9 2026
September 2026
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30Key points:
- The current date is often highlighted.
- Useful for quick reference without a GUI.
- Month value ranges from 1 to 12.
-
Question 3 of 20
Explain the
datecommand in detail. How can date be displayed in custom formats using format specifiers?Model answer
The
datecommand displays or sets the system date and time.Syntax:
date [options] [+format]
Basic usage:
date→ Shows current date and time, e.g.Fri Sep 25 22:26:57 UTC 2026.
Format Specifiers (prefixed with
+):%d→ Day of month (01–31)%m→ Month number (01–12)%Y→ Four-digit year%y→ Two-digit year%H→ Hour (00–23)%M→ Minute (00–59)%S→ Second (00–59)%A→ Full weekday name%B→ Full month name%j→ Day of the year%T→ Time in HH:MM:SS
Examples:
$ date +"%d-%m-%Y"
25-09-2026$ date +"%A, %B %d"
Friday, September 25Setting the date (requires superuser):
sudo date -s "2026-09-25 10:00:00"
Key points:
- Only root can change the system date.
- Format strings allow flexible output for scripts and logs.
-
Question 4 of 20
What is the purpose of the
echocommand? Explain its escape sequences and important options.Model answer
The
echocommand displays a line of text or the value of a variable on the standard output.Syntax:
echo [options] [string]
Common Options:
-n→ Does not output the trailing newline.-e→ Enables interpretation of backslash escape sequences.-E→ Disables escape sequence interpretation (default).
Escape Sequences (used with
-e):\n→ New line\t→ Horizontal tab\\→ Backslash\a→ Alert (bell)\b→ Backspace\c→ Suppress trailing newline
Examples:
$ echo "Hello World"
Hello World$ echo -e "Name:\tKiro\nRole:\tAI"
Name: Kiro
Role: AI$ echo -n "No newline"
Displaying variables:
$ name="Linux"
$ echo "Value is $name"
Value is LinuxKey points:
- Widely used in shell scripts for messages and debugging.
- Behaviour of
-emay differ between shells.
-
Question 5 of 20
Distinguish between the
echoandprintfcommands. Explain whyprintfis preferred for formatted output.Model answer
Both
echoandprintfsend output to the terminal, but they differ in flexibility and formatting control.Feature echoprintfPurpose Simple text display Formatted output Newline Adds newline automatically Does not add newline automatically Format specifiers Not supported Supports %s,%d,%f, etc.Portability Behaviour varies across shells Consistent, C-like behaviour Escape sequences Needs -eoptionInterprets by default printfSyntax:printf "format" [arguments]
Format Specifiers:
%s→ String%d→ Integer%f→ Floating point number%c→ Character
Examples:
$ printf "Name: %s, Age: %d\n" "Kiro" 5
Name: Kiro, Age: 5$ printf "%.2f\n" 3.14159
3.14Why
printfis preferred:- Precise control over width, precision, and alignment.
- Consistent, predictable behaviour across systems.
- Ideal for generating tabular or formatted reports in scripts.
-
-
Question 6 of 20
Explain the
bccommand as a command-line calculator. Demonstrate arithmetic operations, scale, and use in scripts.Model answer
The
bc(Basic Calculator) command is an arbitrary-precision calculator language that supports interactive and scripted calculations, including floating-point arithmetic.Interactive Mode:
$ bc
5 + 3
8
quitSetting precision with
scale:- The
scalevariable controls the number of decimal places.
$ bc
scale=2
10 / 3
3.33Using with a pipe (non-interactive):
$ echo "scale=4; 22/7" | bc
3.1428Mathematical library (
-loption):Enables standard math functions with default scale 20.
$ echo "sqrt(2)" | bc -l
1.41421356237309504880Operators supported:
- Arithmetic:
+,-,*,/,%,^ - Relational and logical operators
Example in a script:
result=$(echo "scale=2; 15.5 * 2" | bc)
echo "Result = $result"Key points:
- Unlike
expr,bchandles floating-point numbers. - Supports variables, loops, and functions.
- The
-
Question 7 of 20
Explain the
exprcommand with examples. What are its limitations compared tobc?Model answer
The
exprcommand evaluates expressions and prints the result. It is mainly used for integer arithmetic and string operations in shell scripts.Syntax:
expr expression
Arithmetic Examples:
$ expr 5 + 3
8$ expr 10 - 4
6$ expr 6 * 2
12$ expr 20 / 3
6Note: The multiplication operator
*must be escaped as\*to prevent shell globbing.String Operations:
$ expr length "Linux"
5$ expr substr "Creative" 1 4
CreaLimitations compared to
bc:- Only integer arithmetic — no floating-point support.
- Requires careful escaping of operators like
*. - Every operand and operator must be space-separated.
- Less powerful;
bcsupports precision, functions, and loops.
Key points:
- Useful for simple counters and integer math in scripts.
- Returns exit status based on the result value.
-
Question 8 of 20
Describe the
scriptcommand. How is it used to record a terminal session? Explain with an example.Model answer
The
scriptcommand makes a typescript (a recording) of everything displayed on the terminal, including commands typed and their output. It is useful for documentation, tutorials, and audit trails.Syntax:
script [options] [filename]
- If no filename is given, output is saved in a file named
typescriptby default.
Workflow:
$ script session.log
Script started, file is session.log
$ date
$ whoami
$ exit
Script done, file is session.log- Type
exitor pressCtrl+Dto stop recording.
Useful Options:
-a→ Append to an existing file instead of overwriting.-t→ Output timing data.-c command→ Run a single command and record it.
Example of appending:
script -a session.log
Key points:
- Captures the entire interactive session.
- The recorded file can be viewed with
cator a text editor. - Helpful for reproducing steps or teaching.
- If no filename is given, output is saved in a file named
-
Question 9 of 20
Explain the
passwdcommand. Describe its role in user authentication and important options.Model answer
The
passwdcommand is used to change a user's password and manage password-related properties.Syntax:
passwd [options] [username]
Basic usage:
passwd→ Changes the password of the current user. It prompts for the current password, then the new password twice.sudo passwd username→ Root changes another user's password (no current password needed).
Important Options:
-l→ Locks the user account.-u→ Unlocks the account.-d→ Deletes the password (makes it empty).-e→ Expires the password, forcing change at next login.-S→ Displays password status information.
Example:
$ passwd
Changing password for user.
Current password:
New password:
Retype new password:
passwd: password updated successfullyKey points:
- Passwords are stored in encrypted form in
/etc/shadow. - A normal user can change only their own password.
- Only root can modify other users' passwords or lock accounts.
-
Question 10 of 20
Distinguish between the
who,whoami, andwcommands. Explain the output fields ofwho.Model answer
These commands provide information about users logged into the system.
Command Purpose whoLists all users currently logged in whoamiDisplays the effective username of the current user wShows logged-in users and what they are doing whocommand output fields:$ who
user1 tty1 2026-09-25 09:15
user2 pts/0 2026-09-25 10:02 (192.168.1.5)- Username → Name of the logged-in user.
- Terminal (tty/pts) → The terminal line used.
- Login date & time → When the session started.
- Host/IP (in parentheses) → Remote host for network logins.
whoamiexample:$ whoami
user1- Equivalent to
id -un.
Key points:
whoreports all users;whoamireports only you.- Useful options for
who:-H(headers),-b(last boot time),-r(run level).
-
Question 11 of 20
Explain the
unamecommand and its various options. What information doesuname -aprovide?Model answer
The
uname(Unix name) command prints system information about the operating system and hardware.Syntax:
uname [options]
Options:
-s→ Kernel name (default output), e.g.Linux.-n→ Network node hostname.-r→ Kernel release version.-v→ Kernel version (build info).-m→ Machine hardware name (architecture), e.g.x86_64.-p→ Processor type.-i→ Hardware platform.-o→ Operating system name.-a→ All available information combined.
uname -aexample:$ uname -a
Linux myhost 5.15.0-73-generic #80-Ubuntu SMP x86_64 GNU/LinuxThe output includes, in order:
- Kernel name (
Linux) - Hostname (
myhost) - Kernel release (
5.15.0-73-generic) - Kernel version (build date/details)
- Machine architecture (
x86_64) - Operating system (
GNU/Linux)
Key points:
- Quick way to identify kernel and architecture.
- Frequently used in scripts to detect the platform.
-
Question 12 of 20
Explain the
uptimecommand in detail. Interpret the meaning of the load average values it displays.Model answer
The
uptimecommand shows how long the system has been running along with current load information.Syntax:
uptime [options]
Sample Output:
$ uptime
22:26:57 up 5 days, 3:14, 2 users, load average: 0.15, 0.20, 0.10Fields explained:
- Current time →
22:26:57 - Up time → How long the system has been running (
5 days, 3:14). - Number of users → Users currently logged in (
2 users). - Load average → Three numbers:
0.15, 0.20, 0.10.
Load Average interpretation:
- The three values represent the average system load over the last 1, 5, and 15 minutes.
- Load is the average number of processes waiting for or using the CPU.
- On a single-core system:
1.00means the CPU is fully utilised.< 1.00means idle capacity.> 1.00means processes are waiting (overloaded).
- For an -core system, a load of indicates full utilisation.
Options:
-p→ Pretty format of uptime only.-s→ Shows the time since the system booted.
Key points:
- Useful for monitoring system health and performance trends.
- Current time →
-
Question 13 of 20
What is a terminal in Linux? Explain the
ttycommand and the difference betweenttyandpts.Model answer
A terminal is an interface that allows users to interact with the operating system by entering commands and viewing text output.
ttycommand:The
ttycommand prints the file name of the terminal connected to standard input.Syntax:
tty [options]
Example:
$ tty
/dev/pts/0Options:
-s→ Silent mode; prints nothing, only sets exit status.
Difference between
ttyandpts:Aspect tty(virtual console)pts(pseudo-terminal)Meaning Physical/virtual console terminal Pseudo terminal slave Path /dev/tty1,/dev/tty2/dev/pts/0,/dev/pts/1Usage Direct console login (Ctrl+Alt+F1) Remote logins (SSH), terminal emulators Origin Real hardware terminals historically Software-created terminals Key points:
ttyhelps identify the current terminal device.- If input is not a terminal, it prints
not a tty. - Useful in scripts to check whether they are running interactively.
-
Question 14 of 20
Explain the
sttycommand. How is it used to change and view terminal settings? Give examples.Model answer
The
stty(set terminal) command is used to display and change terminal line settings, such as input/output behaviour and control characters.Syntax:
stty [options] [setting]
Viewing settings:
stty→ Shows basic terminal settings.stty -a→ Shows all settings in detail.
$ stty -a
speed 38400 baud; rows 24; columns 80;
intr = ^C; erase = ^?; kill = ^U; ...Changing settings — examples:
-
Disable echo (useful for password input):
stty -echo
-
Enable echo again:
stty echo
-
Change the interrupt key:
stty intr ^X
-
Reset the terminal to sane defaults:
stty sane
Common control settings:
erase→ Character to delete previous character.kill→ Character to erase entire line.intr→ Interrupt character (usuallyCtrl+C).
Key points:
- Controls how the terminal handles input and special keys.
stty -echois commonly used in scripts to hide sensitive input.
-
Question 15 of 20
Explain the
mancommand and describe how to navigate a manual page. What are the different sections of the man pages?Model answer
The
man(manual) command displays the reference manual pages for commands, system calls, files, and more. It is the primary source of built-in documentation in Linux.Syntax:
man [section] command
Example:
$ man ls
Manual Page Navigation (uses the
lesspager):- Spacebar /
f→ Move forward one screen. b→ Move back one screen.- Arrow keys → Scroll line by line.
/pattern→ Search forward for a pattern.?pattern→ Search backward.n/N→ Next / previous search match.g/G→ Go to beginning / end.q→ Quit the man page.
Manual Sections:
- Section 1 → User commands (executable programs).
- Section 2 → System calls.
- Section 3 → Library functions.
- Section 4 → Special files (devices in
/dev). - Section 5 → File formats and conventions.
- Section 6 → Games.
- Section 7 → Miscellaneous (macros, conventions).
- Section 8 → System administration commands.
Example of specifying a section:
man 5 passwd # shows the /etc/passwd file format
Key points:
- Use
man -k keyword(apropos) to search by keyword. - Structured sections: NAME, SYNOPSIS, DESCRIPTION, OPTIONS, EXAMPLES, SEE ALSO.
- Spacebar /
-
Question 16 of 20
Compare internal (built-in) commands and external commands in Linux. How can you determine the type of a command?
Model answer
Linux commands can be broadly classified as internal (built-in) and external commands.
Aspect Internal Commands External Commands Definition Built into the shell itself Separate executable programs on disk Location Part of the shell (no separate file) Stored in directories like /bin,/usr/binExecution speed Faster (no disk access) Slightly slower (loaded from disk) Examples cd,echo,pwd,exitls,cat,date,calProcess Runs within the shell process Runs as a new child process Determining the type of a command:
The
typecommand reveals whether a command is built-in or external.$ type cd
cd is a shell builtin$ type ls
ls is /usr/bin/lsOther helpful commands:
which command→ Shows the path of an external command.command -V command→ Similar totype.
Key points:
- Some commands (like
echo) exist both as built-ins and external programs. - The shell searches built-ins first, then the directories in the
PATHvariable.
-
Question 17 of 20
Write short notes with examples on any four system information commands:
date,uname,uptime, andwhoami.Model answer
These commands quickly report useful details about the system and user environment.
1.
date- Displays or sets the current date and time.
- Supports custom formats.
$ date +"%d-%m-%Y"
25-09-20262.
uname- Prints operating system and kernel information.
uname -ashows all details.
$ uname -r
5.15.0-73-generic3.
uptime- Shows how long the system has run, number of users, and load averages.
$ uptime
22:26:57 up 5 days, 2 users, load average: 0.15, 0.20, 0.104.
whoami- Displays the effective username of the current user.
$ whoami
studentSummary Table:
Command Information Provided dateCurrent date & time unameOS / kernel details uptimeRunning time & load whoamiCurrent username Key points:
- These commands are widely used in shell scripts and system monitoring.
-
Question 18 of 20
A shell script needs to perform both integer and floating-point calculations. Explain and demonstrate how
exprandbccan be combined, and write example calculations for area of a circle and simple interest.Model answer
In shell scripts,
exprhandles simple integer math whilebchandles floating-point math. Combining them lets scripts perform a variety of calculations.Using
exprfor integers:$ count=$(expr 5 + 10)
$ echo $count
15Using
bcfor floating-point:$ result=$(echo "scale=2; 22/7" | bc)
$ echo $result
3.14Example 1 — Area of a circle :
r=5
area=$(echo "scale=2; 3.14159 $r $r" | bc)
echo "Area = $area"For :
Example 2 — Simple Interest :
P=1000
R=5
T=2
SI=P $R $T)/100" | bc)
echo "Simple Interest = $SI"For , , :
Key points:
- Use
exprfor counters and integer indices. - Use
bcwhenever decimals or precision are required. - The
scalevariable inbccontrols decimal places.
- Use
-
Question 19 of 20
Explain in detail the concept of options and arguments in command structure, the difference between short and long options, and how combining options works. Support your answer with multiple examples.
Model answer
Commands in Linux gain flexibility through options and arguments that follow the command name.
1. Arguments:
Arguments are the data or objects on which a command acts, such as filenames or text strings.
$ cat file1.txt file2.txt
Here
file1.txtandfile2.txtare arguments.2. Options (Flags):
Options modify the behaviour of a command.
-
Short options: Single letter preceded by a single hyphen
-.$ ls -l
-
Long options: Full word preceded by a double hyphen
--.$ ls --all
Difference between short and long options:
Aspect Short Option Long Option Prefix Single -Double --Form One letter ( -a)Descriptive word ( --all)Readability Compact More readable Combining Can be combined Usually written separately 3. Combining options:
Multiple short options can be merged after a single hyphen.
$ ls -l -a -h # separate
$ ls -lah # combined (equivalent)Options with values:
$ sort -k 2 file.txt # short with argument
$ head --lines=5 file.txt # long with =value4. Order and precedence:
- Options generally come before arguments.
- Some commands allow options anywhere; others require a strict order.
Key points:
- Commands are case-sensitive.
- The
--marker signals the end of options, so filenames beginning with-can follow. - Understanding options and arguments is essential for reading man pages and writing scripts.
-
-
Question 20 of 20
Describe how the
mancommand,apropos,whatis, and--helpwork together as sources of command documentation. Compare them and give examples of when to use each.Model answer
Linux provides several complementary tools for learning about commands. Together they help a user discover, understand, and quickly reference commands.
1.
man— full manual pages:Provides complete, detailed documentation for a command.
$ man ls
- Structured into NAME, SYNOPSIS, DESCRIPTION, OPTIONS, etc.
- Best when you need in-depth information.
2.
whatis— one-line description:Displays a brief, one-line summary of a command.
$ whatis ls
ls (1) - list directory contents- Best for a quick reminder of what a command does.
3.
apropos— keyword search:Searches man page descriptions for a keyword (same as
man -k).$ apropos copy
cp (1) - copy files and directories
scp (1) - secure copy- Best when you don't know the command name but know the task.
4.
--helpoption — quick syntax help:Most commands support a built-in
--helpflag.$ ls --help
- Shows a concise usage summary without opening the pager.
Comparison Table:
Tool Detail Level Best Use manDetailed Complete reference whatisOne line Quick definition aproposList of matches Find a command by keyword --helpShort summary Quick syntax check Key points:
whatisandaproposrely on a database updated bymandb.- Use
aproposto discover,whatisto recall,--helpfor quick syntax, andmanfor depth.
That's unit 2
Long answers stick best when they're tested again soon. Run the MCQs on this unit, then come back to the questions you found hardest.
Nearly through. Did unit 2 of CSE105 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 2 of CSE105 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill; the rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks.